<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 非同于MCU的獨(dú)立按鍵消抖動(dòng)

          非同于MCU的獨(dú)立按鍵消抖動(dòng)

          作者: 時(shí)間:2012-03-08 來(lái)源:網(wǎng)絡(luò) 收藏

          module key_scan

          #(

          parameter KEY_WIDTH = 2

          )

          (

          input clk, //50MHz

          input rst_n,

          input [KEY_WIDTH-1:0] key_data,

          output key_flag,

          output reg [KEY_WIDTH-1:0] key_value

          );

          //---------------------------------

          //escape the jitters

          reg [19:0] key_cnt; //scan counter

          reg [KEY_WIDTH-1:0] key_data_r;

          always @(posedge clk or negedge rst_n)

          begin

          if(!rst_n)

          begin

          key_data_r = {KEY_WIDTH{1'b1}};

          key_cnt = 0;

          end

          else

          begin

          key_data_r = key_data; //lock the key value

          if((key_data == key_data_r) (key_data != {KEY_WIDTH{1'b1}})) //20ms escape jitter

          begin

          if(key_cnt 20'hfffff)

          key_cnt = key_cnt + 1'b1;

          end

          else key_cnt = 0;

          end

          end

          wire cnt_flag = (key_cnt == 20'hffffe) ? 1'b1 : 1'b0;//!!

          //-----------------------------------

          //sure the key is pressed

          reg key_flag_r;

          always@(posedge clk or negedge rst_n)

          begin

          if(!rst_n)

          begin

          key_flag_r = 0;

          key_value = 0;

          end

          else if(cnt_flag)

          begin

          key_flag_r = 1;

          key_value = key_data; //locked the data

          end

          else //let go your hand

          key_flag_r = 0; //lock the key_value

          end

          //---------------------------------------

          //Capture the rising endge of the key_flag

          reg key_flag_r0,key_flag_r1;

          always@(posedge clk or negedge rst_n)

          begin

          if(!rst_n)

          begin

          key_flag_r0 = 0;

          key_flag_r1 = 0;

          end

          else

          begin

          key_flag_r0 = key_flag_r;

          key_flag_r1 = key_flag_r0;

          end

          end

          assign key_flag = ~key_flag_r1 key_flag_r0;

          endmodule


          上一頁(yè) 1 2 3 下一頁(yè)

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();