Question

From Microchip sample code

PR2 = 2083u;     /* Timer2 Period, 19.2 kHz */ 

How does 2083u correspond to 19.2 kHz, which is

1 / 19.2E03 = 52.083u

They don't correspond at all. Mistake by Microchip?

Was it helpful?

Solution

PR2 = 2083U

makes TIMER2 trigger every 2083 CPU cycles. Calculating

52.083 us / 2083 = 25 ns
1 / 25 ns = 40 MHz

we can conclude that the processor is probably running at FCY = 40 MHz in the example.

The letter u in PR2 = 2038u; does not mean microseconds; it is a C language syntax that makes the integer literal unsigned. See Signedness (Wikipedia).

OTHER TIPS

Setting PR2 to 2083 means that the timer triggers every 2084 (not 2083) clock cycles. When you calculate a timer period, you always have to subtract 1 because the timer value is zero-based.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top