View previous topic :: View next topic |
Author |
Message |
future
Joined: 14 May 2004 Posts: 330
|
What would be your solution to an event driven code? |
Posted: Thu Feb 17, 2005 11:24 pm |
|
|
Hi,
Talking about a program to watch 8 a/d inputs and 2 digital.
A good amount of math is involved, but they need to be evaluated only when one of the input changes.
I want to know how would you code it, no code needed just ideas.
Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 17, 2005 11:49 pm |
|
|
If I had to do it, I would use multi-tasking method that I describe
in this thread, and poll the inputs in one or more tasks (routines).
If the input had changed to a specified state, then I would also
perform some appropriate action in the task routine.
http://www.ccsinfo.com/forum/viewtopic.php?t=17189 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Feb 18, 2005 8:18 am |
|
|
My method would be very similar to PCM's. Recently, I have been taking a more modular approach. I have a timer set to go off at a certain interval. This is the "system tick". The main loop monitors the system tick and when it occurs calls a routine in each of my modules to handler their timers. In each of the module timer routines if anything needs to happen, a module level flag is set. The main loop also calls a task routine in each of the modules. This routine who check its flags and do the appropriate task. For my system tick, I actually increment a variable rather than just set a flag. The main "system tick" monitor gets called anytime the tick var is greater than zero. This keeps the whole system "in time" in case any task takes longer than a tick period. |
|
|
|