Control loop- routine repeating after fixed time- help!
dp81732
Posts: 1
What I really need to do is measured elapsed time during program execution.
I'm trying to set up a simple control loop that will endlessly loop.
I want to read some inputs (buttons) every 100ms and update the display every 200ms.
The problem is that I want the tasks to start after the 100ms or 200ms and continue, then run again at the next interval- instead of running all the code, then putting in a delay.
Any recommendations?
I was thinking of maybe using a simple oscillator to trigger an input.
Thanks.
I'm trying to set up a simple control loop that will endlessly loop.
I want to read some inputs (buttons) every 100ms and update the display every 200ms.
The problem is that I want the tasks to start after the 100ms or 200ms and continue, then run again at the next interval- instead of running all the code, then putting in a delay.
Any recommendations?
I was thinking of maybe using a simple oscillator to trigger an input.
Thanks.
Comments
I believe·http://www.rhombus-tek.com/co-processors.html makes a "Simple Multi-Tasking Co-processor" which can be set to output a signal every 100 mSec, that you can use to synchronize your process.
I used an 890k or so resistor and .1 capacitor and got about 62337 so:
62337 times 2 = 124,674 uS
124,674 / 1000 = 124.67 mS
So you need a bit less resistance to get the rctimer to return 50,000, to equal 100 mS
Remember the capacitor has an error percentage that makes a big difference at the far end of the time scale
You can make a timer to any number of mS you wish as you are just polling the pin for a low state
and RCtim has a maximum of 65535 time units (BS2=2us per time unit)
So when I comment out the rctime and uncomment the other code I get the loop to execute about 157 times in 124 mS
Just set up an RC timeer resistor/capacitor circuit and add the subroutine to your program
include the variables and set up code. Will keep track of 65535 seconds then rolls over.
If you want a 24 hour clock use another variable and increment it by one in the timesub when seconds rolls over to 0
With a basic stamp 2 you can execute about 150 instructions every 100 mS so this is like an interrupt routine except
you must call the timesub routine manually. If you call it every 25 instructions you could be off time by 100/(150/25)
that is it takes 100 ms for 150 instructions so 25 instructions takes 100/6 or 16.6 mS
Now programs that have pause statements longer than 100 ms should be converted to polling the tenths variable instead
All loops and for next routines you should add gosub timesub before then NEXT statement or goto loop statement
Ok have fun.