06 Task Performance 1 - ARG
06 Task Performance 1 - ARG
BSCpE – 601
// Testbench
module tb_binary_up_counter;
reg clk = 0;
reg reset = 1;
wire [1:0] count;
initial begin
// Dump waveform
$dumpfile("counter.vcd");
$dumpvars(0, tb_binary_up_counter);
Output:
Pseudocode:
BEGIN
// Initialization (implicit in hardware/reset behavior)
count ← 00
// This block always “runs” on every rising clock edge or if reset is asserted
ON each rising_edge(clk) or rising_edge(reset) DO
IF reset == 1 THEN
count ← 00 // Force counter to 0 when reset is high
ELSE
count ← count + 1 // Increment by one (wraps from 11 → 00)
END IF
END ON
END
Explanation of each step:
1. Initialization:
o When the system first powers up (or when reset is asserted), count is
driven to 00.
2. Sensitivity List (posedge clk or posedge reset):
o On any rising edge of clk, we will update count.
o On any rising edge of reset, we immediately force count = 00, regardless
of clk.
3. Reset Check:
o If reset is detected high, set count = 00.
o Otherwise (i.e., normal clock edge with reset = 0), increment count by 1.
4. Natural Binary Wraparound:
o Since count is a 2-bit register, adding 1 to 2’b11 automatically rolls it over
to 2’b00.
Flowchart:
Is reset == 1?
yes no