【FPGA】Verilog实现交通讯号灯

大二数字电路的课程设计中,有一份平常做业使用Xilinx FPGA实现简易交通讯号灯,但很惋惜当时时间有限,没能最终完成。正好在这一学期选修SOPC设计课程,一样采用了Xilinx FPGA,故打算从新完成交通讯号灯的相关内容。框架

本项目采用Digilent公司生产的BASYS3开发板,基于Xilinx FPGA,该板子目前能够在马云家买到,不过价格偏贵,在校学生可在digilent官网申请以更低价格买入。编辑器

大体的框架以下,只是个构思,还很不完善,后续会进行修改。好比如今我目前并无把计时功能彻底从State模块中摘出来,只是用Timer实例化了一个1s计时器在里面,而且用count计数。ide

 

下面是State部分的代码,目前还有不少须要修改完善的地方,好比后续会将State中的count计数也摘出来。注释部分因为Vivado自带编辑器过于磕碜(没有办法字体回退),而我又很不喜欢微软雅黑和宋体,因此只好用个人工地英语写一点注释了。字体

module BASYS_BIGPROJECT_State(
input clk,
output reg[1:0]state,
output reg[3:0]count
    );
wire clk_1;
Freq_divider #(27)clk_1s(clk,0,,clk_1);
always@(posedge clk_1)
begin
    count <= count + 1;
end

//green led for 4s, yellow led for 2s
always@(posedge clk)
begin
    case(state)
    2'b00:begin //main red, branch green
        if(count<4) begin
            state <= 2'b00;
        end
        else begin
            state <= 2'b01;
            count = 3'b000;
        end
    end
    2'b01:begin //main red, branch yellow
        if(count<2) begin
            state <= 2'b01;
        end
        else begin
            state <= 2'b11;
            count = 3'b000;
        end
    end
    2'b11:begin //main green, branch red
        if(count<4) begin
            state <= 2'b11;
        end
        else begin 
            state <= 2'b10;
            count = 3'b000;
        end
    end
    2'b10:begin //main yellow, branch red
        if(count<2) begin
            state <= 2'b10;
        end
        else begin
            state <= 2'b00;
            count = 3'b000;
        end
    end
    endcase
end
endmodule
相关文章
相关标签/搜索