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

0 Members and 1 Guest are viewing this topic.

Offline EEVblog

  • Administrator
  • *****
  • Posts: 22870
  • Country: au
    • EEVblog
EEVblog #961 - Monkey Debouncing
« on: December 28, 2016, 01:41:54 PM »
How do you debounce a clapping monkey?
Probes The Monkey makes his return.
All about contact debouncing, setting up a universal counter as an event counter, and other issues that can arise on a seemingly simple test setup.

 
The following users thanked this post: SeanB, jonovid

Offline joeqsmith

  • Super Contributor
  • ***
  • Posts: 2583
  • Country: us
Re: EEVblog #961 - Monkey Debouncing
« Reply #1 on: December 28, 2016, 02:57:57 PM »
Interesting.  I would have used a hall sensor or optics and filtered it in the digital domain.  Looking forward to seeing the actual testing of that little boost converter.
How electrically robust is your meter?? https://www.youtube.com/channel/UCsK99WXk9VhcghnAauTBsbg
 

Offline ECEdesign

  • Regular Contributor
  • *
  • Posts: 168
  • Country: us
Re: EEVblog #961 - Monkey Debouncing
« Reply #2 on: December 28, 2016, 03:19:03 PM »
We were taught to use a latch to debounce a switch at Uni
 

Online rob77

  • Super Contributor
  • ***
  • Posts: 1732
  • Country: sk
Re: EEVblog #961 - Monkey Debouncing
« Reply #3 on: December 28, 2016, 03:30:15 PM »
"how many times it claps" in a chinese or japanese accent would be much more funny   :-DD
 
The following users thanked this post: jonovid

Online rrinker

  • Super Contributor
  • ***
  • Posts: 1302
  • Country: us
Re: EEVblog #961 - Monkey Debouncing
« Reply #4 on: December 28, 2016, 04:06:22 PM »
 Or German. "Ve haf veys of making you clap, monkey!"
 

Offline MartinX

  • Regular Contributor
  • *
  • Posts: 103
  • Country: se
Re: EEVblog #961 - Monkey Debouncing
« Reply #5 on: December 28, 2016, 08:03:34 PM »
Worth mentioning is also that constantly shorting a capacitor will over time seriously corrode the contact surfaces, so the circuit will appear to work in the beginning but may stop counting after a while.
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 5197
Re: EEVblog #961 - Monkey Debouncing
« Reply #6 on: December 28, 2016, 09:34:29 PM »
Use an Arduino!

It's two minutes' work to write a sketch that waits a minimum time between claps.

It can output pulses to your counter for display.

Code: [Select]
pinMode(counterOut,OUTPUT);
pinMode(clap,INPUT_PULLUP);

if (digitalRead(clap)==0) {
  // This creates 20ms of delay before it will recognize another clap
  // Adjust timing as needed
  digitalWrite(counterOut,LOW);
  delay(10);
  digitalWrite(counterOut,HIGH);
  delay(10);
}
« Last Edit: December 28, 2016, 10:32:35 PM by Fungus »
 
The following users thanked this post: jonovid

Offline kalleboo

  • Regular Contributor
  • *
  • Posts: 100
  • Country: jp
Re: EEVblog #961 - Monkey Debouncing
« Reply #7 on: December 28, 2016, 10:06:21 PM »
It's two minutes' work to write a sketch that waits a minimum time between claps.
Will that be reliable if there's noise on the line when it's making the squeaking noises?
 

Offline max_torque

  • Frequent Contributor
  • **
  • Posts: 567
  • Country: gb
    • bitdynamics
Re: EEVblog #961 - Monkey Debouncing
« Reply #8 on: December 28, 2016, 10:10:08 PM »
Whilst the 330uF cap across the inputs of the counter is, frankly, at least 10x too large for this job, it does suggest the false counting from the head nodding motor noise has to be common mode noise, because that massive cap creates a low impedance AC "short" across the input of the counter.  Putting the two leads from Probes hands together a couple of turns round a large ferrite (as a common mode choke) would probably have fixed the issue without requiring the pass filter device used!
 

Offline strangersound

  • Regular Contributor
  • *
  • Posts: 135
  • Country: us
  • Resistance Is Not Futile
Re: EEVblog #961 - Monkey Debouncing
« Reply #9 on: December 28, 2016, 10:13:22 PM »
This was great lesson. What appears on the surface to be a pointless and silly exercise turns out to be a good lesson in setting up a test and some basic functions of multiple pieces of test gear, and even various signal issues such as noise, shape, etc.  :-+
"I learned a long time ago that reality was much weirder than anyone's imagination." - Hunter S. Thompson
 
The following users thanked this post: jonovid

Online Fungus

  • Super Contributor
  • ***
  • Posts: 5197
Re: EEVblog #961 - Monkey Debouncing
« Reply #10 on: December 28, 2016, 10:19:04 PM »
It's two minutes' work to write a sketch that waits a minimum time between claps.
Will that be reliable if there's noise on the line when it's making the squeaking noises?

If there's that much noise on the line then the entire setup won't work anyway, doesn't matter what you do.

I think Dave's choice of components in the video isn't great - the capacitor/resistor values are much too large and will leave it very susceptible to noise. Maybe he chose those values to make a pretty video (see the capacitor charge!). In real life the capacitor should recharge in much less than a second.
« Last Edit: December 28, 2016, 10:42:39 PM by Fungus »
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 5197
Re: EEVblog #961 - Monkey Debouncing
« Reply #11 on: December 28, 2016, 10:26:04 PM »
Just saw this while surfing...


 
The following users thanked this post: lpickup, kalleboo, jonovid

Offline amspire

  • Super Contributor
  • ***
  • Posts: 2955
  • Country: au
Re: EEVblog #961 - Monkey Debouncing
« Reply #12 on: December 28, 2016, 10:35:44 PM »
Most top-end counters have a gate hold-off or delay so that once it triggers, it will not trigger again for the delay/hold-off time you set.

With this method, the noise becomes irrelevant because the counter trigger is disabled for the duration of the noise.

Doesn't this counter have a delay->time setting?

Edit: had a quick look at the manual and it looks like it does have a delay function but it may be it only works with the external gate input. Not sure about that.
« Last Edit: December 28, 2016, 10:45:37 PM by amspire »
 

Offline Faith

  • Supporter
  • ****
  • Posts: 101
  • Country: sg
Re: EEVblog #961 - Monkey Debouncing
« Reply #13 on: December 29, 2016, 12:02:56 AM »
Mm, not sure if it's a good idea to measure number of "cycles" versus exact numbers of claps.

If I recall correctly from previous videos Probes The Monkey does slow down in clapping quite significantly at lower voltage levels.

Thus you'll reach a point where it becomes a little trickier in determining exactly what one cycle is.

Since one clap at low voltage could be as long as one entire cycle at nominal voltage.

Other than that, super interesting video!~ Thanks much :D
~ Faith <3 ~
 
The following users thanked this post: lpickup

Offline PeterL

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
Re: EEVblog #961 - Monkey Debouncing
« Reply #14 on: December 29, 2016, 02:56:19 AM »
Whilst the 330uF cap across the inputs of the counter is, frankly, at least 10x too large for this job, it does suggest the false counting from the head nodding motor noise has to be common mode noise, because that massive cap creates a low impedance AC "short" across the input of the counter.  Putting the two leads from Probes hands together a couple of turns round a large ferrite (as a common mode choke) would probably have fixed the issue without requiring the pass filter device used!

I agree on this one, in fact I would say it's at least 1000x to large for a normal design. For a simple one-time solution like Dave needs here a quick-and-dirty solution is more acceptable, but I was hoping for a 555 solution right from the start.

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.
 

Offline joeqsmith

  • Super Contributor
  • ***
  • Posts: 2583
  • Country: us
Re: EEVblog #961 - Monkey Debouncing
« Reply #15 on: December 29, 2016, 04:53:47 AM »
It's two minutes' work to write a sketch that waits a minimum time between claps.
Will that be reliable if there's noise on the line when it's making the squeaking noises?

If there's that much noise on the line then the entire setup won't work anyway, doesn't matter what you do.

I think Dave's choice of components in the video isn't great - the capacitor/resistor values are much too large and will leave it very susceptible to noise. Maybe he chose those values to make a pretty video (see the capacitor charge!). In real life the capacitor should recharge in much less than a second.

I think the micro is fine but not use a simple delay.  You really want a counter running at some rate faster than the cycle time that is reading the input and waiting for it to settle.  Any change in the input state resets the counter.  So you want what ever your debounce time to be a number of consecutive reads of the input with no state change.



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
  case state is
    when S_INIT    =>
      nt <= (others => '0');           -- Reset filter timer
      if input /= filt_out then         -- Test input state change
        state <= S_SETTLE;              -- Wait for input to settle
      end if;
    when S_SETTLE  =>
      cnt <= cnt + 1;                   -- Increment the filter timer
      if input = filt_out then          -- Check if input glitched
        state <= S_INIT;                -- Glitched, reset filter
      elsif cnt > FILTPERIOD then       -- Check filter timeout
        state <= S_DEBNCED;             -- We have a clean signal
      end if;
    when S_DEBNCED =>
      filt_out <= input;                -- Change output state
      state <= S_INIT;                  -- Reset filter and search for next edge
    when others=>
      state <= s0;                      -- We are lost, reset filter
  end case;
end if;




How electrically robust is your meter?? https://www.youtube.com/channel/UCsK99WXk9VhcghnAauTBsbg
 

Offline lpickup

  • Regular Contributor
  • *
  • Posts: 87
  • Country: us
  • Uncle Bobby Dazzler
Re: EEVblog #961 - Monkey Debouncing
« Reply #16 on: December 29, 2016, 05:38:52 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.
No worries, mate!  Just slap a batteriser on it, and she'll be right!

In all seriousness though, the batteries driving the switch detector circuitry should last an order of magnitude or so longer than the batteries driving Probes, no?

 

Offline Dave

  • Frequent Contributor
  • **
  • Posts: 979
  • Country: si
  • I like to measure things.
Re: EEVblog #961 - Monkey Debouncing
« Reply #17 on: December 30, 2016, 03:26:29 AM »
Use an Arduino!

It's two minutes' work to write a sketch that waits a minimum time between claps.

It can output pulses to your counter for display.
You keep the switch pressed and have a 50Hz signal generator. Great solution there, buddy.
Kudos on the blocking code.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 
The following users thanked this post: SL4P

Online rrinker

  • Super Contributor
  • ***
  • Posts: 1302
  • Country: us
Re: EEVblog #961 - Monkey Debouncing
« Reply #18 on: December 30, 2016, 03:51:48 AM »
 Yet after ALL that work, I see the monkey STILL bounces after he claps....  :-DD
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 1006
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: EEVblog #961 - Monkey Debouncing
« Reply #19 on: December 30, 2016, 03:57:36 AM »
Worth mentioning is also that constantly shorting a capacitor will over time seriously corrode the contact surfaces, so the circuit will appear to work in the beginning but may stop counting after a while.

Good point there. I always yell pissed, where someone puts a pair of 100n caps directly accross a mechanical rotary encoder, as a means of debouncing the contacts.  >:D  ;D
 

Online Fungus

  • Super Contributor
  • ***
  • Posts: 5197
Re: EEVblog #961 - Monkey Debouncing
« Reply #20 on: December 30, 2016, 04:03:03 AM »
It's two minutes' work to write a sketch that waits a minimum time between claps.
You keep the switch pressed and have a 50Hz signal generator. Great solution there, buddy.
Kudos on the blocking code.
It's only for the monkey so who cares about the blocking, etc.

Off topic: Shameless plug for some non-blocking, fully debounced Arduino code I'm working on:

https://www.facebook.com/official.arduino/videos/1604466669579646/

 :)
« Last Edit: December 30, 2016, 04:24:33 AM by Fungus »
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 1006
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: EEVblog #961 - Monkey Debouncing
« Reply #21 on: December 30, 2016, 04:04:17 AM »
[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.
[/quote]

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

Offline PeterL

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
Re: EEVblog #961 - Monkey Debouncing
« Reply #22 on: December 30, 2016, 04:20:01 AM »
[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.
[/quote]

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

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 1491
  • Country: de
    • Frank Buss
Re: EEVblog #961 - Monkey Debouncing
« Reply #23 on: December 30, 2016, 04:25:50 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.
quadro copter flying, electronics, retro computing and other geeky things: https://www.youtube.com/user/frankbuss/
 

Online Kalvin

  • Super Contributor
  • ***
  • Posts: 1249
  • Country: fi
Re: EEVblog #961 - Monkey Debouncing
« Reply #24 on: December 30, 2016, 06:04:02 AM »
Arduino pseudo-code:

#define SAMPLE_TIME_ms 1
#define THRESHOLD 100
state = input_pin_state
count = THRESHOLD / 2
loop forever:
  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
    endif
  endif
  output_pin_state = state
  delay SAMPLE_TIME_ms
endloop
« Last Edit: December 30, 2016, 06:36:40 AM by Kalvin »
 
The following users thanked this post: jonovid


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf