Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. module bin_cnt
  3. (
  4.     input logic clk, resetn,
  5.     int start,
  6.     output logic [3:0] count
  7. );
  8.  
  9. int it;
  10. logic cond;
  11.  
  12.     always @ (posedge clk or negedge resetn)
  13.     begin
  14.        
  15.         if (!resetn)
  16.             begin
  17.                 count <= 0;
  18.                 it = 0;
  19.                 cond = 1;
  20.             end
  21.         else
  22.             if(cond)
  23.             if (count==(start-it))
  24.                 begin
  25.                     if((start-it)<=(it+1))
  26.                         begin
  27.                             cond = 0;
  28.                             count <= count - 1;
  29.                         end
  30.                     else
  31.                     count <= it
  32.                     it <= it + 1;
  33.                 end
  34.             else
  35.                 count <= count + 1;
  36.     end
  37.  
  38. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement