More counts than should be
Posted 07 July 2012 - 05:07 PM
I have 5 flow sensors that provide a pulsed signal via a reed type switch. Each sensor feeds a hardware debounce circuit then to a multiplexer which feeds one U3 counter input. I'm using CIO0 - 2 as the address lines and CIO3 as the enable line to the multiplexer.
When I use the LJ control panel and force the CIO lines, scoping the counter input shows a clean square wave with a duty cycle of about 84%. Frequencies range from 7 Hz to 18 Hz. Given the circuits the flow sensors are in, this is what I would expect.
My script is just to cycle through each flow sensor and check for proper flow count. Don't need anything fast here and basically is:
Set CIO0 - 2 for address
Set multiplexer output enable ON
Set multiplexer output enable OFF
Get counter value and show in a V channel
Repeat for next sensor
The script works fine but I am getting too many counts for a 1 second delay, about 4 times as many.
Am I doing this right or is there a more proper way to perform this?
Posted 08 July 2012 - 09:24 PM
Posted 09 July 2012 - 10:33 AM
1) Rearrange your code to look like this:
2) Use a timer in counter debounce mode instead of a counter: http://labjack.com/s...s-guide/220.127.116.11
Posted 09 July 2012 - 03:30 PM
// resevoir flow sensor
eput (ID1, LJ_ioPUT_COUNTER_RESET, 1, 0, 0, 0) // reset counter 1
ePut (ID1, LJ_ioPUT_DIGITAL_PORT, 16, 0, 3, 0) // set S0, S1, S2 to to 0, 0, 0
ePut (ID1, LJ_ioPUT_COUNTER_ENABLE, 1, 1, 0, 0) // enable counter 1
ePut (ID1, LJ_ioPUT_DIGITAL_BIT, 19, 0, 0, 0) // set enable line low
Delay(1) //accummalate counts
ePut (ID1, LJ_ioPUT_DIGITAL_BIT, 19, 1, 0, 0) // set enable line high
eGet (ID1, LJ_ioGET_COUNTER, 1, @Count_0, 0) //get counter value
ePut (ID1, LJ_ioPUT_COUNTER_ENABLE, 1, 0, 0, 0) //disable counter
private flow_0 = ((Count_0 / 3) * 0.307) //calc LPM (3/8" hose factor)
v.RES_Flow.AddValue(flow_0) //update virtual channel
No matter what the Delay is I get the 4 times the real count should be. Funny thing is if I would set the Delay to about 20 seconds or so and measure the frequency with my Fluke meter I would get the same Hz reading (about 4 times as high).
I'll try the above script suggestion and if that doesn't work I'll switch to timers. I have extra ones now that I can take one timer PWM out, push it through a line driver which can drive several PWM controlled analog voltage sources.
Thanks for the help.