Timimg question, COUNT, BS2: How many pulses likely to drop?
xanatos
Posts: 1,120
Hi!
I am using the following code to count pulses coming from a flowmeter that is dispensing liquid:
Since the flowmeter provides a few hundred pulses per gallon, and it dispenses a lot of gallons, the count can get very high. So I am counting for 1 sec (1000ms), reading the count, figuring gallons, figuring the remainder, then getting the new count, adding the remainder from the last count, and repeating the cycle.
Two questions: Isn't there a better way to do this?! :-) And 2: If not, how can I reliably estimate how long of a delay my code puts into the mix, ie, so I can figure out how many pulses I might be missing during my calculations.
I am designing and building for a 1khz pulse rate, but the actual pulse rate will not likely exceed 100 pps.
The above code IS working... but I know it's gotta be dropping pulses every time I cycle through.
Thanks for your thoughts, ideas, ridicule, etc! :-)
Dave
I am using the following code to count pulses coming from a flowmeter that is dispensing liquid:
DO COUNT flowCount, 1000, rawCount rawCount = rawCount + remains galsPumped = rawCount / ppg remains = rawCount - (galsPumped * ppg) galTotal = galTotal + galsPumped LOOP
Since the flowmeter provides a few hundred pulses per gallon, and it dispenses a lot of gallons, the count can get very high. So I am counting for 1 sec (1000ms), reading the count, figuring gallons, figuring the remainder, then getting the new count, adding the remainder from the last count, and repeating the cycle.
Two questions: Isn't there a better way to do this?! :-) And 2: If not, how can I reliably estimate how long of a delay my code puts into the mix, ie, so I can figure out how many pulses I might be missing during my calculations.
I am designing and building for a 1khz pulse rate, but the actual pulse rate will not likely exceed 100 pps.
The above code IS working... but I know it's gotta be dropping pulses every time I cycle through.
Thanks for your thoughts, ideas, ridicule, etc! :-)
Dave
Comments
Tracy Allen's site has some useful info on reckoning BS2 instruction speed:
http://www.emesystems.com/BS2speed.htm
Dave
A usual work around is to use an external counter which can keep counting as the processor takes time off to do other things.
When the processor is once again free, it reads in the value from the counter, resets it and goes away to do calculations or control.
Cheers,
Still wondering if this is the best way to do it all... the lack of floating point and a max count of 65,535 make this a tricky set of operations to run properly. Normally I'd just count pulses until the pumping was done, divide by the ppg (pulses per gallon) and be done with it...
Thanks for the info. I feel at least like the code isn't dropping large wads of pulses, which is helpful! :-)
Dave
(Act now, while all 24 pin Stamps are on sale for $50.)