Mel
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 ==========
Hold:
OUT15 = 1
IF IN10 = 1 THEN Holdˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ 'Wait for input 10 (TEN) to go low
DEBUG CLS
ˇ
Main:
COUNT 0,50,Cycles
DEBUG HOME, 10, "Cycles Per Second: ", DEC (Cycles * 20),CR
L2Count = L2Count + Cycles
IF L2Count >= 725 THEN Done
GOTO Main
ˇ
Done:
DEBUG CLS
DEBUG "Were Done ",CR
DEBUG "Cycles Per Second: ", DEC (Cycles * 20),CR
DEBUG ? L2Count, CR
OUT15 = 0
PAUSE 1000
L2Count = 0
GOTO Hold
ˇ
ˇ
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 ==========
Hold:
OUT15 = 1
IF IN10 = 1 THEN Holdˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ 'Wait for input 10 (TEN) to go low
DEBUG CLS
ˇ
Main:
COUNT 0,50,Cycles
DEBUG HOME, 10, "Cycles Per Second: ", DEC (Cycles * 20),CR
L2Count = L2Count + Cycles
IF L2Count >= 725 THEN Done
GOTO Main
ˇ
Done:
DEBUG CLS
DEBUG "Were Done ",CR
DEBUG "Cycles Per Second: ", DEC (Cycles * 20),CR
DEBUG ? L2Count, CR
OUT15 = 0
PAUSE 1000
L2Count = 0
GOTO Hold
ˇ