Shop OBEX P1 Docs P2 Docs Learn Events
Counting without time limit and comparing to variable — Parallax Forums

Counting without time limit and comparing to variable

ManuelManuel Posts: 105
edited 2005-07-31 05:07 in General Discussion
Hello
I want to count a hall effect sensor with my BS2sx but not within a time limit. I want to be counting all the time until i reach the value of·a variable(word size). I was thinking of the lookdown command and adding 1 to·another variable each time·the sensor reads a magnetic fiels,·until my lookdown command sees tey are the same.
Does anyone have a suggestion, correction, tip?
Everything you write is warmly welcome.
Thanks for all the help i may recieve.
Best Regards
Manuel C. Reinhard

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-31 02:20
    Hello,
    ·· You might try something like:
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
     
    Target   CON   1234
    Current  VAR   Word
     
    DO
       IF IN0 = 1 THEN Current = Current + 1
       DO : LOOP WHILE IN0 = 1
    LOOP WHILE Current < Target
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ManuelManuel Posts: 105
    edited 2005-07-31 02:24
    Does the while command exist for the BS2sx?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-31 02:25
    Manuel,

    ·· Whoops!· Yes, it does...I had a BS2p in the board already when I tested the code, but as long as you have the PBASIC 2.5 syntax selected, you're fine.· You just need to change the Stamp directive to BS2sx.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ManuelManuel Posts: 105
    edited 2005-07-31 02:26
    Thanks very much for your help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • ManuelManuel Posts: 105
    edited 2005-07-31 02:37
    do you think that i can use your code to count fast enough a hall sensor, sensing once every .02 seconds?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-31 02:41
    Manuel,

    ·· On the SX, it's possible, although I haven't checked the timing.· You could try it though.· Timing for the BS2, and I think the BS2sx can be found on Dr. Tacy Allen's website at www.emesystems.com·along with a wealth of other useful information!· =)· Check it out!




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ManuelManuel Posts: 105
    edited 2005-07-31 02:42
    Thanks, i will check there. when the loop ends, it will automatically go to the next line in my program?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-31 05:07
    Manuel,

    ·· That is correct.· The DO...LOOP exits when the Target variable has been reached.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.