Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

debounce for waitDigTrig() on CR800?


kirving Apr 9, 2012 10:46 PM

We have a device using a CR800 logger and the waitDigTrig() function to trigger actions via a mechanical push-button switch. The code is similar to:

scan(1,sec,0,0)
waitDigTrig(4,0)
call doStuff
nextscan

I've noticed that the action is also sometimes triggered by static discharge, and was wondering if a 'debounce' option might be possible algorithmically. The second parameter to waitDigTrig() is for an Option argument, but it does not seem to support debounce directly. We could perhaps add a brief delay after the trigger and then check the port again.

I notice that section 4.6.3 in a CR1000.pdf manual recommends a pull-up resistor for connecting switch closures for digital I/O, so maybe that's what we should be doing. That might be a better solution than trying to debounce in the program. Any thoughts on this?


aps Apr 10, 2012 10:44 AM

For this to work, I would guess your switch is connected between the control port and 5V, otherwise it would never generate a pulse on closure?

Control ports do have a 100k pull down resistor to hold the port low but if you have long, unshielded cables then big enough transients could trigger the Waitdigtrig input.

There are several ways to solve this.

a) add a lower value resistor across the control port input, e.g. 10k, to pull down the input "harder". This will not solve the problem of switch bounce through.

b) add a small capacitor across the input of the control port, which in combination with the logger's pull down resistor will act both as a simple debounce and noise filter. A 1 microfarad capacitor should do the trick.

c)use a software trick as you say, but you need to be careful as you are not really looking at debounce alone but also noise filtering, so you would need to check the port was held high for a reasonable time (to avoid the spikes) and if not jump around the call to dostuff.


kirving Apr 11, 2012 02:38 AM

Thanks. That is correct, the switch connects +5V to the control port. The spurious triggers may only be a problem in the lab, but if they persist we'll try the capacitor.

Log in or register to post/reply in the forum.