View Full Version : High Speed Counting

06-15-2005, 12:50 PM
I have a project where I am trying to count pulses coming from a turbine flow meter. I tried some of the StampWorks experiments such as #16 Counter.bs2 it did not appear to be able to count fast enough. I tried the following code (See Below) and it appeared to work OK on the workbench with a function generator supplying the pulses but is less reliable in real life with the pulses coming from the flow meter (flow meter is more erratic as valve opens and closes)
Basically I want to wait until input 10 goes low (signaling the sol valve opened).ˇ Start counting pulses on input 0 and when the count gets to 725ˇˇ Make output 15 low (signals correct volume has been measured), reset the count and wait to do it all again.
According to the meter documentation at Maximum flow rate the pulse freq would be 828 Hz - under normal circumstances I should be well below this.ˇ
What is the best way to accumulate a count at these speeds and what is the max freq I can expect to be able to count?
My thoughts on this code (Extracted from #17 FreqIn1.BS2) were to look at the COUNT every 1/20 of a second find the count for this period and add it to a running total
‘======= CODE SNIPIT ==========
OUT15 = 1
IF IN10 = 1 THEN Holdˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ 'Wait for input 10 (TEN) to go low
COUNT 0,50,Cycles
DEBUG HOME, 10, "Cycles Per Second: ", DEC (Cycles * 20),CR
L2Count = L2Count + Cycles
IF L2Count >= 725 THEN Done
DEBUG "Were Done ",CR
DEBUG "Cycles Per Second: ", DEC (Cycles * 20),CR
DEBUG ? L2Count, CR
OUT15 = 0
PAUSE 1000
L2Count = 0

06-15-2005, 06:36 PM
You may need a schmitt trigger gate to clean up the pulses coming from the flow meter.
Also you are going to miss pulses because the DEBUG line sends serial data to the PC, and the program must wait for the data to be sent.

"SX-VideoˇModule" Now available from Parallax for only $28.95


Product web site: www.sxvm.com (http://www.sxvm.com)

"If you keep doing what you always did, you'll keep getting what you always got."

06-16-2005, 02:20 AM

The flow meter is equipped with a board that amplifies and conditions the low-amplitude signal from the magnetic pickup coil on the meter.ˇ From there I have it going into a OPTO22 type module (IDC5 Gordos) that converts the DC pulse of 12 volts to a 5 volt logic.ˇ From the specs for the OPTO22 it states Maximum Turn-On Time .2 mSec and Maximum Turn-Off Time .4 mSec .ˇ That would be around 1600 Hz or almost twice as fast as the meter pulses.ˇ The pulses from the meter on an Oscilloscope look like a nice square wave with a constant amplitude and only the freq varying with the flow.

Your make a good point about the DEBUG statements.ˇ I had not thought of the time (and counts) lost while communicating with my Laptop.ˇ The DEBUG statements are not needed in the final version and I was only using them for troubleshooting.ˇˇ I am going to remove them and do some more testing.ˇ The problem is that I am measuring the flow of Liquid Nitrogen at 100 psiˇ so I can’t just fill up a bucket and measure what came out.ˇ It comes out very fast (almost violent) and then changes to a gas also very rapidly.
Do you have any other ideas about the program?ˇ What would be the recommended way to accumulate a fast changing count?ˇ What is the fastest rate I could expect to be able to count reliably with a BS2 Stamp?
Thanks in advance

Post Edited (Mel) : 6/15/2005 7:35:03 PM GMT