作者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://webptt.com/cn.aspx?n=bbs/Electronics/M.1401705099.A.362.html
1F:→ deathcustom:另外<=跟=的差别要弄清楚~"~ 06/02 18:32
2F:→ deathcustom:另一种方式就是always@ (negedge i_start_stop)中 06/02 18:34
3F:→ deathcustom:不用写if(i_start_stop==0),因为你negedge後一定是0 06/02 18:34
4F:推 light0617:第一种方法 若去掉if 我也试过了 效果还是一样 06/02 18:58
5F:→ light0617:大约也是10次有一次按了没反应 在想是不是硬体问题 06/02 18:58
6F:→ light0617:若是OCDE需要改 我只想到把它加入 同一个always 上 06/02 18:58
7F:→ light0617:同一alway中用if(i_start_stop==0) 无法 因为我是用加的 06/02 19:00
8F:→ light0617:当它等於0时(手按下去 事实上已跑了好几个clk)会加多次 06/02 19:01