文章目录
- 7. 时序逻辑电路
- 1.触发器
- (1)D触发器
- (2)JK触发器
- (3)T触发器
- 2. 移位寄存器
- (1)右移寄存器
- (2)左移寄存器
- 3. 计数器
- (1)反馈清零计数器
- (2)反馈置数计数器
- (3)移位计数器
- 4. 信号产生器
- (1)状态图类型
- (2)移位寄存器类型
- (3)计数器加组合输出网络类型
- (4)移位寄存器加组合逻辑反馈电路类型
- (5)m序列信号发生器
- 5. 有限状态机
- (1)状态机的组成
- (2)状态机分类
- (3)状态机的编码方式
- (4)有限状态机的设计方式
参考:Verilog数字VLSI设计教程
硬件描述语言Verilog
Verilog HDL数字设计与综合
Verilog HDL 数字集成电路高级程序设计
7. 时序逻辑电路
对于一个时序电路,可以把它分为一部分组合逻辑和一部分存储逻辑
时序电路的三大方程
典型的时序电路设计流程
1.触发器
(1)D触发器
1 2 3 4 5 6 7 8 9 | module dff(clk,clr,rst,d,q); input clk,clr,rst,d; output q; reg q; always @(posedge clk or posedge clr) if(clr==1'b1) q<=1'b0; else if(rst==1'b1) q<=1'b1; else q<=d; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | module dff_tb; reg clk,clr,rst,d; wire q; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0; clr=1'b0; rst=1'b0;clr=1'b0;d=1'b0; #10 rst=1'b1;clr=1'b0;d=1'b0; #10 clr=1'b1;rst=1'b1;d=1'b1; #10 clr=1'b0;rst=1'b0;d=1'b1; #20 d=1'b0; #20 d=1'b1; end dff u1(clk,clr,rst,d,q); endmodule |
8位D触发器
1 2 3 4 5 6 7 8 | module eight_register(d,clk,q); input [7:0] d; input clk; output [7:0] q; reg [7:0] q; always @(posedge clk) q<=d; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | module dff8_tb; reg [7:0] d; reg clk; wire [7:0] q; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0; d=8'b00000000; #10 d=8'b00000011; #10 d=8'b00000000; #10 d=8'b00000111; #20 d=8'b00001111; #20 d=8'b00011111; #20 d=8'b00111111; end dff8 u1(.d(d),.clk(clk),.q(q)); endmodule |
(2)JK触发器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | module jk_trigger(clk,j,k,q,qb); input clk,j,k; output q,qb; reg q; always@(posedge clk) begin case({j,k}) 2'b00:q<=q; 2'b01:q<=1'b0; 2'b10:q<=1'b1; 2'b11:q<=~q; default: q<=q; endcase end assign qb=~q; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | module jk_trigger_tb; reg clk,j,k; wire q,qb; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0;j=1'b0;k=1'b0; #10 j=1'b0;k=1'b0; #20 j=1'b0;k=1'b1; #20 j=1'b1;k=1'b0; #20 j=1'b1;k=1'b1; #20 j=1'b1;k=1'b0; end jk_trigger u1(clk,j,k,q,qb); endmodule |
(3)T触发器
1 2 3 4 5 6 7 8 | module t_trigger(clk,rst,T,dout); input clk,rst,T; output dout; reg dout; always @(posedge clk or posedgerst) if(rst==1) dout<=1'b0; else if(T==1) dout<=~dout; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | module t_trigger_tb; reg clk,rst,T; wire dout; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0; rst=1'b0;T=1'b0; #10 rst=1'b1;T=1'b1; #10 rst=1'b0;T=1'b0; #20 T=1'b1; #20 T=1'b0; #20 T=1'b1; end t_trigger u1(clk,rst,T,dout); endmodule |
2. 移位寄存器
(1)右移寄存器
1 2 3 4 5 6 7 8 | module register_right(clk,din,dout); input clk; input din; output [15:0] dout; reg [15:0] dout; always @(posedge clk) dout<={din,dinout[15:1]}; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | module register_right_tb; reg clk; reg din; wire [15:0] dout; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0; din=1'b0; #10 din=1'b1; #20 din=1'b0; #20 din=1'b1; #100; end register_right u1(clk,din,dout); endmodule |
(2)左移寄存器
1 2 3 4 5 6 7 8 | module register_left(clk,din,dout); input clk; input [15:0] din; output [15:0] dout; reg [15:0] dout; always @(posedge clk) dout<={din[14:0],din[15]}; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | module register_left_tb; reg clk; reg [15:0] din; wire [15:0] dout; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0; din=16'b0000000000000000; #10 din=16'b0000000000000001; #20 din=16'b0000000000000011; #20 din=16'b0000000000000101; end register_left u1(clk,din,dout); endmodule |
3. 计数器
(1)反馈清零计数器
1 2 3 4 5 6 7 8 9 10 11 12 13 | module count12(clk,rst_n,co,dout); input clk,rst; output co; output [3:0] dout; reg [3:0] dout; always @ (posedge clk) begin if(rst_n==1'b0) dout=4'b0000; else if(dout==4'b1011) dout<=4'b0000; else dout<=dout+1'b1; end assign co=dout[3]&&dout[1]&&dout[0]; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | module count12_tb; reg clk,rst_n; wire oc; wire [3:0] dout; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0; rst_n=1'b0; #20 rst_n=1'b1; #100; end count12 u1(clk,rst_n,oc,dout); endmodule |
(2)反馈置数计数器
1 2 3 4 5 6 7 8 9 10 11 12 13 | module count10(clk,rst,load,din,dout); input clk,rst,load; input [3:0] din; output [3:0] dout; reg [3:0] dout; always @ (posedge clk or posedge rst) begin if(rst==1'b1) dout=4'b0000; else if(load==1'b 1) dout=4'b1001; else if(dout==4'b0000) dout<=4'b1001; else dout<=dout-1'b1; end endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | module count10_tb; reg clk,rst,load; reg [3:0] din; wire [3:0] dout; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0; rst=1'b0;load=1'b0; #10 rst=1'b1; #10 rst=1'b0; #50 load=1'b1; #10 load=1'b0; #100; end count10 u1(clk,rst,load,din,dout); endmodule |
(3)计数器级联
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | module count10(clk,rst_n,en,dout,co); input clk,rst_n,en; output[3:0] dout; output co; reg [3:0] dout; always @ (posedge clk or negedge rst_n) begin if(rst_n ==1'b 0) dout<=4'b0000; else if(en==1'b1) if(dout==4'b1001) dout<=4'b0000; else dout<=dout+1'b1; else dout<=dout; end assign co=dout[0]&dout[3]; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | module count6(clk,rst_n,en,dout,co); input clk,rst_n,en; output[3:0] dout; output co; reg [3:0] dout; always @ (posedge clk or negedge rst_n) begin if(rst_n ==1'b 0) dout<=4'b0000; else if(en==1'b1) if(dout==4'b0101) dout<=4'b0000; else dout<=dout+1'b1; else dout<=dout; end assign co=dout[0]&dout[2]; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | module count60(clk,rst_n,en,dout,co); input clk,rst,en; output[7:0] dout; output co; wire c010,co6; wire[3:0] dout10,dout6; counter_10 u1(.clk(clk),.rst_n(rst_n),.en(en),.dout(dout10),.co(co10)); counter_6 u2(.clk(clk),.rst_n(rst_n),.en(co10),.dout(dout6),.co(co6)); and u3(co,co10,co6); assign dout={dout6,dout10}; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | module count60_tb ; reg clk,rst_n,en ; wire [7:0] dout ; wire co ; always begin #1 clk=1'b1 ; #1 clk=1'b0 ; end initial begin clk=1'b0 ; rst_n=1'b1 ; en=1'b1; #1 rst_n=1'b0 ; #1 rst_n=1'b1 ; end count60 U1(.clk(clk),.rst_n(rst_n),.en(en),.dout(dout),.co(co)); endmodule |
(3)移位计数器
扭环计数器
1 2 3 4 5 6 7 8 9 | module twisted_counter(clk,rst_n,dout); input clk,rst_n; output[3:0] dout; reg [3:0] dout; always @(posedge clk or negedge rst_n) if(!rst_n) dout<=4'b0000; else begin dout<={dout[2:0],~dout[3] }; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | module twisted_counter_tb; reg clk,rst_n; wire [3:0] dout; always begin #10 clk=1'b1; #10 clk=1'b0; end initial begin clk=1'b0; rst_n=1'b1; #10 rst_n=1'b0; #10 rst_n=1'b1; #100; end twisted_counter u1(clk,rst_n,dout); endmodule |
4. 信号产生器
(1)最大循环长度序列码,M=2n。
(2)最长线形序列码(m序列码),M=2n-1。
(3)任意循环长度序列码,M<2n。
(1)状态图类型
有限状态机方式实现001011序列信号产生器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | module sequence_signal_fsm(clk,rst_n,dout); input clk,rst_n; output dout; reg dout; reg [2:0] pre_state,next_state; parameter s0=3'b000,s1=3'b001,s2=3'b010,s3=3'b011,s4=3'b100,s5=3'b101; always @(posedge clk or negedge rst_n) if(rst_n ==1'b0) pre_state<=s0; else pre_state<=next_state; always @(pre_state) case(pre_state) s0: begin dout<=1'b0; next_state<=s1; end s1: begin dout<=1'b0; next_state<=s2; end s2: begin dout<=1'b1; next_state<=s3; end s3: begin dout<=1'b0; next_state<=s4; end s4: begin dout<=1'b1; next_state<=s5; end s5: begin dout<=1'b1; next_state<=s0; end default next_state<=s0; endcase endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 | module sequence_signal_fsm_tb; reg clk,rst_n; wire dout; sequence_signal_fsm u1(clk,rst_n,dout); always #10 clk=~clk; initial begin clk=1'b0; rst_n=1'b1; #5 rst_n=1'b0; #5 rst_n=1'b1; end endmodule |
(2)移位寄存器类型
移位寄存器型序列信号产生器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | module signal_generator_shifter_reg(clk,rst,din,dout); input clk,rst; input [5:0] din; output dout; reg dout; reg [5:0] temp; always @(posedge clk) begin if(rst==1'b1) temp<=din; else begin dout<=temp[5]; temp<={temp[4:0],temp[5]}; end end endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | module signal_generator_shifter_reg_tb; reg clk,rst; reg [5:0] din; wire dout; signal_generator_shifter_reg u1(.clk(clk),.rst(rst),.din(din),.dout(dout)); always #10 clk=~clk; initial begin clk=1'b0; rst=1'b0; #10 rst=1'b1;din=6'b001011; #20 rst=1'b0; end endmodule |
(3)计数器加组合输出网络类型
计数器+组合编码电路 001011序列信号产生器。
1 2 3 4 5 6 7 8 9 10 11 12 13 | module counter_sequence(clk,rst,dout); input clk,rst; output dout; reg [2:0] counter; always @(posedge clk) if(rst==1'b1) counter<=3'b000; else if(counter==3'b101) counter<=3'b000; else counter<=counter+1'b1; assign dout=((~counter[0])&counter[1])|counter[2]; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 | module counter_sequence_tb; reg clk,rst; wire dout; counter_sequence u1(.clk(clk),.rst(rst),.dout(dout)); always #10 clk=~clk; initial begin clk=1'b0; rst=1'b0; #10 rst=1'b1; #20 rst=1'b0; end endmodule |
(4)移位寄存器加组合逻辑反馈电路类型
(1)根据给定的序列信号的循环长度M,确定寄存器位数n,2n-1
(2)确定移位寄存器的M个独立状态。
将给定的序列码按照移位规律每n位一组,划分为M个状态。若M个状态中出现重复现象,则应增加移位寄存器位数。用n+1位再重复上述过程,直到划分为M个独立状态为止。
(3)根据M个不同的状态列出移位寄存器的态序表和反馈函数表,求出反馈函数F的表达式。
(4)检查自启动性能。
设计一个移位寄存器加组合逻辑电路类型的010011序列信号发生器。
对于“010011”序列的信号发生器
1 2 3 4 5 6 7 8 9 10 11 12 | module signal_shifter_feedback(clk,load,dout,D); input clk,load; input [2:0]D; output dout; reg [2:0] Q; wire F; always @(posedge clk) if(load==1'b1) Q<=D; else Q<={Q[1:0],F}; assign F=((~Q[0])&(~Q[2]))|((~Q[1])&Q[2]); assign dout=Q[2]; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | module signal_shifter_feedback_tb; reg clk,load; reg[2:0] D; wire dout; signal_shifter_feedback u1(.clk(clk),.load(load),.dout(dout),.D(D)); always #10 clk=~clk; initial begin clk=1'b0; D=3'b001; load=1'b0; #10 load=1'b1; #20 load=1'b0; end endmodule |
(5)m序列信号发生器
设计一个m序列信号产生器的Verilog HDL描述,该程序中n=5
1 2 3 4 5 6 7 8 9 10 11 12 | module m_sequence(clk,en,dout,D); input clk,en; input[4:0] D; output dout; reg[4:0] Q; wire F; always @ (posedge clk) if(en==1'b0) Q<=D; else Q<={Q[3:0],F}; assign F=(Q[0]^Q[2])|((~Q[4])&(~Q[3])&(~Q[2])&(~Q[1])&(~Q[0])); assign dout=Q[4]; endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | module m_sequence_tb; reg clk,en; reg[4:0] D; wire dout; m_sequence u1(.clk(clk),.en(en),.dout(dout),.D(D)); always #10 clk=~clk; initial begin clk=1'b0; D=5'b10000; en=1'b0; #20 en=1'b1; end endmodule |
5. 有限状态机
(1)状态机的组成
(2)状态机分类
Mealy型
Moore型
(3)状态机的编码方式
(4)有限状态机的设计方式
用两段式描述的5进制同步加法计数器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | module couter5_fsm(clk,rst_n,Z); input clk,rst_n; utput Z; reg Z; reg[2:0] pre_state,next_state; parameter s0=3'b000,s1=3'b001,s2=3'b010,s3=3'b011,s4=3'b100; //第一个过程,同步时序always模块,描述状态转移方程 always @(posedge clk or negedge rst_n) if(!rst_n) pre_state<=s0; else pre_state<=next_state; //第二个过程,组合逻辑always模块,描述激励方程和输出方程 always @(pre_state) begin next_state=3'bxxx; Z=1'b0; case (pre_state) s0: begin next_state=s1; Z=1'b0; end s1: begin next_state=s2; Z=1'b0; end s2: begin next_state=s3; Z=1'b0; end s3: begin next_state=s4; Z=1'b0; end s4: begin next_state=s0; Z=1'b1; end default: begin next_state=s0; end endcase end endmodule |
用三段式描述5进制加法计数器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | module couter5_fsm(clk,rst_n,Z); input clk,rst_n; output Z; reg Z; reg[2:0] pre_state,next_state; parameter s0=3'b000,s1=3'b001,s2=3'b010,s3=3'b011,s4=3'b100; //第一个过程,同步时序always模块,描述状态转移方程 always @(posedge clk or negedge rst_n) if(!rst_n) pre_state<=s0; else pre_state<=next_state; //第二个过程,组合逻辑always模块,描述激励方程 always @(pre_state) begin next_state=3'bxxx; case (pre_state) s0:next_state=s1; s1:next_state=s2; s2:next_state=s3; s3:next_state=s4; s4:next_state=s0; default:next_state=s0; endcase end //第三个过程,同步时序always模块,格式化描述输出方程 always @(pre_state) begin Z=1'b0; case (pre_state) s0: Z=1'b0; s1: Z=1'b0; s2: Z=1'b0; s3: Z=1'b0; s4: Z=1'b1; default: Z=1'b0; endcase end endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 | module couter5_fsm_tb; reg clk,rst_n; wire Z; couter5_fsm u1(clk,rst_n,Z); always #10 clk=~clk; initial begin clk=1'b0; rst_n=1'b1; #10 rst_n=1'b0; #10 rst_n=1'b1; end endmodule |
设计Mealy型0101序列检测器。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | module detector_Mealy(clk,rst_n,din,dout); input clk,rst_n,din; output dout; reg dout; reg [1:0] pr_state,next_state; parameter s0=2'b00,s1=2'b01,s2=2'b10,s3=2'b11; always @(posedge clk or negedge rst_n) begin if(rst_n ==1'b0) pr_state<=s0; else pr_state<=next_state; end always@(pr_state or din) begin next_state<=2'bxx; dout<=1'b0; case(pr_state) s0: //the state is 1; begin if(din==1'b1) begin next_state<=s0; dout<=1'b0; end else begin next_state<=s1; dout<=1'b0; end end s1://the state is 0; begin if(din==1'b1) begin next_state<=s2; dout<=1'b0; end else next_state<=s1; end s2: //the state is 01; begin if(din==1'b1) begin next_state<=s0; dout<=1'b0; end else next_state<=s3; end s3: //the state is 010; begin if(din==1'b1) begin next_state<=s2; dout<=1'b1; end else next_state<=s1; end endcase end endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | module detector_Mealy_tb; reg clk,rst_n,din; wire dout; detector_Mealy u1(.clk(clk),.rst_n(rst_n),.din(din),.dout(dout)); always #50 clk=~clk; initial begin clk=1'b1; rst_n=1'b0; #100 rst_n=1'b1; din=1'b0; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; #100 din=1'b0; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; end endmodule |
用Moore型状态机实现0101序列检测器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | module detector_Moore(clk,rst_n,din,dout); input clk,rst_n,din; output dout; reg dout; reg [2:0] pr_state,next_state; parameter s0=3'b000,s1=3'b001,s2=3'b010,s3=3'b011,s4=3'b100; always @(posedge clk or negedge rst_n) begin if(rst_n ==1'b0) pr_state<=s0; else pr_state<=next_state; end always@(pr_state or din) begin next_state<=2'bxx; dout<=1'b0; case(pr_state) s0://the state is 1; begin dout<=1'b0; if(din==1'b1) next_state<=s0; else next_state<=s1; end s1://the state is 0; begin dout<=1'b0; if(din==1'b1) next_state<=s2; else next_state<=s1; s2: //the state is 01; begin dout<=1'b0; if(din==1'b1) next_state<=s0; else next_state<=s3; end s3: //the state is 010; begin dout<=1'b0; if(din==1'b1) next_state<=s4; else next_state<=s1; end s4: //the state is 0101; begin dout<=1'b1; if(din==1'b1) next_state<=s0; else next_state<=s3; end endcase end endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | module detector_Moore_tb; reg clk,rst_n,din; wire dout; detector_Moore u1(.clk(clk),.rst_n(rst_n),.din(din),.dout(dout)); always #50 clk=~clk; initial begin clk=1'b1; rst_n=1'b0; #100 rst_n=1'b1; din=1'b0; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; #100 din=1'b0; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; #100 din=1'b1; #100 din=1'b0; end endmodule |
计数器控制的状态机。该程序为计数器控制的状态机模型,0—16数值分别对应了不同的格雷码和约翰逊码,当计数器进行计数时,计数到每一个不同状态,相应地输出该状态所对应的格雷码和约翰逊码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | module counter_fsm(clk,rst,dout_gray,dout_johnson); input clk,rst; output [3:0] dout_gray; output [7:0] dout_johnson; reg [3:0] dout_gray; reg [7:0] dout_johnson; reg [3:0] counter; always @(posedge clk) if(rst==1'b1) counter=4'b0000; else counter=counter+4'b0001; always @(counter) case(counter) 4'b0000: begin dout_gray=4'b0000; dout_johnson=8'b0000_0000; end 4'b0001: begin dout_gray=4'b0001; dout_johnson=8'b0000_0001; end 4'b0010: begin dout_gray=4'b0011; dout_johnson=8'b0000_0011; end 4'b0011: begin dout_gray=4'b0010; dout_johnson=8'b0000_0111; end 4'b0100: begin dout_gray=4'b0110; dout_johnson=8'b0000_1111; end 4'b0101: begin dout_gray=4'b0111; dout_johnson=8'b0001_1111; end 4'b0110: begin dout_gray=4'b0101; dout_johnson=8'b0011_1111; end 4'b0111: begin dout_gray=4'b0100; dout_johnson=8'b0111_1111; end 4'b1000: begin dout_gray=4'b1100; dout_johnson=8'b1111_1111; end 4'b1001: begin dout_gray=4'b1101; dout_johnson=8'b1111_1110; end 4'b1010: begin dout_gray=4'b1111; dout_johnson=8'b1111_1100; end 4'b1011: begin dout_gray=4'b1110; dout_johnson=8'b1111_1000; end 4'b1100: begin dout_gray=4'b1010; dout_johnson=8'b1111_0000; end 4'b1101: begin dout_gray=4'b1011; dout_johnson=8'b1110_0000; end 4'b1110: begin dout_gray=4'b1001; dout_johnson=8'b1100_0000; end 4'b1111: begin dout_gray=4'b1000; dout_johnson=8'b1000_0000; end endcase endmodule |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | module counter_fsm_tb; reg clk,rst; wire [3:0] dout_gray; wire [7:0] dout_johnson; counter_fsm u1(.clk(clk),.rst(rst),.dout_gray(dout_gray),.dout_johnson(dout_johnson)); always #10 clk=~clk; initial begin clk=1'b0; rst=1'b0; #10 rst=1'b1; #20 rst=1'b0; end endmodule |