ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

FPAG实验交通灯

2021-10-27 11:34:21  阅读:199  来源: 互联网

标签:led clkout 交通灯 实验 FPAG 方向 input reg


FPGA交通灯控制器verilog-QuratusⅡ

一、设计并调试好一个由南北方向和东西方向汇合点形成的十字交叉路口的交通灯控制器,具体要求如下:

(1)掌握quaruts 软件的使用方法
(2)熟悉GW48实验开发系统的基本使用方法
(3)掌握verilog综合系统的设计方法
(4)了解交通灯的控制原理
(1) 南北、东西方向各设有一个左转、黄、绿、红指示灯,两个显示数码管。
(2) 突发事件下,两个方向都亮红灯
(3) 正常情况下,交替通行,绿灯亮的时间为40s,左转灯亮为15s,黄灯过度时间为5s,在每个方向上倒计时显示时间。

二、代码

module test10(clk, tufa,clkout,rst_n,led);
input clk;
input rst_n;
input tufa;
output [7:0] led;
output clkout; 

reg [7:0] led;
reg [4:0] time_left;
reg [4:0] state;
reg clkout; 
reg [31:0] cnt;

parameter [8:0] S0 = 4'b0000,
				S1 = 4'b0001,
                S2 = 4'b0010,
                S3 = 4'b0011,
                S4 = 4'b0100,
                S5 = 4'b0101,
                S6 = 4'b0110,
                S7 = 4'b0111,
                S8 = 4'b1000;
                


always @(posedge clk) 
begin //板子时钟为100MHZ,
if(cnt == 32'd9999_9999)
begin  
clkout <= 1'b1; 
cnt <= 32'd0;
end  
else 
begin  
clkout <= 1'b0;
cnt <= cnt + 32'd1; 
end 
end       
 
 
  
always @(posedge clk)
if(!tufa)
begin
	if(!rst_n)
	begin
		state <= S1;
        time_left <= 5'd14;
        led <= 8'b1000_0001;
     end
     else
     begin   
        case(state)
			S1:begin    
				if(clkout)
                begin        
                if(time_left==0)
                begin
                state <= S2;
                time_left <= 5'd4;
                led <= 8'b0100_0001; 
                end
                else
                begin
                state <= S1;
                time_left <= time_left-1'b1;
                led <= 8'b1000_0001;
                end
                end
			  end
              S2:begin
               if(clkout)
               begin
               if(time_left==0)
               begin   
               state <= S3;
               time_left <= 5'd39;
               led <= 8'b0010_0001; 
               end
               else
               begin
               state <= S2;
               time_left <= time_left-1'b1;
               led <= 8'b0100_0001;
               end
               end
              end
              S3:begin
               if(clkout)
               begin
               if(time_left==0)
               begin
               state <= S4;
               time_left <= 5'd4;
               led <= 8'b0100_0001; 
               end
               else
               begin
               state <= S3;
               time_left <= time_left-1'b1;
               led <= 8'b0010_0001;
               end
               end
              end
              S4:begin
               if(clkout)
               begin
               if(time_left==0)
			   begin 
               state <= S5;
               time_left <= 5'd14;
               led <= 8'b0001_1000; 
               end
               else
               begin
               state <= S4;
               time_left <= time_left-1'b1;
               led <= 8'b0100_0001;
               end
              end
              end
              S5:begin
               if(clkout)
               begin
               if(time_left==0)
			   begin 
               state <= S6;
               time_left <= 5'd4;
               led <= 8'b0001_0100; 
               end
               else
               begin
               state <= S5;
               time_left <= time_left-1'b1;
               led <= 8'b0001_1000;
               end
              end
              end
             S6:begin
               if(clkout)
				begin
					if(time_left==0)
					 begin
						state <= S7;
						time_left <= 5'd39;
						led <= 8'b0001_0010; 
					 end
					else
					 begin
						state <= S6;
						time_left <= time_left-1'b1;
						led <= 8'b0001_0100;
					 end
					end
				
              end
              S7:begin
               if(clkout)
				begin
					if(time_left==0)
					 begin
						state <= S8;
						time_left <= 5'd4;
						led <= 8'b0001_0100; 
					 end
					else
					 begin
						state <= S7;
						time_left <= time_left-1'b1;
						led <= 8'b0001_0010;
					 end
					end
				
              end              
               S8:begin
               if(clkout)
				begin
					if(time_left==0)
					 begin
						state <= S1;
						time_left <= 5'd14;
						led <= 8'b1000_0001; 
					 end
					else
					 begin
						state <= S8;
						time_left <= time_left-1'b1;
						led <= 8'b0001_0100;
					 end
					end
				end
         
              
              
              
          endcase
      end
      

    end
else
begin
state <= S0;
time_left <= 5'd0;
led <= 8'b0000_0000;
end
endmodule


三、总结

时序仿真结果是正确的,没有经过硬件仿真,需要的话可以自己设置下pin脚,然后自己仿真下试试

标签:led,clkout,交通灯,实验,FPAG,方向,input,reg
来源: https://blog.csdn.net/weixin_44192651/article/details/120989162

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有