![]() |
Timer interrupt hic-cupping - HELP
Trying to set up a 32-bit 10Mhz timer...
I initialized Timer1 like this: Code:
volatile unsigned int tmsClock = 0;Code:
unsigned int GetTick(void) //Gets 16-bit timer valueBTW: I discovered this error around 3:00am on ship day, which was wreaking havoc on our autonomuous code. Without a controller to test on, I haven't been able to trace the problem. |
Re: Timer interrupt hic-cupping - HELP
Quote:
In GetTick(), why not just set Timer_Snapshot to tmsClock? Doesn't the interupt go off every tick? or just on overflow? |
Re: Timer interrupt hic-cupping - HELP
Quote:
Define really large. As do you think the error is in the high 16 bit or the low 16? |
Re: Timer interrupt hic-cupping - HELP
Quote:
Code:
Since my terminal program converted the hexstring to decimal, I wasn't able to issolate it to ONLY the high 16. |
Re: Timer interrupt hic-cupping - HELP
Printf expects signed ints. Use the other guy's lib. (See Getting Long Data)
|
Re: Timer interrupt hic-cupping - HELP
Quote:
[edit]My error. I forgot about the %lx format being available in printf. Our original issue with printing longs was with interpreting signed longs easily. Thanks for the correction Random. |
Re: Timer interrupt hic-cupping - HELP
Quote:
No, the %lx directive supports longs. Though, as to the orignial question, I think it may be a critical section problem, where the interrupt code is running during a critical part of the main code. Specifically: ThisTick=tmsClock; That line actually compiles to about 10 lines of assembly. If the interrupt occurs during that section, really odd things can happen. You may need to disable interrupts right before that, and reenable them right after it. [edit] Further thought on this (and clarification as to the actual problem) makes me realize that this wouldn't occur quite that often.[/edit |
Re: Timer interrupt hic-cupping - HELP
Here is the ouput using the EDU controller: (I only output a line every 5th program loop) I marked lines that contain errors with asteriks.
Code:
|
Re: Timer interrupt hic-cupping - HELP
Quote:
GetTime() = 016017d1 tmsClock = 352 GetTime() = 016d104a tmsClock = 365 GetTime() = 017a08cf tmsClock = 378 ***** GetTime() = 01870181 tmsClock = 391 ***** Notice the extra 0's. The problem is the printf function doesn't zero pad the output like it should. That is 'ok' for the ints, but for the longs it causes problems (In the printf lib, the printi function actually gets called twice for longs. once for each word.) |
Re: Timer interrupt hic-cupping - HELP
You are right. Thanks for pointing that out.
It appears the timer is actually working correctly. Well, that's one less thing to worry about. Now, back to other things. |
| All times are GMT -5. The time now is 05:55. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi