银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2020-05-26 | gingko | 初次建立 |
//控制led亮灭的状态机 //状态机流程,复位后进入空闲状态,等待约3s时间闸门打开,点亮led;当检测到时间 //闸门信号的高电平时,熄灭led,再次检测到时间闸门时切换至亮状态,如此循环。 reg led_r; reg [2:0]led_current_state;//当前状态 reg [2:0]led_next_state;//下一个状态 //状态跳转逻辑设计always块 always@(posedge clk_25m or negedge rst_n) begin if(!rst_n) begin led_current_state <= `state_idle; end else begin led_current_state <= led_next_state; end end //状态输出 always@(led_current_state or state_sig or rst_n) begin if(!rst_n) begin led_next_state <= `state_idle; end else begin case(led_current_state) `state_idle:begin if(state_sig) begin led_next_state <= `state_led_on; end else begin led_next_state <= `state_idle; end end `state_led_on:begin if(state_sig) begin led_next_state <= `state_led_off; end else begin led_next_state <= `state_led_on; end end `state_led_off:begin if(state_sig) begin led_next_state <= `state_led_on; end else begin led_next_state <= `state_led_off; end end default:begin led_next_state <= `state_idle; end endcase end end always@(posedge clk_25m or negedge rst_n) //逻辑输出 begin if(!rst_n) begin led_r <= led_off; end else begin case(led_next_state) `state_idle:begin led_r <= led_off; end `state_led_on:begin led_r <= led_on; end `state_led_off:begin led_r <= led_off; end default:begin led_r <= led_off; end endcase end end