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

0 Members and 1 Guest are viewing this topic.

Offline Harrkev

  • Contributor
  • Posts: 37
  • Country: us
  • ASIC Design Engineer
Re: EEVblog #961 - Monkey Debouncing
« Reply #25 on: December 29, 2016, 08:06:41 pm »
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.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: EEVblog #961 - Monkey Debouncing
« Reply #26 on: December 29, 2016, 09:10:36 pm »
[quote author=PeterL link=topic=80536.msg1100856#msg1100856 date=1482940579}
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]

Oh, sorry, I wasn't reading right. I read Joules instead of Coulombs. Doh.  :palm:
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.
 

Online joeqsmith

  • Super Contributor
  • ***
  • Posts: 5905
  • Country: us
Re: EEVblog #961 - Monkey Debouncing
« Reply #27 on: December 30, 2016, 01:48:05 am »

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.       
How electrically robust is your meter?? https://www.youtube.com/channel/UCsK99WXk9VhcghnAauTBsbg
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 10180
  • Country: 00
Re: EEVblog #961 - Monkey Debouncing
« Reply #28 on: December 30, 2016, 09:53:31 am »

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  :)
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 1793
  • Country: fi
  • Embedded SW/HW.
Re: EEVblog #961 - Monkey Debouncing
« Reply #29 on: December 30, 2016, 01:03:30 pm »
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:
 

#define ADC_THRESHOLD_RANGE 255
function Get_Threshold() : int
begin
  return ADC value between 0 ...  ADC_THRESHOLD_RANGE
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

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf