Shop OBEX P1 Docs P2 Docs Learn Events
Timimg question, COUNT, BS2: How many pulses likely to drop? — Parallax Forums

Timimg question, COUNT, BS2: How many pulses likely to drop?

xanatosxanatos Posts: 1,120
edited 2011-09-29 17:36 in BASIC Stamp
Hi!

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

  • davejamesdavejames Posts: 4,047
    edited 2011-09-28 10:07
    Hi Dave,

    Tracy Allen's site has some useful info on reckoning BS2 instruction speed:

    http://www.emesystems.com/BS2speed.htm

    Dave
  • stamptrolstamptrol Posts: 1,731
    edited 2011-09-28 10:19
    Your concern is a common one for anyone doing high-speed counting.

    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,
  • xanatosxanatos Posts: 1,120
    edited 2011-09-28 10:29
    Thanks, that was interesting. If I am calculating right, the above calculations would take about 670 uS per loop, so even if I round up to 1000 uS, I would only be dropping 1 pulse per cycle if the timing coincided (at a 1kHz pulse rate). This would probably all be able to fit betweem pulses if my pulse rate was as low as 100Hz.

    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
  • ercoerco Posts: 20,256
    edited 2011-09-29 17:36
    Obviously the BS2SX and BS2P24 and BS2PX are alternatives offering faster counting response: http://www.parallax.com/tabid/436/Default.aspx

    (Act now, while all 24 pin Stamps are on sale for $50.)
Sign In or Register to comment.