We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi I am trying to use a Timer 0 as a 16-bit Timer to generate an Interrupt every 10 ms. In this example (downloaded from keil), the Interrupt is generated every 65536 clocks My question is how would i modify the example so that the interrupt is generated not according to the clock cycles, but rather by how much time passed away? Do I have to prescale the clock that is benig feed to Timer 0? if so, how? static unsigned long overflow_count = 0; void timer0_ISR (void) interrupt 1 { overflow_count++; /* Increment the overflow count */ } void main (void) { TMOD = (TMOD & 0xF0) | 0x01; /* Set T/C0 16-bit Timer Mode */ ET0 = 1; /* Enable Timer 0 Interrupts */ TR0 = 1; /* Start Timer 0 Running */ EA = 1; /* Global Interrupt Enable */ while (1) { } }
Hi, Try this:-
#define XTAL 22.1184e6 /* system clock frequency */ #define CLOCK_TICK_PERIOD 20e-3 /* time period required (= 20ms.) */ #define CLOCK_TICK_RELOAD (unsigned int)(-CLOCK_TICK_PERIOD * XTAL / 12) /* Timer 0 16 bit relaod value for 20ms. clock tick */ TH0 = CLOCK_TICK_RELOAD / 0x100; /* For my example a 20ms. Timer */ TL0 = CLOCK_TICK_RELOAD & 0xFF;