Author Topic: EEVblog #961 - Monkey Debouncing  (Read 10532 times)

0 Members and 1 Guest are viewing this topic.

Harrkev

• Contributor
• Posts: 37
• Country:
• ASIC Design Engineer
Re: EEVblog #961 - Monkey Debouncing
« Reply #25 on: December 30, 2016, 07:06:41 am »
OK.  I am confused.  At around the 14 minute mark, there is a circuit shown with a diode bypassing R2 so that, when charging, R2 does not matter.  In that case, only R2 is used for discharging, and only R1 is used for charging.

Ummmm, given that R2 is going to be much smaller than R1, couldn't we just choose a new R1 that is found by R1 - R2?  That saves us having to put a diode in there at all!  One fewer part is a good thing.

I could see needing the diode if, for some reason, R2 > R1.  However, that does not seem to be the case here.

Yansi

• Super Contributor
• Posts: 2385
• Country:
• STM32, STM8, AVR, 8051
Re: EEVblog #961 - Monkey Debouncing
« Reply #26 on: December 30, 2016, 08:10:36 am »
This circuit is also a bit high on the load of the batteries that feed the switch. At each (1st)clap 1mC is thrown away. So I expect the batteries are starting to drain after a couple of thousand claps.

How did you get to 1mC?   I thought he used 330uF and 3V. That is 3mC per each clap.

To my best knowledge it's: Q=C x U
3 times 330u gives 990u...
[/quote]

0,5*C*U^2 per discharge lost in the ESR when switch closes, the same 0,5CU^2 lost on charge in the pullup resistor. ... if I am not mistaken.

joeqsmith

• Super Contributor
• Posts: 5354
• Country:
Re: EEVblog #961 - Monkey Debouncing
« Reply #27 on: December 30, 2016, 12:48:05 pm »

if clear = '1' then
state <= S_INIT;
cnt <= (others => '0');               -- Reset filter timer
filt_out <= '0';                      -- Force output low
elsif (clock'event and clock = '1') then
...

Hmm, asynchronous reset, this can have metastability problems. And we are in 2016, you can write "elsif rising_edge(clock) then" (and parentheses are not needed). Every synthesis tool should understand this by now.

Hmm, I guess S0 state should have been S_INIT.  Codes there just to give readers another way to look at the simple debounce problem.

Fungus

• Super Contributor
• Posts: 9580
• Country:
Re: EEVblog #961 - Monkey Debouncing
« Reply #28 on: December 30, 2016, 08:53:31 pm »

if clear = '1' then
state <= S_INIT;
cnt <= (others => '0');               -- Reset filter timer
filt_out <= '0';                      -- Force output low
elsif (clock'event and clock = '1') then
...

Hmm, asynchronous reset, this can have metastability problems. And we are in 2016, you can write "elsif rising_edge(clock) then" (and parentheses are not needed). Every synthesis tool should understand this by now.

Hmm, I guess S0 state should have been S_INIT.  Codes there just to give readers another way to look at the simple debounce problem.

I liked my code better, even if it did block. KISS

Kalvin

• Super Contributor
• Posts: 1775
• Country:
• Embedded SW/HW.
Re: EEVblog #961 - Monkey Debouncing
« Reply #29 on: December 31, 2016, 12:03:30 am »
Modified the original pseudocode to allow dynamically adjustable debounce time using the A/D-converter and a trimpot connected toe ADC-input and between VCC and GND:

function Get_Threshold() : int
begin
end
#define SAMPLE_TIME_ms 1
state = input_pin_state
count = Get_Threshold() / 2
loop forever:
threshold = Get_Threshold()
if input_pin_state == 0:
/* switch closed, react fast */
count = 0
state = 0
else
/* switch opened, debounce */
if count < threshold:
count = count + 1
endif
if count >= threshold:
state = 1
count = threshold
endif
endif
output_pin_state = state
delay SAMPLE_TIME_ms
endloop

Smf