??? 04/07/05 16:54 Read: times |
#91180 - A timing issue |
Have been having problems with timing in a code. The variations in the actual achieved timing were quite erratic and wrote a small checkout code. The MCU is P89v51rd2 @ 6Mhz in 6-clk mode. The display is a 16C x 2L LCD.
In the checkout code, I simply toggled a LED and tried to read the On time and Off time. Instead of them being equal at 1000, I get 1000/768 ms and that 768 occurs randomly. Similarly if I load 2000ms , I get 2000/1902 and that 1902 happens randomly. I get similiar FIXED variation for other delays. What could be the reason. The checkout code is given. Since for every delay, the variation is fixed, I am suspecting any hardware problem and hence not changed the crystal / MCU. What else could be wrong ? //============================================= // T2 is set for a 1ms interrupt in auto-reload void timer2_int(void) interrupt 5 using 2 { TF2 = 0; ++checkCount; // count of ms ++msTick_1 ; // count of general purpose delay } //============================================= //Part of Main code for checkout. No other part is active.. while(1) { LedFlash(); // checkCount is the actual delay in ms. if (toggle==0) sprintf (string, "%s%d","LED OFF:", checkCount ); else sprintf (string, "%s%d","LED ON: ", checkCount ); display(string); checkCount = 0; } //=============================================== void LedFlash (void) { msDelay(1000); // Flash Interval DOT_3 = ~DOT_3; // Change LED state for every call toggle = ~toggle; // Flag to change On/Off message } //================================================ //Time delay function. Call with required ms delay void msDelay (int DelayVal) { TR2 = 1; while ( msTick_1 < DelayVal); // msTick1 inc.by timer2_int msTick_1 = 0; TR2 = 0; } //================================================ Thanks Raghu |
Topic | Author | Date |
A timing issue | 01/01/70 00:00 | |
Atomicity? | 01/01/70 00:00 | |
curious | 01/01/70 00:00 | |
Synchonocity was the issue | 01/01/70 00:00 | |
Synchonocity and Atmomicity? | 01/01/70 00:00 | |
Let me try? | 01/01/70 00:00 | |
Atomic and Synchronous![]() | 01/01/70 00:00 |