Shop OBEX P1 Docs P2 Docs Learn Events
How can an accurate time of a BS2 program be determined? — Parallax Forums

How can an accurate time of a BS2 program be determined?

po2lepo2le Posts: 76
edited 2008-06-20 00:02 in BASIC Stamp
I'm using this program to count pulses.· How can I determine elapsed time during the 'DO LOOP' ?
It seems to be longer than the 1000 msecs during the count command.

' pulsecount.bs2
' count pulses
' {$STAMP BS2}
' {$PBASIC 2.5}
reps··· VAR···· Word
time VAR Word
plscount· VAR Word


reps· = 0
DO WHILE (reps <= 20)
· COUNT 0, 1000, plscount················· 'equals number of pulse/1000ms
·· DEBUG DEC plscount, CR
·· reps = reps + 1
LOOP

END

My circuitry: Basic Stamp homework board with Embedded Basic stamp 2, powered by 9v battery. It has a serial port connector, a header for connecting i/o pins to embedded breadboard, with volt regulator and some EEPROM. I'm taking pulses from a motorcycle electronic ignition at the primary side of the ignition coil (the same point that the tach. circuit is fed from). Then counting the pulses using the above BS2 program.

Thanks,
PO'T

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-20 00:02
    Each of the statements takes some time with the DEBUG statement taking the longest after the COUNT statement.· EME Systems (http://www.emesystems.com) has some information on PBasic·timings (look at the bottom of the page for "app-notes"), but the only way to do this is to repeat the section of code many times and use a stopwatch to time the section of code (using a DEBUG message at the start and end of the test), then divide by the number of repetitions.· The Stamp itself has no built-in timer that can be used.· You can use an external real time clock like the DS1302, but these only keep time to the nearest second.
Sign In or Register to comment.