Shop OBEX P1 Docs P2 Docs Learn Events
Timer help — Parallax Forums

Timer help

ChemkidChemkid Posts: 2
edited 2008-04-09 01:50 in Learn with BlocklyProp
Hi, first time user here and I am faced with a little problem.

I am quite new to using a STAMP(BS2SX) so I have not been able to figure this out on my own, and I was hoping one of you could help. I need to be able to identify the amount of time that has passed between two high signals that have been sent to two different input pins( obviously time has elapsed between each high signal) . I have looked through the manual and have not found a simple command which does this, and cant quite wrap my head around a code that can do this.

Any help would be appreciated.
Thanks in advance!
Chemkid

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-08 22:51
    There isn't a simple command to do this. If the time is on the order of milliseconds, you can test for the first high signal, then set a counter to zero and check for the second high signal. If not present, you increment the counter and do a "PAUSE 1". When the second signal becomes high, the counter has the approximate number of milliseconds that has passed.
  • jmalaysiajmalaysia Posts: 97
    edited 2008-04-09 01:08
    If inputpin1=1 then
    do until inputpin2=1
    timer=timer+1
    PAUSE 1
    loop
    endif

    As Mike suggested, putting a PAUSE in the loop will increase your elapsed time capability, but it won't actually produce an accurate millisecond count that you could convert directly to elapsed time because the loop execution time isn't accounted for. The more you put in the loop, the longer it will take to execute. If timer is a word variable, the max count number is 65,535 before you run into problems. Inserting a PAUSE 1, 2, or longer into the loop can reduce your count if needed. The PAUSE is not required if you are measuring very short time intervals. Once you get everything in the loop, run it for a fixed period of time and see what the count is. Use an equation to convert the timer value to actual elapsed time if required.
  • ChemkidChemkid Posts: 2
    edited 2008-04-09 01:50
    Thanks a million guys for the quick response. I tried it out and it worked like a charm!

    chemkid
Sign In or Register to comment.