Software debounce for WC8 counter?

mminehan

Member
I am having some issues with a water meter connected to a WC8 (firmware v03.03.31).
 
The water meter uses a simple contact closure pulse relay.  I have connected it to TTL Input 1 on the WC8 and enabled TTL1 as counter.
 
This seems to be working except for what I think is some switch bouncing, frequently causing the count to jump by 3 or 4 counts per pulse.  This is more pronounced with low water flows when I think the relays closes less quickly.  At full flow the meter pulses about once a second or slightly less, and still bounces a little bit.
 
I have looked at various options such as a RC circuit (+/- a logic chip like the 74HC14) but this would require pulling apart the housing which is mounted in a wall box inside a pool pump house. Quite a bit of time involved.  And I am uncertain what would be appropriate values for the two resistors and the cap anyway.
 
Other things I have read suggest using a 'software' debouncing option.  But I am not very familiar with PLC.  And reading through these forums I can't see that anyone has done this with the TTL1 COUNTER option in the WC8 PLC software.
 
Any advice would be appreciated.
 
Marty
 
Do you have a friend who has an oscilloscope?  This would show if it is an actual relay bounce problem.     You might have to use a debounce circuit as you described if it is indeed relay bounce, though I would look at the water meter specs and perhaps call the manufacturer as you would think they would have included that feature with the meter since its intent is to be connected to a digital counter of some sort.    
 
Basically, you need to 'stretch' the pulse width of the closure so all the small 'bounce' contact closures are not counted. 
 
https://www.allaboutcircuits.com/textbook/digital/chpt-4/contact-bounce/
 
 
You would need to know the maximum number of pulses per second (resolution of the meter), then 'stretch' the pulse with an RC value to ensure it isn't so wide where counts are missed during the maximum pulses per second.  
 
You could also try to correct this with software, basically delaying the capability to count any more pulses after the first one is received.  The amount of that delay would again depend on the maximum pulses per second (I would give a safety factor of 50%) to ensure the delay isn't so long as you could potentially miss a pulse.  I'm just not sure how fast the Webcontrol unit reacts and again, what your maximum pulse rate is.   
 
Do you have a link or datasheet to the meter you are using? Also, what is your absolute maximum flow rate you would measure?
 
There are a lot of sites out there that have solutions for both hardware and software debounce solutions.
 
IIRC the WC8 counter input can count to 2 MHz and there is no software you can do for it. It only presents the count in a register to the CPU software. There is no interception point in the data flow to software "shape it".
 
You could request a mod from the designer here but I think it is all hardware. I use the same for my anemometer and no debounce was needed for a few years before it started counting double. I had to install an RC network to make it read properly again.
 
I think a RC filter could filter out bounces, if you know roughly what your water meter's frequency range. Using large enough capacitor, so that shorter pulses would not raise the voltage to trigger level. WC8 counter must count every pulse reaching to trigger level, otherwise, it would not be accurate counter.
 
Thanks Larry, Robbin and CAI for taking the time to respond.

Based on your replies it seems that a software debounce option is not viable. So I will have to experiment with a hardware solution (RC).

I'll have to do some time constant maths to work out what size capacitor to use. From memory the meter sends a pulse every 100ml of volume via a reed switch attached to the front of the sealed meter. I can't imagine that this wouldn't be any faster that 2 or 3 pulses a second at maximum flow.

I'll provide an update once I have a satisfactory solution.

Thanks again, Marty.
 
mminehan said:
Thanks Larry, Robbin and CAI for taking the time to respond.

Based on your replies it seems that a software debounce option is not viable. So I will have to experiment with a hardware solution (RC).

I'll have to do some time constant maths to work out what size capacitor to use. From memory the meter sends a pulse every 100ml of volume via a reed switch attached to the front of the sealed meter. I can't imagine that this wouldn't be any faster that 2 or 3 pulses a second at maximum flow.

I'll provide an update once I have a satisfactory solution.

Thanks again, Marty.
Capacitors are typically about +100%/-50% of their rated value, anyway (in the old days) . I just stuck a scope on the line and inserted progressive values from my junk box until it worked. One pulse per second and a fast contact debounce should be easy to arbitrate.
 
So I don't have access to a scope but did try a multimeter.  It seems the pulse is very wide with the contact closed maybe a 3rd of time during a cycle.  So it takes roughly 2 seconds for a 1 litre count with the relay closed for almost a second.
 
With the relay closed I measure around 4.9v at TTL1 input (measured across TTL1 and GND) and then back to near 0 with it open.
 
I am struggling to find a suitable RC circuit so suit this setting. I tried this Embed With Elliot: Debounce Your Noisy Buttons, Part I | Hackaday circuit (the first design without the IC) but still get a lots of extra counts.
 
Can anyone point me in the right direction in terms of circuit design, R and C values?
 
Me electronic skills are average.  I can assemble basic circuits etc.
 
I have one of Rossw's V2 webamp boards connected to my WC8 that I use for analogue filtering for a pH and ORP probe which works well.  So I have screw terminal access to VCC, TTL1 and GND.
 
Thanks, Marty
 
Thanks, Marty.
 
It's hard to give advice without knowing the exact conditions of your system.  For instance, I don't know anything about the WebControl device and the logic it needs for digital inputs (i.e. does it use a pull up resistor?  Polarity it's expecting to count between an 0 and 1?, etc...).
 
If this was me, I would create a de-bounce/one-shot circuit using a 555 chip and set it up to have a pulse width of 100 milliseconds as given your description of the maximum pulses per second this gives a safety factor of two (using four pulses per second as the maximum meter count rate) of not stretching the pulse to much so you miss counts at your maximum expected flow rate.
 
I found a circuit that describes this methodology HERE.  Take a look at figure seven.  The two 10 microfarad capacitors will give a pulse width of 220 milliseconds which is of course to long, but I would create this circuit exactly as shown (even the LED), then connect it to your meter and see if the LED blinks and it's rate increases with flow.  A 220 millisecond pulse should be discernable with the eye.
 
If this circuit works, modify it slightly by taking out one of the 10 microfarad capacitors and LED as shown in the attachment below, and connect it to your WebControl.  
 
Modified Circuit.jpg
 
The contact closures of the relay from the flowmeter are shown in the lower left.
 
The only caution is I don't know the input voltage limits of the WebControl as to what maximum voltage pulse it can accept in one of its inputs.
 
Also, you would have to power the 555 chip (notice power reference on the right) so hopefully whatever you are using for the WebControl power would be compatible with the power inputs of the 555.
 
I would not mind if others critique this design as well and give their advice or corrections if needed on this methodology.
 
BraveSirRobbin said:
It's hard to give advice without knowing the exact conditions of your system.  For instance, I don't know anything about the WebControl device and the logic it needs for digital inputs (i.e. does it use a pull up resistor?  Polarity it's expecting to count between an 0 and 1?, etc...).
 
If this was me, I would create a de-bounce/one-shot circuit using a 555 chip and set it up to have a pulse width of 100 milliseconds as given your description of the maximum pulses per second this gives a safety factor of two (using four pulses per second as the maximum meter count rate) of not stretching the pulse to much so you miss counts at your maximum expected flow rate.
 
I found a circuit that describes this methodology HERE.  Take a look at figure seven.  The two 10 microfarad capacitors will give a pulse width of 220 milliseconds which is of course to long, but I would create this circuit exactly as shown (even the LED), then connect it to your meter and see if the LED blinks and it's rate increases with flow.  A 220 millisecond pulse should be discernable with the eye.
 
If this circuit works, modify it slightly by taking out one of the 10 microfarad capacitors and LED as shown in the attachment below, and connect it to your WebControl.  
 
attachicon.gif
Modified Circuit.jpg
 
The contact closures of the relay from the flowmeter are shown in the lower left.
 
The only caution is I don't know the input voltage limits of the WebControl as to what maximum voltage pulse it can accept in one of its inputs.
 
Also, you would have to power the 555 chip (notice power reference on the right) so hopefully whatever you are using for the WebControl power would be compatible with the power inputs of the 555.
 
I would not mind if others critique this design as well and give their advice or corrections if needed on this methodology.
IIRC the WC8 has a weak pullup resistor on input but there is no reason why one cannot actively drive any input with a pullup as long as Vcc isn't exceeded.
 
The RC network works for some cases but can be very poor for some cases as the bounce time can exceed the maximums of the input frequency. A 555 monostable / Schmidt trigger is sometimes needed to fix things properly.
 
You could find USB based logic analyzer to help see actual pulse width, search "USB 24M 8CH Logic Analyzer " on eBay will find a lot of around $10. I am not sure what kind software do they use.  Or find "DSO112A" mini digital scope for about $60. They will let you see a lot clear what is the actual problem.
 
@CAI_Support:  Given you know the specs of the WebControl inputs, what pulse would it take to go from a digital zero to a one?  Can one connect a logic chip directly to the input (and also connect it's ground to the WebControl ground), then have a pulse go from zero volts to ??? volts and have that pulse register as a '1'?   
 
Reason I ask is I am unfamiliar with this devices input requirements.  Is an external pullup needed?  
 
Also, I believe your recommendation of the logic analyzer is a good one, though it will not show the waveform's true shape, as it can just register low and high signals (past a known threshold) and show them as square waves.  
 
@LarryILix:  My solution does use a 555 chip in a monostable mode.  I really don't think a Schmitt trigger is needed after that as the rise time and waveform pulse should be sufficient for the WebControl counter mode (IMO).  A scope will go a long way though. 
 
Also, one might be able to use a 2N3904 switching transistor on the output as well in lieu of a one shot.  This would also be needed if the logic needs to be opposite of what I'm thinking is needed for the WebControl's digital input.  
 
If I have time, I could mock this circuit up as I do have an oscilloscope, breadboard and (I think) a 555 chip and other related components in my electronics box/closet.  Can't get to this until Monday at the earliest though.
 
WC TTL inputs are pull-down to logic zero. It could count fast pulses up to 4MHz with 50% modulation ratio. TTL logic 1 level is determined by TTL input buffer IC, 74LV4245 running at 5V, according to its spec will be at 2V level at the chip input pin.TTL zero is 0.8V.
 
BraveSirRobbin said:
@CAI_Support:  Given you know the specs of the WebControl inputs, what pulse would it take to go from a digital zero to a one?  Can one connect a logic chip directly to the input (and also connect it's ground to the WebControl ground), then have a pulse go from zero volts to ??? volts and have that pulse register as a '1'?   
 
Reason I ask is I am unfamiliar with this devices input requirements.  Is an external pullup needed?  
 
Also, I believe your recommendation of the logic analyzer is a good one, though it will not show the waveform's true shape, as it can just register low and high signals (past a known threshold) and show them as square waves.  
 
@LarryILix:  My solution does use a 555 chip in a monostable mode.  I really don't think a Schmitt trigger is needed after that as the rise time and waveform pulse should be sufficient for the WebControl counter mode (IMO).  A scope will go a long way though. 
 
Also, one might be able to use a 2N3904 switching transistor on the output as well in lieu of a one shot.  This would also be needed if the logic needs to be opposite of what I'm thinking is needed for the WebControl's digital input.  
 
If I have time, I could mock this circuit up as I do have an oscilloscope, breadboard and (I think) a 555 chip and other related components in my electronics box/closet.  Can't get to this until Monday at the earliest though.
Yes. I was commenting on your suggested circuit and agreeing with the method. The 555 is two analogue comparitors, and a Schmitt trigger. Probably perfect for the job.
Everything looked good to me except now CAI support says the input is pulldown. I haven't seen a 555 chip for 40+ years now. LOL
 
 
Thank you Larry, Robbin and CAI for your responses.
 
I have made up the circuit that Robbin posted a link to.  I have used breadboard like the link shows.  To test it I used a bench power supply set at 5V.  The LED lights up and stays lit while the switch is held closed.  And I managed to borrow a handheld scope, which I am still learning how to use.  The output to the LED is a nice square wave with no noise.  So far so good.  But the voltage on pin 3 of the 555 is only 3.2v when high, and 0.2v when low.  So I am wondering if I should remove the LED and lower the value of R3 (currently 220ohm).
 
It's been raining here and I don't fancy hanging out in the rain working in the pump shed so have not scoped the actual pulse meter yet.
 
Next I'll hook up the water pulse meter and the WC8 to the breadboard prototype and see how it performs, when the rain stops.  If it works then I'll use a PCB to make up the permanent circuit.
 
I'm pleased with the progress so far.  Thanks for helping me.
 
Marty.
 

Attachments

  • WC8 debounce.jpg
    WC8 debounce.jpg
    139.4 KB · Views: 9
Back
Top