当前位置:网站首页>Digital IC code -- traffic lights
Digital IC code -- traffic lights
2022-06-29 14:42:00 【FPGA silicon agriculture】
subject
describe
A traffic light is required , It has three small red, yellow and green indicators and a pedestrian button , Under normal circumstances , The motorway indicator light shall be in accordance with 60 Clock cycle green ,5 A clock cycle yellow light ,10 A clock cycle, a red light cycle . When the pedestrian button is pressed , If the remaining green time is greater than 10 A clock , Is shortened to 10 A clock , Less than 10 The two clocks remain the same .
The signal interface diagram of the module is as follows :
Please use VerilogHDL Language implementation , And write testbench Verification function .
Code
Design
`timescale 1ns/1ns
module triffic_light
(
input rst_n, // Ectopic reset signal , Low level active
input clk, // Clock signal
input pass_request,
output reg [7:0]clock,
output reg red,
output reg yellow,
output reg green
);
parameter RED=0;
parameter GREEN=1;
parameter YELLOW=2;
reg [1:0] state,next_state;
//60 clk green
//5 clk yellow
//10 clk red
[email protected](posedge clk,negedge rst_n)
if(~rst_n)
state<=RED;
else
state<=next_state;
[email protected](*)
begin
case(state)
RED:if(clock==1)
next_state=GREEN;
else
next_state=RED;
YELLOW:if(clock==1)
next_state=RED;
else
next_state=YELLOW;
GREEN:if(clock==1)
next_state=YELLOW;
else
next_state=GREEN;
default:next_state=RED;
endcase
end
//led
[email protected](*)
case(state)
RED:{
red,yellow,green}=3'b100;
YELLOW:{
red,yellow,green}=3'b010;
GREEN:{
red,yellow,green}=3'b001;
default:{
red,yellow,green}=3'b000;
endcase
//clock
[email protected](posedge clk,negedge rst_n)
if(~rst_n)
clock<=10; //red
else
case(state)
RED:if(clock==1)
clock<=60;
else
clock<=clock-1;
YELLOW:if(clock==1)
clock<=10;
else
clock<=clock-1;
GREEN:
if(pass_request)
if(clock>10)
clock<=10;
else
clock<=clock-1;
else if(clock==1)
clock<=5;
else
clock<=clock-1;
default:clock<=10;
endcase
endmodule
Test platform
module test;
reg clk;
reg rst_n;
reg pass_request;
wire [7:0] clock;
wire red;
wire yellow;
wire green;
//clk
initial
begin
clk=0;
forever
#5 clk=~clk;
end
//rst_n
initial
begin
rst_n=0;
#100
rst_n=1;
end
//
initial
begin
pass_request=0;
//
repeat(20)
@(posedge clk);
wait(green&&clock==18);
pass_request<=1;
@(posedge clk);
pass_request<=0;
//
repeat(40)
@(posedge clk);
wait(green&&clock==9);
pass_request<=1;
@(posedge clk)
pass_request<=0;
end
//inst
triffic_light U
(.*
/* input rst_n, // Ectopic reset signal , Low level active input clk, // Clock signal input pass_request, output reg [7:0]clock, output reg red, output reg yellow, output reg green */
);
endmodule
result
Under normal circumstances , A green light 60 A cycle , Yellow light 5 A cycle , A red light 10 A cycle 
Green and greater than 10 A cycle , Pedestrian press 
Green light and less than or equal to 10 A cycle , Pedestrian press 
边栏推荐
- Characteristics of human immaturity
- 3d立体相册,情人节,情侣生日礼物代码适用
- 布隆过滤器Bloom Filter简介
- By proxy, by buyout, the wild era of domestic end-to-end travel is waiting for the next "eternal robbery"
- 云上第一课 | 建个小破站有多简单?云计算老司机带你一小时搞定
- Thanos Store 组件
- 《canvas》之第8章 像素操作
- Interview shock 61: tell me about MySQL transaction isolation level?
- How goby exports scan results
- 《canvas》之第10章 canvas路径
猜你喜欢

校园跑腿微信小程序跑腿同学带直播新版源码

Transport layer user datagram protocol (UDP)

仿头条新闻资讯dz模板 Discuz新闻资讯商业版GBK模板源码

揭秘!付费会员制下的那些小心机!

Practical application cases of drives

idea输出台输出中文乱码问题

stm32 mbed 入门教程(四)---PWM

浅析 Istio——可观测性

传输层 选择性确认 SACK

VQA needs not only pictures, but also external knowledge! University of Washington & Microsoft proposed revive, using gpt-3 and wikidata to help answer questions
随机推荐
布隆过滤器Bloom Filter简介
golang代码规范整理
Chapter 9 of canvas: gradients and shadows
【置顶】博客使用须知,公告板,留言板,关于博主
Redis的持久化机制
[use of veux developer tools - use of getters]
Opengauss community establishes sig knowledgegraph
用手机在指南针上开户靠谱吗?这样炒股有没有什么安全隐患
Redis' data expiration clearing strategy and memory obsolescence strategy
《canvas》之第13章 事件操作
URL encoding in Delphi7
By proxy, by buyout, the wild era of domestic end-to-end travel is waiting for the next "eternal robbery"
【烹饪记录】--- 酸辣白菜
Persistence mechanism of redis
[important notice] the 2022 series of awards and recommendations of China graphics society were launched
广州开展瓶装气安全宣传活动,普及燃气安全知识
Redis为什么这么快?Redis是单线程还是多线程?
tcpdump如何对特定的tcp标志位进行过滤
3d立体相册,情人节,情侣生日礼物代码适用
VQA needs not only pictures, but also external knowledge! University of Washington & Microsoft proposed revive, using gpt-3 and wikidata to help answer questions