updown_counter.v
上传用户:yecheng
上传日期:2013-03-04
资源大小:120k
文件大小:1k
源码类别:

邮电通讯系统

开发平台:

Matlab

  1. module updown_counter(clk,reset,u_dn,ahead,lag,ldn);
  2. input clk,reset,u_dn;
  3. output ahead,lag;
  4. output ldn;
  5. wire ahead,lag;
  6. wire ldn;
  7. reg[5:0] counter;
  8. parameter UP_COUNTER=6'd35;
  9. parameter DOWN_COUNTER=6'd29;
  10. assign ahead=(counter==UP_COUNTER);
  11. assign lag=(counter==DOWN_COUNTER);
  12. assign ldn=~(ahead|lag);
  13. always@(posedge clk or negedge reset)
  14.   if(!reset)
  15.     begin
  16.       counter<=6'd32;
  17.     end
  18.   else
  19.     begin
  20.       if(!ldn)
  21.          counter<=6'd32;
  22.       else
  23.         if(u_dn)
  24.           counter<=counter+1;
  25.         else
  26.           counter<=counter-1;
  27.     end
  28. endmodule