Shop OBEX P1 Docs P2 Docs Learn Events
Count Execution Question? Solved... — Parallax Forums

Count Execution Question? Solved...

smplsmpl Posts: 19
edited 2011-11-20 16:37 in BASIC Stamp
Hello all. I am a newbe, new to microcontrollers and this is my first post.

Question: Doesn't the Count command need to finish the count duration before executing the next command?
The debug screen updates every 1/4 of a second using this code.

Test Code:
' {$STAMP BS2p}
' {$PBASIC 2.5}
' {$PORT COM29}
PAUSE 100
SENS CON 0
RPM VAR Word
FREQ VAR Word
SECS VAR Word
DEBUG CLS,"Pulses = ",CR,"RPM = ",CR,"Seconds = "
DO
COUNT SENS, 1000, FREQ
RPM = (FREQ*60)
SECS = (SECS + 1)
DEBUG CRSRXY,9,0, DEC FREQ,CLREOL
DEBUG CRSRXY,6,1,DEC RPM,CLREOL
DEBUG CRSRXY,10,2, DEC SECS,CLREOL
LOOP

Thanks

Comments

  • smplsmpl Posts: 19
    edited 2011-11-20 03:09
    Well this has been driving me nuts for 2 days. And of course I found out what I was doing wrong minutes after posting this thread. There appears to be an offset required in the duration depending on the Basic Stamp used. The modified code below shows the offsets.

    Modified Code:

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    ' {$PORT COM29}
    PAUSE 100
    SENS CON 0
    RPM VAR Word
    FREQ VAR Word
    SECS VAR Word
    #SELECT $STAMP
    #CASE BS2, BS2E
    Offset CON $100 ' / 1
    #CASE BS2SX
    Offset CON $280 ' / 0.400
    #CASE BS2P, BS2PX
    Offset CON $37B ' / 0.287
    #CASE BS2PE
    Offset CON $163 ' / 0.720
    #ENDSELECT
    DEBUG CLS,"Pulses = ",CR,"RPM = ",CR,"Seconds = "
    DO
    COUNT SENS, (1000 */ Offset), FREQ
    RPM = (FREQ*60)
    SECS = (SECS + 1)
    DEBUG CRSRXY,9,0, DEC FREQ,CLREOL
    DEBUG CRSRXY,6,1,DEC RPM,CLREOL
    DEBUG CRSRXY,10,2, DEC SECS,CLREOL
    LOOP
  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-20 05:44
    Yes, the various Stamp models have different timing units that are described in the Stamp Editor help files and the Basic Stamp Syntax and Reference Manual under the description of each of the statements that do timing. In the case of the COUNT statement, you can adjust for the differences either by changing the amount of time that the COUNT statement counts pulses as you've done or by counting for a fixed period, then adjusting the resulting count for the time unit involved.
  • smplsmpl Posts: 19
    edited 2011-11-20 16:37
    Well with a osciliscope I measered the time between pulses and calculated ((1/.028)*60)=2143 RPM with 1 pulse per revolution which is what I am now seeing with the Basic Stamp (BS2p40).

    TIP: When your trouble shooting, sometimes you have to walk away from the problem for a while and then when you return to it, the solution stares you straight in the face. I live by this, but in this situation I let it consume me for 2 days. NEED MORE BEER......LOL
Sign In or Register to comment.