Debounce for the 'count' command

Tyro

Member
I have a NO relay contact with a pull up resistor. I need to count how many times it closes within a certain period. Using the count command I get the wrong answer because of switch bounce.

To get rid of switch bounce in software normally requires a short pause. What do I use for the count command? I do not want to use an RC filter if I can possibly get away with it.
 

SAborn

Senior Member
Why use a mechanical relay? what voltages are involved controlling the relay.

Can you use a solid state device like a transistor or optocoupler, or even a solid state relay, to replace the NO relay, this way you will have no switch bounce to deal with.
 

Tyro

Member
The input is a slowly rotating magnet with a reed switch close to it. I cannot use a hall switch because the reed and magnet are all an existing assembly.
 

westaust55

Moderator
Typically contact bounce is less than 5 ms.
There is no way you can modify the PULSIN command.

I believe you may be restricted to external components.

Try adding a say 10 kOhm resistor and small value ( 100nF) capacitor in parallel across the PICAXE input.
The capacitor will briefly hold the signal line high during which time the contact bounce should cease from each contact operation.
The resistor (try different values if need be) will dissipate the energy faster and thus voltage from the capacitor when the contact is open.
 

Buzby

Senior Member
If you can get access to the NC contact of the relay, as well as the NO, you can connect them to two inputs on the PICAXE.
Then you can write simple 'toggling' code, or use the SR latch, to do the counting.
 

SAborn

Senior Member
I agree with Westaust55, and recommend you try his suggestion, as i have used almost identical to what Westy said for anemometers that use a reed switch and magnet.
Most times when a reed switch becomes noisey, is after a lot of use and close to failing anyway, so if able i would replace the reed switch for starters.

On average a reed switch dont normally give a lot of switch bounce or noise, so i would look a little deeper to the cause.
Perhaps the way the magnet is mounted could be effecting the operation too.
 

Tyro

Member
Thank you all. It is a bouncing contact. I have captured it on a digital scope. Using a 22k pullup and a 100n cap to 0v and a 1k in series to limit peak currents works fine.
 
Top