Discussion forum for the BasicX family of microcontroller chips.
|
Hey All I have a vehicle which, at certain time periods after start, needs to perform a function. But all the while, (while not doing the timed function) it needs to check pins to see if obstacles are in the way or not. ie, there is a loop that checks pins, but at 5 seconds, I want that loop interupted and a sub called, and then back to that loop. How might I do this? Thanks, -Jack C www.CREPinc.com |
|
|
|
Jack C At the start (before your main loop) check the system clock and store that value. Each time through the main loop compare the start time to the current time and when five seconds has elapsed trigger the jump to the sub that you want executed. After the completion of you sub reset the clocks initial value (by checking the clock again) and go back to your main loop. In five seconds the sub will be triggered again and on it goes. Harry -----Original Message----- From: Jack [mailto:] Sent: Saturday, May 10, 2003 3:46 PM To: Subject: [BasicX] MultiTasking Hey All I have a vehicle which, at certain time periods after start, needs to perform a function. But all the while, (while not doing the timed function) it needs to check pins to see if obstacles are in the way or not. ie, there is a loop that checks pins, but at 5 seconds, I want that loop interupted and a sub called, and then back to that loop. How might I do this? Thanks, -Jack C www.CREPinc.com [Non-text portions of this message have been removed] |
|
How about using the Timer function: -------------------------------- Sub Main Dim Five_Secs As Single Five_Secs = Timer() Do Call CheckPins() If ( (Timer() - Five_Secs ) >= 5.0) Then Call Special_Function() Five_Secs = Timer() End If Loop End Sub -------------------------------- The Timer() will roll over in a day. If you run continuously, you have to do roll over correction when the value gets to 86400 seconds. Emil H At 03:45 PM 05/10/2003, you wrote: >Hey All > >I have a vehicle which, at certain time periods after start, needs to >perform a function. But all the while, (while not doing the timed >function) it needs to check pins to see if obstacles are in the way >or not. ie, there is a loop that checks pins, but at 5 seconds, I >want that loop interupted and a sub called, and then back to that >loop. How might I do this? > >Thanks, > >-Jack C |
|
BasicX supports virtual interrupts using multi tasking/threading. There is a way to make it "listen" for obstacles continuously (while doing other things) and trigger a function when an obstacle is detected. I think this would work best for your device. There should be information about multi tasking in the manual. --- In , "Jack" <nutzo_skiers@y...> wrote: > Hey All > > I have a vehicle which, at certain time periods after start, needs to > perform a function. But all the while, (while not doing the timed > function) it needs to check pins to see if obstacles are in the way > or not. ie, there is a loop that checks pins, but at 5 seconds, I > want that loop interupted and a sub called, and then back to that > loop. How might I do this? > > Thanks, > > -Jack C > www.CREPinc.com |