User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 30 © 2009 Microchip Technology Inc.
Finally, TMR0 is a writable register. Meaning that a value can be added to the register
to offset the number of counts it takes for the overflow to occur. Equation 3-3 demon-
strates how to calculate the value to preload the TMR0 register with to create a 10mS
overflow period.
EQUATION 3-3: CALCULATING A TMR0 PRELOAD VALUE TO GENERATE A
10MS OVERFLOW PERIOD
The software flowchart to implement a 10mS delay is shown in Figure 3-13.
FIGURE 3-13: DELAY_10MS() USING TIMER0
The maximum overflow period that can be achieved using Timer0 only utilizes a 1:256
prescaler is as shown in Equation 3-4.
Desired TMR0 Overflow Period = (4/FOSC) x (256 - Preload Value) x prescaler
Using a 1:64 prescaler setting, a 4 MHz internal oscillator and requiring a 10 mS
overflow period:
10mS = 1
μSecond x (256 - Preload Value) x 64
10mS/(1
μSecond x 64) = 256 - Preload Value
Preload Value = 256 - [10mS/(1
μSecond x 64)]
Preload Value = 99.75 rounded up becomes 100
Therefore, to produce a 10 mS overflow period, using the internal instruction
clock with a 4 MHz internal oscillator and a TMR0 prescaler value of 1:64
requires that TMR0 be preloaded with a value of 100.
Delay_10mS()
END
YES
NO
Preload TMR0 register with 100
Clear the TMR0 overflow flag
(T0IF)
T0IF = 0?