银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2020-22-26 | gingko | 初次建立 |
//-----------------------------------------------------// //循环计数1秒 reg [31:0] time_cnt; reg state_sig; always@(posedge fpga_clk or negedge rst_n) if(!rst_n) time_cnt <=32'd0; else if(time_cnt == 32'd25_000_000) time_cnt <= 32'd0; else time_cnt <= time_cnt + 1'd1; //每计数满1秒拉高1个脉冲信号 always@(posedge fpga_clk or negedge rst_n) if(!rst_n) state_sig <= 1'b0; else if(time_cnt == 32'd25_000_000) state_sig <= 1'b1; else state_sig <= 1'b0;
//时序逻辑,控制状态跳转 always@(posedge fpga_clk or negedge rst_n) if(!rst_n) led_current_state <= `state_idle; else led_current_state <= led_next_state; //组合逻辑,控制状态跳转条件及状态输出 always@(led_current_state or state_sig or rst_n) if(!rst_n) begin led_r <= LED_ON; led_next_state <= `state_idle; end else case(led_current_state) `state_idle:begin//触发信号有效,则跳转到led_on状态,否则,保持当前状态 if(state_sig) begin led_next_state <= `state_led_on; led_r <= LED_ON; //点亮LED end else led_next_state <= `state_idle; end `state_led_on:begin if(state_sig)//触发信号有效,则跳转到led_off状态,否则保持当前状态 begin led_next_state <= `state_led_off; led_r <= LED_OFF; //熄灭LED end else led_next_state <= `state_led_on; end `state_led_off:begin if(state_sig)//触发信号有效,则跳转到led_on状态,否则保持当前状态 begin led_next_state <= `state_led_on; led_r <= LED_ON; //点亮LED end else led_next_state <= `state_led_off; end endcase
1、 通过HqInsight采样状态机跳转信号及状态寄存器的值,观察信号变化。 2、 对比一段式状态机和二段式状态机状态跳转的时序有何不同。