gauravkothari23
Advanced Member level 2
Hi all,
I am trying to make RPM Meter using 8051 Microcontroller.
code:
It shows wrong RPM on LCD.
as i am rotating the DC motor at the speed of 80 RPM(i am sure about the speed of Motor because at 80 RPM, the RPM can be easily visualize and counted manually), but the it shows 280 to 300 on LCD.
what i have done in the code is:
created a delay function for 3 seconds and incremented the cnt variable by 1, and again after delay function i multiple the cnt valve by 20 to get the value for 1 minute and store it in rpm and then print it on LCD.
can anybody please let me know what the issue is
- - - Updated - - -
Here is the image of IR and Motor.
- - - Updated - - -
Crystal value is 11.0592
I am trying to make RPM Meter using 8051 Microcontroller.
code:
Code:
#include <REG51.h>
#include <stdio.h>
sbit LCD_en=P0^0; // LCD EN
sbit LCD_rs=P0^1; // LCD RS
sbit motor_1_signal=P1^5;
unsigned int cnt=0;
unsigned char buf[8];
void msdelay(unsigned int value)
{
unsigned int i,j;
for(i=0;i<value;i++)
for(j=0;j<100;j++);
}
void delay()
{
unsigned int i;
for(i=0;i<1500;i++)
{
TMOD = 0x01; // Timer 0 Mode 1
TH0= 0xF8; //initial value for 2ms
TL0 = 0xCC;
TR0 = 1; // timer start
while (TF0 == 0) // check overflow condition
{
if(motor_1_signal==1)
{
cnt=cnt+1;
while(motor_1_signal==1);
}
}
TR0 = 0; // Stop Timer
TF0 = 0; // Clear flag
}
}
void main()
{
unsigned int rpm,i;
msdelay(20);
LCD_init();
lcdclear();
buz=0;
lcdrow1();
LCD_puts("MOTOR-1 RPM");
while(1)
{
cnt=0;
delay();
rpm=0;
rpm=cnt*20;
for(i=0;i<8;i++)
buf[i]='\0';
lcdrow2();
sprintf(buf, "%d", rpm);
LCD_puts(buf);
LCD_puts(" ");
}
}
as i am rotating the DC motor at the speed of 80 RPM(i am sure about the speed of Motor because at 80 RPM, the RPM can be easily visualize and counted manually), but the it shows 280 to 300 on LCD.
what i have done in the code is:
created a delay function for 3 seconds and incremented the cnt variable by 1, and again after delay function i multiple the cnt valve by 20 to get the value for 1 minute and store it in rpm and then print it on LCD.
can anybody please let me know what the issue is
- - - Updated - - -
Here is the image of IR and Motor.
- - - Updated - - -
Crystal value is 11.0592