![]() |
Interrupt timer, executing code asap?
Thanks for Innovation First for that good white paper on timers, without that I'd be lost. :)
Well I got the interrupt timer working, looks good. So I wrote this function to use the loop code. Here is the code: Code:
void example(unsigned int seconds, char startEnd)My question: does this approach even work in practice? I know that you have to be zip zip in and out of interrupts, but in the whitepaper it says that the interrupt od is the most effective timer. So does my example() start and end always take less than one second? Have I approached this totally wrong? Any tips? I wouldn't recommend anyone to take this code for their own, it most likely doesn't work. :) |
Re: Interrupt timer, executing code asap?
Was I meandering in my meaning? I apologize, sometimes I do that.
My question is purely that if a function is executed, does everything else stop while that is exected? |
Re: Interrupt timer, executing code asap?
Quote:
Yes, only one thing can be happening at a time. When an interrupt occurs, whatever is currently happening stops, and the data being used gets set aside (onto the stack actually) Then the interrupt handler runs, and handles the interrupt (obviously). Then whatever code was running before resumes where it left off, without any real knowledge of the interruption. Let me know if this doesn't answer you question. |
Re: Interrupt timer, executing code asap?
So my example(), if it took 5 seconds (start and end each), then the timer itself would be off by 10 seconds? Well I need a fork(). :)
|
Re: Interrupt timer, executing code asap?
technically, even fork() only does one thing at a time ;) it just interlaces the needs of multiple things, so that part of one function executes, then part of the next, et cetera.
solution? no function in your bot code should last 5 seconds ;) |
Re: Interrupt timer, executing code asap?
Quote:
|
Re: Interrupt timer, executing code asap?
that too ;) heck, no individual function should last anywhere near 26ms :)
|
Re: Interrupt timer, executing code asap?
except sine ;):);):) Well, if you forgot the lookup table!
|
Re: Interrupt timer, executing code asap?
wouldn't be that useful a sine function if it took near 26ms - remember, you have do do something with it too ;)
|
Re: Interrupt timer, executing code asap?
Real time programming requires the use of a "state machine", which is a programming technique where one state starts the motors, for example, and the second state monitors for a certain amount of time to pass before proceeding to the third state.
The second state can be entered multiple times without causing any problems. So the second state checks the time, then reutrns to the code where the data packets can be handled. Then the same fuction is called to execute the seconds state which looks at the time again. State machines are best implemented using the C "switch" statement, and some long hard thinking. |
Re: Interrupt timer, executing code asap?
Quote:
-Kevin |
| All times are GMT -5. The time now is 18:17. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi