Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
18 years ago

DE2 Quartus Debounced Circuitry

Hello Folks,

I am working on a senior design project and have a DE2 board connected to external circuitry. There are pushbuttons on the external circuit which control leds also on that circuit board. My design requires that I press the pushbutton and the led lights up and I press it a second time and the led goes off.

It turns out that those pushbuttons which are single-pole-double-throw (SPDT) are not debounced and give multiple outputs when I want a clean signal.

I would like to know if there is a reference design so I can build debounced circuitry for the buttons in Quartus. If not, how do I build debouncers in Quartus for SPDT pushbuttons?

Thanks.

Kofi.

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    suggest you write a small FSM, if you could not find fitting code.

    S0 (off)

    S1 (switch to on and withhold for timer to verify)

    S2 (on)

    S3 (switch to off and wtihhold for timer to verify)

    S0

    /

    S1 S3

    \ /

    S2
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    Heres a (4) switch debouncer written in AHDL quite like mentioned above:

    Hope it works for you - it certainly works for me.

    Peter

    -------------------------------------------------------------------

    SUBDESIGN debounce

    (

    clk : INPUT;

    key_pressed[3..0] : INPUT;

    pulse[3..0] : OUTPUT;

    )

    VARIABLE

    count_reg0[20..0] : DFF;

    at_zero0 : NODE;

    count_reg1[20..0] : DFF;

    at_zero1 : NODE;

    count_reg2[20..0] : DFF;

    at_zero2 : NODE;

    count_reg3[20..0] : DFF;

    at_zero3 : NODE;

    BEGIN

    % Preset to 255 when key bounces or is not %

    % pressed. Decrement when key is pressed. %

    %-0---%

    count_reg0[].clk = clk;

    count_reg0[].prn = not key_pressed[0];

    count_reg0[].d = count_reg0[].q - (00000,!at_zero0);

    % Emit single pulse when counter reaches 1. %

    pulse[0] = count_reg0[].q == h"00001";

    % Don't let counter decrement below zero. %

    at_zero0 = count_reg0[].q == h"00000";

    %-1---%

    count_reg1[].clk = clk;

    count_reg1[].prn = not key_pressed[1];

    count_reg1[].d = count_reg1[].q - (00000,!at_zero1);

    % Emit single pulse when counter reaches 1. %

    pulse[1] = count_reg1[].q == h"00001";

    % Don't let counter decrement below zero. %

    at_zero1 = count_reg1[].q == h"00000";

    %-2---%

    count_reg2[].clk = clk;

    count_reg2[].prn = not key_pressed[2];

    count_reg2[].d = count_reg2[].q - (00000,!at_zero2);

    % Emit single pulse when counter reaches 1. %

    pulse[2] = count_reg2[].q == h"00001";

    % Don't let counter decrement below zero. %

    at_zero2 = count_reg2[].q == h"00000";

    %-3--%

    count_reg3[].clk = clk;

    count_reg3[].prn = not key_pressed[3];

    count_reg3[].d = count_reg3[].q - (00000,!at_zero3);

    % Emit single pulse when counter reaches 1. %

    pulse[3] = count_reg3[].q == h"00001";

    % Don't let counter decrement below zero. %

    at_zero3 = count_reg3[].q == h"00000";

    END;