??? 05/13/08 07:56 Read: times Msg Score: +7 +7 Good Answer/Helpful |
#154721 - Your program needs to be restructured Responding to: ???'s previous message |
Shawn,
Your problem is almost surely a result of the way you have structured your program. After main() gets everything initialized, it spins in a do-nothing loop while all the action takes place within the interrupt handlers. This is almost always a poor approach, especially when the interrupt handlers are as involved as those in your program. In general, interrupt handlers should be short, sweet, and to the point, leaving most of the processing to be done within a main loop of some sort that is straightforward and easy to understand. When everything is done within lenghty and complicated interrupt handlers, it's almost impossible to predict the control flow, and you wind up with interesting and mysterious problems exactly as you have seen. Here's just one example of what I'm talking about. In your program, TimerZeroHandler() sometimes calls draw() right near the end. But wait: a different interrupt handler, DSPHandler(), also calls draw()!!! Since you've given DSPHandler() high priority, that means that it can interrupt the timer interrupt handler, possibly during the time that the timer interrupt handler is within draw(). Did you know that this was possible? Can you imagine what will happen when draw() is interrupted and then called a second time from a second interrupt handler? Can you imagine what will happen after the second handler returns? Can you imagine now how your Contact[] array might get corrupted? If that isn't enough to confuse you, consider that draw() is also called by moveCursor() and enterPress(), both of which are called by a third interrupt handler, ButtonHandler(), which also has priority over the timer interrupt. Yikes! Unfortunately, the only real solution for your problem is to completely restructure the program in a way that can be understood by mere mortals. From what I can gather, you basically want to respond to various system events by updating a display of some sort. It appears that the events are: NEW_DSP_INFO_RECEIVED UP_BUTTON_PRESSED DOWN_BUTTON_PRESSED LEFT_BUTTON_PRESSED RIGHT_BUTTON_PRESSED ENTER_BUTTON_PRESSED --------------------- TILT_CHANGED HEADING_CHANGED It appears that the first six of these cause interrupts, and that the last two are detected by polling. If all that is true, then here is one way you could proceed:
|
Topic | Author | Date |
Struct member losing value | 01/01/70 00:00 | |
Please post your code | 01/01/70 00:00 | |
Posted here (along with file descriptions): | 01/01/70 00:00 | |
the can of worms | 01/01/70 00:00 | |
Your program needs to be restructured | 01/01/70 00:00 | |
Can't mod this one up enough. | 01/01/70 00:00 | |
Thanks for the tips | 01/01/70 00:00 | |
You're doing pretty good then. | 01/01/70 00:00 | |
I think that it can be said in a simple way | 01/01/70 00:00 | |
Sorry but.. | 01/01/70 00:00 | |
Agreed | 01/01/70 00:00 | |
the phrase was | 01/01/70 00:00 | |
I agree | 01/01/70 00:00 | |
Don't ignore rules | 01/01/70 00:00 | |
What is "short" in an ISR...? | 01/01/70 00:00 | |
Two Program | 01/01/70 00:00 | |
breaking switch/case![]() | 01/01/70 00:00 | |
Do you understand why? | 01/01/70 00:00 | |
make it a FAQ, please... | 01/01/70 00:00 |