Debouncing pushbuttons in verilog

debounceverilog

I have two circuits which I have designed using verilog.One is Counter circuit and other is the debouncing pushbutton circuit.but I dont now how to instantiate a model so that the pushbutton circuit is also included in the main module of counter.Please help me.I am using a Digilent Basys-2 Spartan Board xc3s100e

 Counter Circuit
  module button_binary(
    input clock,
    input reset,
    input button,
    output led,
    output led2,
    output led3,
    output led4,
    output led5,
    output led6,
    output led7,
    output led8
    );

    reg [7:0]count;

    debouncing U1
    (
    .clock  (clock),
    .reset  (reset),
    .button  (button)
    );



 always @ (posedge clock or posedge reset)
   begin
    if (reset)
        count <= 0;
    else if (button)
        count <= count + 1;
    end

    assign led = count[0];
    assign led2 = count[1];
    assign led3 = count[2];
    assign led4 = count[3];
    assign led5 = count[4];
    assign led6 = count[5];
    assign led7 = count[6];
    assign led8 = count[7];
 endmodule 

Best Answer

I am not sure what you mean by main module, but I assume you mean that you are trying to include the debouncing module inside of your counter module??

If so, I would create two different verilog files, one with each module. In the counter module, to instantiate an instance of the debouncing module, you use the following syntax:

debouncing U0(
    .clock(clock_input_to_module),
    .reset(reset_input_to_module),
    .button(button_input_to_module),
    .out(out_output_from_module)
);

U0 is the name of the instance, and the variable names inside the parenthesis are wires and regs that you declare in the counter module. The names with the periods in front are the I/Os of the debouncing module.

Regardless though, if you need to instantiate a module, the above syntax is the method to do so.