This initial block forms the stimulus of the testbench If reset is 1, then design should be allowed to count up, so increment counter Once inside this block, it checks if the reset is 0, if yes then change out to zero This always block will be triggered at the rising edge of clk (0->1) Output reg out) // Declare 4-bit output port to get the counter values Input rstn, // Declare input port for reset to allow the counter to be reset to 0 when required Module counter ( input clk, // Declare input port for clock to allow counter to count up There is a 4-bit output called out which essentially provides the counter values. An active-low reset is one where the design is reset when the value of the reset pin is 0. The design contains two inputs one for the clock and another for an active-low reset. When counter is at a maximum value of 4'b1111 and gets one more count request, the counter tries to reach 5'b10000 but since it can support only 4-bits, the MSB will be discarded resulting in 0. The rollover happens when the most significant bit of the final addition gets discarded. It will keep counting as long as it is provided with a running clock and reset is held high. The 4-bit counter starts incrementing from 4'b0000 to 4'h1111 and then rolls over back to 4'b0000.
0 Comments
Leave a Reply. |