紅綠燈動作原則:
1.開機時的初始狀態為第一大道綠燈、第二大道紅燈
2.在紅燈狀態達13秒時轉為綠燈狀態
3.在綠燈狀態達10秒時轉為黃燈狀態
4.在黃燈狀態達2秒時轉為紅燈狀態
Moore 狀態機之設計:
依動作原則,有6個輸出R1,Y1,G1,R2,Y2,G2分別表式兩個路口的紅燈、黃燈、綠燈,故配以狀態組合:一綠二紅狀態(SG1R2)、一黃二紅狀態(SY1R2)、一紅二紅狀態(SR1R2)、一紅二綠狀態(SR1G2) 、一紅二黃狀態(SR1Y2)。
狀態轉移表:
currentStatenextState 輸出 狀態 說明
CBAC+B+A+R1Y1G1R2Y2G2
010011100100SR1R2a
011100001100SG1R2
100101010100SY1R2
101110100100SR1R2b
110111100001SR1G2
111011100010SR1Y2
依動作原則需1秒之時脈(clk1sec)及2個4位元計數器(cnt1與cnt2)計算秒數,並以此計數器之值作為狀態機之輸入。
下面是老師給的初始程式碼
module HW3_top(
input wire mclk ,
input wire btn0,
output wire R1_led,
output wire Y1_led,
output wire G1_led,
output wire R2_led,
output wire Y2_led,
output wire G2_led,
output wire [6:0] a_to_g ,
output wire [3:0] an ,
output wire dp
);
clk_1Hz U0(mclk,reset,clk1sec);
trafficlight U1( _____ );
endmodule
module trafficlight(
input wire clk,
input wire reset,
input wire clk1sec,
output wire R1_led,
output wire Y1_led,
output wire G1_led,
output wire R2_led,
output wire Y2_led,
output wire G2_led,
output wire [6:0] a_to_g ,
output wire [3:0] an ,
output wire dp
);
reg [2:0] currentState,nextState;
reg [3:0] cnt1,cnt2;
always @(posedge clk or negedge reset) begin //計算次一狀態
if (~reset) nextState= ;
else
end
always @( ____ ) begin //變更目前狀態與輸出燈號
currentState= nextState;
??
??
??
end
...
endmodule
module clk_1Hz(
input wire clk,
input wire reset,
output wire clk1sec
);
reg[ ?? :0] cnt;
always@(posedge clk or regedge reset)
if (~reset) cnt=24'h0;
else if (cnt==24'h ??? ) cnt=24'h0;
else cnt=cnt+1'b1;
assign clk1sec=(cnt==24'h ??? );
endmodule
因為自己沒有學過Verilog相關語言,所以寫起來相當的吃力...
所以上來詢問各位大大該如何編寫這個程式 謝謝
This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
Want something else to read? How about 'Grievous Censorship' By The Guardian: Israel, Gaza And The Termination Of Nafeez Ahmed's Blog