-1

I have a top module that implements a 14-bit counter.

I added an input button in the top module and to the 14-bit counter

In the counter I check to see if the button is pressed and if so reset the counter to 0.

I have also added the line

NET "button" LOC = K18;

to the .ucf file.

But the design will not implement. It complains that button is defined but not used and something about button_ibuf and button has no load...

does anyone have an idea what is wrong with my code?

here is the counter module

module counter_14bit(
input wire counter_clk_signal,
input wire switch,          // enable / disable the counter
input wire button,          // reset the counter to 0
output reg [13:0] counter=0     // 14 bit counter value (0-16383)
    );

always@(posedge counter_clk_signal)
begin   
    if (switch == 0) begin
        counter <= counter;
    end
    
    // max 14-bit unsigned value is 16383 but my board has only 4 sseg displays so
    // limit counter to 9999 max
    if (switch == 1) begin
        if (button == 1) begin
           counter <= 0;    // reset counter to 0 if button 1 is pressed
        end
        if (counter == 9999) begin  // reset counter to 0 if counter is 9999
            counter <= 0;
        end else begin
            counter <= counter+1;
        end
    end

end

endmodule
2
  • Is counter_14bit the top-level module, or where is it instantiated? Commented Aug 6, 2023 at 15:46
  • you should provide more information about error messages and the code around the counter_14b module. something about button_ibuf and button has no load.. is not very descriptive. Commented Aug 6, 2023 at 18:16

1 Answer 1

-1

You must remember that in the Verilog the non-blocking assignments are not executed sequentially, but all executed simultaneously. All the effects of all assignments will be applied at the end of the always block, and if there are multiple assignments to the same register - the last assignment wins.

You have counter assigned multiple times, once after checking the button input, and then by result of checking the counter against 9999. That second section overrides anything done on counter prior that manipulation.

Move the if (button) section below the section that counts up or wraps the counter around 9999.

Sign up to request clarification or add additional context in comments.

1 Comment

actually, it can be solved by adding 'else' after the button's 'if'. or 'if (button == 1 || conter == 9999)' will also work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.