1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在100M时钟下,每次扫描都是只扫到第一列的键值,后面的234列都不会扫描到。按键按下时候我延时了20ms用来消抖,按键松开时候也是20ms的消抖,我想请问是我状态机哪里出现问题了
parameter key_jitter1 = 12'd2; //按键检测进行消抖,延时20ms parameter scan_col0 = 12'd4; //扫描第0列 parameter scan_col1 = 12'd8; //扫描第1列 parameter scan_col2 = 12'd16; //扫描第2列 parameter scan_col3 = 12'd32; //扫描第3列 parameter key_judge1 = 12'd64; //按键按下,判断是否为特殊按键 parameter key_pressed = 12'd128; //判断特殊按键按键时间 parameter key_release1 = 12'd256; // parameter key_release2 = 12'd512; // parameter key_pressed3 = 12'd1024; // parameter key_release3 = 12'd2048; // reg [11:0] current_state; reg [11:0] next_state; //现态、次态 //----------延时消抖20ms------------------------------------- parameter delay_20ms = 20000_00; //100M时钟 延时20ms reg [31:0] delay_cnt;//20ms完整的扫描一次 always @ (posedge clk100 or negedge rst_n) if (!rst_n) delay_cnt <= 32'd0; else if(delay_cnt == delay_20ms) delay_cnt <=32'd0; else if(next_state == key_jitter1 | next_state == key_release1 | next_state == key_release2 | next_state == key_release3 ) delay_cnt <=delay_cnt +32'd1; else delay_cnt <=24'd0; wire delay_done; assign delay_done = (delay_cnt == delay_20ms) ? 1'b1:1'b0; //-----------------按键计数1s---------------------------- reg [31:0] cnt_1s; always @ (posedge clk100 or negedge rst_n) if(!rst_n) cnt_1s<=32'd0; else if( row!=5'h1F ) cnt_1s <= cnt_1s +32'd1; else cnt_1s <= 0; wire cnt_1s_sig ; assign cnt_1s_sig = ( cnt_1s >= 32'd9999_9999 )? 1'b1: 1'b0; //长按短按1s判定 //状态机第一部分 always @ (posedge clk100 or negedge rst_n) if(!rst_n) current_state <= idle; else current_state <= next_state; // 状态机第二部分 always @ (*)begin next_state = idle; case (current_state) idle : if (row != 5'h1F) next_state = key_jitter1; else next_state = idle; key_jitter1 : if (row != 5'h1F && delay_done == 1'b1) next_state = scan_col0; else next_state = key_jitter1; scan_col0 : //扫描第0列 if (row != 5'h1F) next_state = key_judge1; else next_state = scan_col1; scan_col1 : // 扫描第1列 if (row != 5'h1F) next_state = key_judge1; else next_state = scan_col2; scan_col2 : // 扫描第2列 if (row != 5'h1F) next_state = key_judge1; else next_state = scan_col3; scan_col3 : // 扫描第3列 if (row != 5'h1F) next_state = key_judge1; else next_state = idle; key_judge1 : // 有按键按下,判断是否为特殊按键 if (({col,row} == 9'b1011_11101) || ({col,row} == 9'b1101_11011) || ({col,row} == 9'b1101_11110) || ({col,row} == 9'b1110_11101) || ({col,row} == 9'b0111_11011) || ({col,row} == 9'b0111_11101) || ({col,row} == 9'b1101_01111) || ({col,row} == 9'b1110_01111)) next_state = key_pressed; else next_state = key_pressed3; key_pressed : if (row != 5'h1F) if (cnt_1s_sig == 1'b0) //特殊按键按住,特殊按键时间小于1S next_state = key_release1; else next_state = key_release2; else next_state = idle; key_release1 : //特殊按键小于1s,释放按键 if (row == 5'h1F && delay_done == 1'b1 ) next_state = idle; else next_state = key_release1; key_release2 : //特殊按键大于1s,释放按键 if (row == 5'h1F && delay_done == 1'b1) next_state = idle; else next_state = key_release2; key_pressed3 : //常规按键按住 if (row != 5'h1F ) next_state = key_release3; else next_state = idle; key_release3 : //常规按键释放 if (row == 5'h1F && delay_done == 1'b1) next_state = idle; else next_state = key_release3; default: next_state = idle; endcase end > |
|
相关推荐
1个回答
|
|
请使用插入代码功能,或者上传附件功能上传代码文件,完整代码上传便于仿真定位问题。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1367 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1046 浏览 0 评论
2442 浏览 1 评论
2146 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2408 浏览 0 评论
1881 浏览 49 评论
6018 浏览 113 评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 12:12 , Processed in 0.484851 second(s), Total 71, Slave 54 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号