Skip to content

Instantly share code, notes, and snippets.

@furkanusta
Created February 21, 2019 15:46
Show Gist options
  • Save furkanusta/ba100439ea9de4fdf568a62b39800be4 to your computer and use it in GitHub Desktop.
Save furkanusta/ba100439ea9de4fdf568a62b39800be4 to your computer and use it in GitHub Desktop.
// Same wrapping counter as the above. However, increment is made blocking so that 'if' check will
// be correct. However, mixing blocking and non-blocking code can cause more problems in larger
// designs. Paste this code in Vivado and read the warning
module counter(input clock, reset, trigger, input[4:0] limit, output[4:0] out);
   logic[4:0] data;
   always_ff @(posedge clock) begin
      if (reset)
        data <= 5'b0;
      else if (trigger) begin
         data = data + 1'b1;
         if (data == limit)
           data <= 5'b0;
      end
   end
   assign out = data;
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment