可控线性序列机
作者:互联网
可控线性序列机:
可控:有个控制端控制何时输出线性序列。
线性序列机:输出一个线性序列。
知识点:
1.包含多个判定条件时用英文()括起来,用&&连接。
2.使能端EN的设置(类似于D触发器 1触发,0保持),注意不能在最后一个状态时立即跳0,要让这个状态跑完。
3.有多个跳变点时,设计多个计数器就可以(仍要注意位数)。
module led_change7( //可控线性序列机. clk, reset, ctrl, tim, led ); input clk; input reset; input [7:0]ctrl; input [5:0]tim; output reg led ; reg [5:0]counter0;//计数每个状态持续时间 50次,持续1us always@( posedge clk or negedge reset ) begin if ( reset == 0 ) counter0 <= 6'b0 ; else if (counter0 == tim - 1 ) counter0 <= 6'b0 ; else counter0 <= counter0 + 1'd1; end reg [9:0]counter2 ;//整个循环周期 20us always@( posedge clk or negedge reset ) begin if ( reset == 0 ) counter2 <= 10'b0 ; else if (counter2 == 20 * tim - 1 ) counter2 <= 10'b0 ; else counter2 <= counter2 + 1'd1; end reg EN = 1'b1 ;//使能端 always@( posedge clk or negedge reset ) begin if ( reset == 0 ) EN <= 1'b0 ; else if ((counter0 == tim - 1 ) && ( counter1 == 3'b111 )) EN <= 1'b0 ; else if ( counter2 == 10'd0 ) EN <= 1; else EN <= EN ; end reg [2:0]counter1;//计数led的状态 always@( posedge clk or negedge reset ) begin if ( reset == 0 ) counter1 <= 3'b0 ; else if ((counter0 == tim - 1 ) && ( EN == 1'b1)) counter1 <= counter1 + 3'd1 ; else if ( EN == 1'b0 ) counter1 <= 3'b0 ; else counter1 <= counter1 ; end always@( posedge clk or negedge reset ) begin if ( reset == 0 ) led <= 0 ; else case( counter1 ) 3'b000 : led <= ctrl[0] ; 3'b001 : led <= ctrl[1] ; 3'b010 : led <= ctrl[2] ; 3'b011 : led <= ctrl[3] ; 3'b100 : led <= ctrl[4] ; 3'b101 : led <= ctrl[5] ; 3'b110 : led <= ctrl[6] ; 3'b111 : led <= ctrl[7] ; default led <= led ; endcase end endmodule
标签:reset,led,clk,可控,序列,线性,input 来源: https://www.cnblogs.com/fbur/p/16311526.html