作者deathcustom (about to be couple)
看板Electronics
標題Re: [問題] verilog 一個按鍵多重功能
時間Mon Jun 2 18:31:36 2014
※ 引述《light0617 (期待寒假)》之銘言:
: 各位大大打擾了
: 最近在實作一個按鍵多重功能
: 也就是
: 按一次開始 再按一次暫停
: 老實說 我有寫出來 但是還是有點奇怪
: 有時候按了沒反應 懷疑是沒有在同一個clk中的關係
: 我的部份的CODE如下:
: input i_start_stop;
: input i_clk;
: input i_rts;
: reg start_ind=1'b0;
: reg [28:0]cnt;
: always @(negedge i_start_stop )//start_stop
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
以下這個block是在"i_start_stop"負緣觸發
: begin
: if(i_start_stop==0)
^^^^^^^^^^^^^^^^^^^^判斷式寫如果"i_start_stop"等於零才作動
: begin
: if(start_ind==1'b1) start_ind<=1'b0;
: else start_ind<=start_ind+1'b1;
: end
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^這個block
基本上讀起來像是要把start_ind反向一次
: end
這個邏輯其實很怪啊,你說要在i_start_stop信號falling的那一瞬間去判斷
i_start_stop信號是1還是0......how do you do it?
在你跳下懸崖的一瞬間判斷你是在懸崖上還是摔死了......queer
請直接把negedge拿掉
: always@(posedge i_clk , negedge i_rts)
: begin
: if(~i_rts) cnt<=29'b0;
: else if(start_ind==1'b1) cnt<=cnt+1'b1;
: end
: 若第一個改成
: always @(negedge i_start_stop, i_clk )//start_stop
改成這樣則是每一次的i_start_stop負緣或是i_clk改變就判斷一次
所以i_clk的正緣與負緣都會觸發判斷
當然跑起來更怪
: 跑起來更奇怪
: 若把i_start_stop 寫在always@(posedge i_clk , negedge i_rts)
: 又不知如何實作
: 麻煩各位大大了
you may try it :)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.159.149.114
※ 文章網址: http://www.ptt.cc/bbs/Electronics/M.1401705099.A.362.html
→ deathcustom:另外<=跟=的差別要弄清楚~"~ 06/02 18:32
→ deathcustom:另一種方式就是always@ (negedge i_start_stop)中 06/02 18:34
→ deathcustom:不用寫if(i_start_stop==0),因為你negedge後一定是0 06/02 18:34
推 light0617:第一種方法 若去掉if 我也試過了 效果還是一樣 06/02 18:58
→ light0617:大約也是10次有一次按了沒反應 在想是不是硬體問題 06/02 18:58
→ light0617:若是OCDE需要改 我只想到把它加入 同一個always 上 06/02 18:58
→ light0617:同一alway中用if(i_start_stop==0) 無法 因為我是用加的 06/02 19:00
→ light0617:當它等於0時(手按下去 事實上已跑了好幾個clk)會加多次 06/02 19:01