1 minute read

3.5 Programming TIMER0 As Counter

Next Article
REVIEW QUESTIONS

REVIEW QUESTIONS

//function for time delay 500ms void delay_500ms( ) {

T0CON=0b00000101; //Configure timer for10MHz crystal, 16-bit mode prescaler 1:64 TMR0H=0xB3; TMR0L=0xB5; TMR0ON= 1; while(TMR0IF== 0); // Keep monitoring the TMR0IF TMR0ON= 0; // Stop the timer TMR0IF= 0; //Clear TMR0IF

Advertisement

3.5 Programming Timer0 as Counter

Timers are also used as counters to count events happening outside the microcontroller.

Example application of counter is Measuring the RPM (speed in revolution per minute) of the

rotating wheel. A small magnet is attached in the edge of the wheel as shown in Figure 3.13.

Whenever this magnet is exactly below the Magnetic sensor its output becomes high. This

output is connected to the T0CKI (Timer0 Clock Input) pin of the MCU. So each time the

magnet passes by the sensor the timer register inside the MCU is incremented. These all

happen without the help of CPU. CPU can do other task and read the Timer register only when

required. The system connected as shown in Figure 3.13.

Figure 3.13: Example application of counter (https://extremeelectronics.co.in)

This article is from: