Forum Discussion
DE2 Quartus debounced circuit
Hello,
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.15 Replies
- Altera_Forum
Honored Contributor
Normally there are delayed timer double check circuit and state machine circuit used as debouncer.
You will find spending a while on google. - Altera_Forum
Honored Contributor
Actually, I believe DE2 switches are debounced with a 74HC245. You should not see multiple inputs for a single button depression. Remember that the switches (or 'key's) are active high. When you push the button it will be low for the period of time that you have it depressed (which even if you push it very quickly will be many thousands of clock cycles). But you will not see it oscillate between a one and a zero after it is depressed (you can prove this to yourself by building a simple SignalTap file and analyzing the operation in hardware). In order to ensure your circuit operates appropriately I would suggest that you watch for the switch (or key) to go from a low to a high (the switches are a logic 1 when not depressed). This will ensure that a single button press results in your code executing only once. If you post your code snippet, then I will have a look...
- Altera_Forum
Honored Contributor
Hi, I'm actually using pushbuttons on an external circuit and not the pushbuttons on the DE2. I'm going to build debounced circuitry in Quartus to fix it. Thanks for the reply.
- Altera_Forum
Honored Contributor
Kofinator,
Please post your reference design when you're done if you don't mind sharing. - Altera_Forum
Honored Contributor
am working on a design project and have a DE2-70 board.I want to control on board LEDS
from my PC. How can I make dialogue based application using NIOS II IDE. - Altera_Forum
Honored Contributor
In case it's useful, this is a general purpose filter I use for IO pins. Debouncing is a special case. The logic is very tight and fast. You'll need to adjust the freq, limit, and N to suit your needs.
module filter(input clock, input in, output reg out, // out a filtered version of in output reg strobe); // true for one cycle synchronous with a change parameter freq = 25_000_000; // 25MHz parameter limit = 50_000; // 50kHz parameter dur = freq / limit; parameter N = 14; // INV: 2**N > dur; reg countdown; // Filter out any meta stability reg in_, in__; always @(posedge clock) begin strobe <= 0; in_ <= in; in__ <= in_; if (in__ == out) countdown <= dur - 1; // Note, we depend on countdown being reset here. else if (~countdown) countdown <= countdown - 1; else begin out <= ~out; strobe <= 1; end end endmodule - Altera_Forum
Honored Contributor
Oops. I used the wrong version.
Please change "if (in__ == out)" to "if (in__ != out)". Also, rather than "out <= ~out;" using the equivalent "out <= in__;" may be more readable. Tommy - Altera_Forum
Honored Contributor
Hi,
Everytime I see code with parameters, some manual action has to be done for setting the bit-width of a register (counter). There is a nice trick with a 'constant-function' to prevednt this action : change this :
and add :parameter N = CLogB2(dur);//ceil of the log base 2 function integer CLogB2; input Depth; integer i; begin i = Depth; for(CLogB2 = 0; i > 0; CLogB2 = CLogB2 + 1) i = i >> 1; end endfunction - Altera_Forum
Honored Contributor
Thanks. There were two reasons I didn't use such a function: it would have distracted from the main point, and my simulator doesn't (didn't?) support functions.
- Altera_Forum
Honored Contributor
Try www.veritak.com. It's really worth its 50$