??? 11/02/09 10:23 Read: times |
#170331 - Odd calculation result... |
Keil 7.5 + simulator.
I'm obviously doing something wrong here, but I've stared at it for ages, and I don't understand where this is going wrong. I'm calling the function below with a value of TICK_MS = 10 (confirmed in the simulator). OSC_FREQ is 12000000UL. OSC_PER_INST is 12. As far as I can see this should give an Inc value of 10000 (which it does, again confirmed in the simulator) and a Reload_16 value of 55536 (0xD8F0), but I always get 0x0000 here instead. In fact, I seem to get 0x0000 here whatever value of TICK_MS I use. A little hint would be grand. I'm willing to bet that it's something really stupid :). Thanks in advance, Rob. /*-*------------------------------------------------------------------ COPYRIGHT --------- This code is associated with the book: EMBEDDED C by Michael J. Pont [Pearson Education, 2002: ISBN: 0-201-79523-X]. This code is copyright (c) 2001 by Michael J. Pont. See book for copyright details and other information. -*------------------------------------------------------------------*/ void sEOS_Init_Timer0(const tByte TICK_MS) { tLong Inc; tWord Reload_16; // Using Timer 0, 16-bit *** manual reload *** TMOD &= 0xF0; // Clear all T0 bits (T1 left unchanged) TMOD |= 0x01; // Set required T0 bits (T1 left unchanged) // Number of timer increments required (max 65536) Inc = ((tLong)TICK_MS * (OSC_FREQ/1000)) / (tLong)OSC_PER_INST; // 16-bit reload value Reload_16 = (tWord) (65536UL - Inc); // 8-bit reload values (High & Low) Reload_08H = (tByte)(Reload_16 / 256); Reload_08L = (tByte)(Reload_16 % 256); // Used for manually checking timing (in simulator) //P2 = Reload_08H; //P3 = Reload_08L; TL0 = Reload_08L; TH0 = Reload_08H; // Timer 0 interrupt is enabled, and ISR will be called // whenever the timer overflows. ET0 = 1; // Start Timer 0 running TR0 = 1; // Globally enable interrupts EA = 1; } |
Topic | Author | Date |
Odd calculation result... | 01/01/70 00:00 | |
Hmm. Even odder. | 01/01/70 00:00 | |
what is the definition... | 01/01/70 00:00 | |
Compiler reuses registers and memory cells | 01/01/70 00:00 | |
Ah. | 01/01/70 00:00 | |
Disable compiler optimizations. | 01/01/70 00:00 | |
Compiler bug? | 01/01/70 00:00 | |
Maturity of compilers | 01/01/70 00:00 | |
the primary suspect should always be the end user. | 01/01/70 00:00 | |
"innovation" as alternative name for bug | 01/01/70 00:00 | |
C51 also does that! | 01/01/70 00:00 | |
C51 has smart linker | 01/01/70 00:00 | |
I found a some genuine compiler bugs. | 01/01/70 00:00 | |
Broken code in RTL is the worst | 01/01/70 00:00 | |
Thanks! | 01/01/70 00:00 | |
Defs | 01/01/70 00:00 | |
poor choice of names | 01/01/70 00:00 | |
Good data types are really critical | 01/01/70 00:00 | |
I'm an idiot. | 01/01/70 00:00 | |
informative! | 01/01/70 00:00 | |
"Answer is wrong" | 01/01/70 00:00 | |
Which one would you prefer??![]() | 01/01/70 00:00 |