Make Tachometer or RPM meter use PIC16F877A Microcontroller and mikorC compiler
In this tutorial we will learn how to make Tachometer or PRM counter use PIC Microcontroller. Tachometer count the RPM of wheel and show the value on display. Here I am use PIC16F877A Microcontroller and mikroC PRO for PIC compiler for code editing.
You can watch the video or read the written tutorial below.
PIC16F877A Microcontroller has three Timer Module.
- Time0
- Timer1
- Timer2
The Timer modules are use Timer or Counter. The Timer module can be measure time and pulse.
In this project I am use two Timer module . Timer0 and Timer1 module. Timer0 module has 8-bit TMR0 register and Timer1 module has two 8-bit register pair(TMR1H : RMR1L) total 16-bit.
The Timer0 module count the wheel rotation. It can be count maximum (2^8 - 1) = 256-1 = 255 rotation at second. If rotation 2 turn/s, than RPM is 2 * 60 = 120. RPM means Rotation Per Minute.
Here I am use Timer1 module for generate 250ms interrupt. The Timer1 module generate interrupt 250ms and increase the value of i. Here i is integer variable. It generate 1second delay. The Timer1 module does not generate 1second .
In this project Timer0 module measure the rotation and Timer1 module generate 1second delay for rotation count. After 1second delay the software clear the TMR0 module.
The IR Sensor module use here for conversion. IR sensor module convert the rotation in pulse. The Timer0 module count this pulses.
Here I am use Timer Calculator for 250ms Timer1 Interrupt.
Circuit Diagram
Source Code
// Lcd module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
//end lcd module connections
#define IR PORTD.RD7 // RD7 pin is pulse input pin
int rotation=0;
int rpm = 0;
char text[15];
int i = 0;
//Timer1
//Prescaler 1:8; TMR1 Preload = 3036; Actual Interrupt Time : 250 ms
void Interrupt(){
if (TMR1IF_bit){
TMR1IF_bit = 0;
TMR1H = 0x0B;
TMR1L = 0xDC;
i++; // increase the value of i
}
}
void main() {
Lcd_Init(); // Initialize the Lcd module
Lcd_Cmd(_LCD_CLEAR); // Clear Lcd display
Lcd_Cmd(_LCD_CURSOR_OFF); // Lcd Cursor off
Lcd_Out(2,2,"RPM Counter");
Lcd_Out(1,3,"TECHOMETER");
delay_ms(2000); // 2 second delay
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,3,"DEVELOPED BY");
Lcd_Out(2,1,"MINA TECHNOLOGY");
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
T1CON = 0x31;
TMR1IF_bit = 0;
TMR1H = 0x0B; // Reload the TMR1 Register
TMR1L = 0xDC;
TMR1IE_bit = 1; // Enable the Timer1 interrupt
INTCON = 0xC0;
OPTION_REG.T0CS = 1 ; // Timer0 use as a counter
OPTION_REG.T0SE = 0; //Increment on high-to-low transition on the TMR0 pin
TMR0 = 0; // Clear the TMR0 Register
Lcd_Out(1,2,"=====RPM====:");
while(1){
TMR0 =0; // Clear the TMR0 Register
i=0; // clear i
while(i !=4); // 1s delay
rotation = TMR0;
rpm = rotation * 60; // rotation count at 1s . if rotation 2 at a 2second
IntTostr(rpm,text); // rpm = (4/2)*60 = 120
Lcd_Out(2,1,text);
}
}
Download free source code
Post Comments