Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Motor RPM using IR and 8051

Status
Not open for further replies.

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
640
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,298
Activity points
6,922
Hi all,
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("     ");
  }
}
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
 

Attachments

  • b53c3538-19da-49ce-b93b-1654dea77331.jpg
    b53c3538-19da-49ce-b93b-1654dea77331.jpg
    106.1 KB · Views: 143

Hi,

What if during this: while(motor_1_signal==1);
a timer overflow happens?

--> you will miss the timer overflow and thus your timing is not correct.

Did you check wheteher the "3s" are correct.


Why don´t you use an interrupt? Less programming effort, best precision, less then 1% processing time.

Klaus
 

Hi,

What if during this: while(motor_1_signal==1);
a timer overflow happens?

--> you will miss the timer overflow and thus your timing is not correct.

Did you check wheteher the "3s" are correct.


Why don´t you use an interrupt? Less programming effort, best precision, less then 1% processing time.

Klaus

You are right Klaust.
i am having the wrong timing. the timing goes around 4.25 to 4.9 seconds instead of 3
will try using an interrupt

- - - Updated - - -

yes... bit confused.. can you help me for the logic.
how can i implement this using timer interrupt.
should i increment cnt value by 1 in interrupt and if so for how many seconds.
how can i create a delay for specific time
 

Hi,

Use one timer to generate the "window" timing.
User another counter, to count the edges.

****
You may use one interrpt, but then you need to give us the timing of the IR signal. At least min HIGH time and min LOW time. Absoulte values.

Klaus
 

Hi,

Use one timer to generate the "window" timing.
User another counter, to count the edges.

****
You may use one interrpt, but then you need to give us the timing of the IR signal. At least min HIGH time and min LOW time. Absoulte values.

Klaus

sorry did not get your point.
how can i give the min HIGH time and LOW time of IR signal... it depends upon the RPM of motor, which is going to vary.
 

Hi,

sorry did not get your point.
how can i give the min HIGH time and LOW time of IR signal... it depends upon the RPM of motor, which is going to vary.
true:
* LOW time depends on RPM
* HIGH time depends on RPM

But MINIMUM timing is your personal decision.
We can´t know what´s your maximum RPM and what is the expectable duty cycle. Only you know.

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top