ATmega8 based RPM Meter

Hello All,
Today I will show you how you can make a simple RPM Meter using AVR ATmega8. The RPM meter we will be making is a contact less type, i.e. it measures the RPM of a rotating object without actually making any contact with it. An IR reflectance sensor will be used to sense the speed. You have to attach a white reflective object (like a white paper sticker) at one point in the periphery of rotation . Then you need to place the reflectance sensor such that the white reflector comes just above it once per rotation. In this way the sensor will give one falling edge to the MCU per rotation, we will measure number of such pulse in one second to get the revolution per second, multiplying this with 60 we get RPM.
For this project I will use a ATmega8 MCU connected to a 16×2 LCD Module for showing the RPM.

Design of AVR based RPM Meter.

The sensor part is made up of TCRT5000 IR Reflectance sensor. It it wired as shown below. The sensor will give a LOW output whenever it detects a white reflective surface just above it. This output is feed to the INT0 pin of MCU. INT0 is a general purpose external interrupt source. It can be adjusted to interrupt the CPU on Rising, falling, low level or high level. In this project we configure it to interrupt on falling edge. When ever a falling edge (high to low transition) is detected on INT0 pin the CPU jumps to the ISR which handles the even. The ISR just increments a global variable count, in this way we keep track of number of revolution.
TIMER1, which is a 16 bit counter is used to generate an interrupt each second. On TIMER1 ISR we just copy the value of count to another global variable rps. And clear count to zero. The input to TIMER1 is taken by prescaler which is set at 1:1024, that means TIMER1 is clocked at 1/1024 of system clock. As our system clock is 1000000, timer frequency is 1000000/1024=976 Hz. To get exact 1 sec time base we use the comparator unit of timer, we set compare value to 976. So as soon as TIMER1 reaches 976 it is cleared to 0 (CTC mode) and an interrupt called output compare 1A (1 because it is timer1 and A because timer1 has 2 comparator A and B)
In the main loop of the program we just print RPM and RPS.
The above circuit made on a mini bread board.

Schematic of AVR based RPM Meter

RPM Meter Schematic Thumb

AVR GCC code for RPM Meter.

#include <avr/io.h>  #include <avr/interrupt.h>  #include <util/delay.h> #include "lcd.h"  volatile uint16_t count=0; //Main revolution counter volatile uint16_t rpm=0; //Revolution per minute  volatile uint16_t rps=0; //Revolution per second 
void Wait() {  uint8_t i;  for(i=0;i<2;i++)  {  _delay_loop_2(0);  } }
For more detail: ATmega8 based RPM Meter 

Related Post

Be the first to comment

Leave a Reply

Your email address will not be published.


= 4 + 7

Read previous post:
Networking and Internetworking Wirh Microcontrollers – AVR E-Book

Today, networking capability in one form or another- in particular internet accessibility- is becoming mandatory in many embedded applications, including...