View
573
Download
1
Category
Preview:
Citation preview
| RPM Counter Using Microcontroller AT89C4051 1
RPM COUNTER USING MICROCONTROLLER
AT89C4051
1. WHAT IS RPM COUNTER
An instrument that measures angular speed, as that of a rotating
shaft. The measurement may be in revolutions over an
independently measured time interval, as in a revolution counter,
or it may be directly in revolutions per minute. The instrument
may also indicate the average speed over a time interval or the instantaneous speed. RPM
Counters are used for direct measurement of angular speed and as elements of control
systems to furnish a signal as a function of angular speed.
2. REVOLUTIONS PER MINUTE
Revolutions per minute (abbreviated rpm, RPM, r/min, or r·min−1
) is a measure of the
frequency of a rotation. It annotates the number of full rotations completed in one minute
around a fixed axis. It is used as a measure of rotational speed of a mechanical component.
Standards organizations generally recommend the symbol r/min, which is more consistent
with the general use of unit symbols.
2.1 International System of Units
According to the International System of Units (SI), rpm is not a unit. This is because
Revolutions is a semantic annotation rather than a unit. The annotation is instead done in the
subscript of the formula sign if needed. Because of the measured physical quantity, the
formula sign has to be f for (rotational) frequency and ω or Ω for angular velocity. The
corresponding basic SI unit is s−1
or Hz. When measuring angular speed, rad·s−1
can also be
used as unit.
| RPM Counter Using Microcontroller AT89C4051 2
Even though angular velocity, angular frequency and hertz all have the dimensions of 1/s,
angular velocity and angular frequency are not expressed in hertz, but rather in an appropriate
angular unit such as radians per second. Thus a disc rotating at 60 revolutions per minute
(rpm) is said to be rotating at either 2π rad/s or 1 Hz, where the former measures the angular
velocity and latter reflects the number of complete revolutions per second. The conversion
between a frequency f measured in hertz and an angular velocity ω measured in radians per
second are:
ω=2*π*f and f=ω/(2*π)
rpm to Hz
2400*2*3.14=15072 rad/min
15072/60=251.2 rad/s
(1800*2*3.14)/60=188.4 rad/s
(3300*2*3.14)/60=345.4 rad/s
3. INTRODUCTION
Counting the revolutions per minute (RPM) of motors determining the motor speed is
essential in the field of industrial automation. It is useful especially for closed-loop control
systems where proper action can be taken in case the actual RPM deviates from the set RPM.
This project is based on micro-controller AT89C4051 that measures and shows on an LCD
the RPM of a running motor. Using a proper transducer, first the rotations of the motor are
converted into pulses. The generated pulses are counted by the micro controller for a fixed
time (say, one second). The count is multiplied by a factor to get the exact RPM and then
displayed; if time is one second, the factor is 60.
4. CIRCUIT DESCRIPTION
Fig. 1 shows the block diagram of the RPM counter based on AT89C4051 microcontroller
that generates pulses for every rotation of the motor, counts them and shows on the LCD.
On a fixed base, there is a laser source on one side and the combination of a light-dependent
resistor (LDR), pulse generator, microcontroller and LCD on the other side. Both the
| RPM Counter Using Microcontroller AT89C4051 3
arrangements are housed in separate wooden cabinets such that the laser beam falls directly
on the LDR. The motor is placed on top of the laser source. A slotted wheel is attached to the
motor shaft. The wheel is so bit that it can interrupt the laser beam falling on the LDR.
As the motor rotates, the slotted wheel also rotates. The laser beam falls on the LDR
whenever the slot aligns with the laser beam and LDR, producing one pulse. Thus the
rotations of the motor are converted into pulses that can be counted by the program in the
microcontroller. Pulses are counted for one second. The pulse count is multiplied by 60
(because 1 RPM = 60 RPS) and finally shown on the LCD.
Fig. 2 shows the circuit of the RPM meter. It comprises microcontroller AT89C4051, timer
NE555, LCD module (16x2 line) and a few discrete components. Timer NE555 is configured
as a mono-stable multi-vibrator whose time period depends upon the combination of resistor
R1 and capacitor C1. Trigger pin 2 of NE555 is pulled high via resistor R2. The LDR is
connected along with resistor R2 to pin 2 of NE555 such that when the laser light falls on the
LDR, pin 2 goes low to trigger NE555.
The output form pin 3 of NE555 is inverted by transistor T1 and fed to port pins P3.3 and
P3.4 of the micro controller. LED2 is connected to port pin P3.0 (pin 2) of the
microcontroller. Data pins D0 through D7 of the LCD are connected to port pins P1.0
through P1.7 of the microcontroller, respectively. Control pins E, RS and R/W of the LCD
| RPM Counter Using Microcontroller AT89C4051 4
are connected to port pins P3.2, P3.5 and P3.7, respectively. A 12MHz crystal connected
between pins 4 and 5 of the microcontroller, along with two 22pF capacitors C4 and C5,
generates the basic clock frequency. Power-on reset is derived with the combination of
resistor R7 and capacitor C6. Switch S2 is used for manual reset.
| RPM Counter Using Microcontroller AT89C4051 5
5. OPERATION
1. As the motor starts rotating, the laser light falls on the LDR when the slot aligns
with the laser beam and LDR.
2. Every time the motor completes one rotation, the mono-stable (NE555) triggers to
generate one pulse, which is indicated by LED1. So LED1 blinks at the rate of
motor speed.
3. As the first pulse arrives, it generates an interrupt for the microcontroller and
immediately the microcontroller starts counting the pulses. This is indicated by
LED2. The LCD shows the message "Counting RPM.
4. The microcontroller counts the pulses for a period of one second. Thereafter,
LED2 shows the message "Counting finished....." and goes off. The
microcontroller stores the count and multiplies it by 60 to give the final RPM
count.
5. The count is in hex format, so you have to convert it into decimal first. As the
LCD accepts only ASCII values, the decimal values are converted into ASCII and
shown on the LCD one by one.
6. Now if you press RST switch, the process repeats.
| RPM Counter Using Microcontroller AT89C4051 6
Figure 4 Continuity Testing
Figure 3 Breadboard Testing
| RPM Counter Using Microcontroller AT89C4051 7
6. SOFTWARE
The software for the RPM counter is written in 'C'
language and compiled using Keil Vision3 compiler.
The generated 'hex' file is burn into the microcontroller
using a suitable programmer.
The various functions are detailed below:
1. Main function initializes the timer, LCD, ports, etc. displays the message "RPM
counter", clears the timer content and enables the external interrupt. It remains in
the loop till 'rpm flag' (flag) is not set. When the RPM counting completes, it
displays the RPM value if it is within the range.
2. Int1 is an interrupt based function that is called automatically when there is a
negative edge on external interrupt 1 pin (P3.3). As soon as the first negative edge
arrives, the counter starts counting the external pulses for one second. After one
second, the content of TL0 is compared with A6h (166d). For any number greater
than 166, multiplication with 60 will yield a number that is longer than four digits,
which is out of the display range. This means RPM of max. 9960 (166x60) can be
displayed. Otherwise, the LCD will show the message "RPM Out of Range".
Figure 5 Connections on PCB
| RPM Counter Using Microcontroller AT89C4051 8
3. Display function performs three tasks one by one :
(i) Converts hex number in TL0 into decimal and multiplies it by 60
(ii) Converts the final decimal number into equivalent ASCII characters one
by one
(iii) Displays all the ASCII characters one by one on the LCD.
4. Write cmd function sends command byte to the LCD. It takes one argument byte
and sends sit to P1.
5. Write data function sends the data byte to be displayed on the LCD. It also takes
one argument byte and sends it to port P1.
6. Write str function writes the entire string (message) on the LCD. It takes the
pointer as an argument that points the address of the first character of the string.
Then through the pointer, it sends all the characters one by one to P1.
7. Busy function checks the status of the busy flag of the LCD. if the flag is set, that
means the LCD is not ready and the program remains within the loop. When the
flag is reset, the LCD is ready and the program comes out of the loop.
8. Delay function generates a fixed delay of one second using timer 0. The basic
delay is of 50 milliseconds, which is rotated in the loop for 20 times to generate
total delay of 20x50 ms = 1000 ms = 1 second.
6.1. PCB Designing & CAD
Although the circuit is tested on general purpose PCB but due to the
complexity of the connections make it very difficult to understand. So that
with the help of CAD it is done for much simple & easier.
In this project double side printed PCB is used means that printing is done on
both side of the PCB.
| RPM Counter Using Microcontroller AT89C4051 9
7. Program of RPM Counter
#include<reg51.h>
#include<string.h>
sbit rs = P3^5; // rs pin of LCD
sbit en = P3^2; // en pin of LCD
sbit rw = P3^7; // rw pin of LCD
sbit b = P1^7; // busy flag
sbit led = P3^0; // led indication
unsigned int flag=0; // rpm flag
void delay() // 1 sec delay
{
int k;
TL1 = 0xAF; // load value 15535=3CAF
TH1 = 0x3C;
TR1 = 1;
for(k=0;k<20;k++)
{
while(TF1==0);
TF1 = 0;
TL1 = 0xAF;
TH1 = 0x3C;
}
TR1 = 0;
}
void busy() // check busy flag
{
en = 0;
P1 = 0xFF;
rs = 0;
rw = 1;
while(b==1)
{
en=0;
en=1;
}
en=0;
}
void writecmd(unsigned char a) // send command byte to LCD
{
busy();
rs = 0;
rw = 0;
| RPM Counter Using Microcontroller AT89C4051 10
P1 = a;
en = 1;
en = 0;
}
void writedata(unsigned char b) // send data byte to LCD
{
busy();
rs = 1;
rw = 0;
P1 = b;
en = 1;
en = 0;
}
void writestr(unsigned char *s) // write string / message to LCD
{
unsigned char l,i;
l = strlen(s);
for(i=0;i<l;i++)
{
writedata(*s);
s++;
}
}
void int1(void) interrupt 2 // external interrupt 1 function
{
EA=0; // first disable interrupts
led=0; // give indication
writecmd(0x01);
writestr("counting RPM...."); // display message
TR0=1; // start timer 0
delay(); // give 1 sec delay
TR0=0; // stop timer
writecmd(0x80);
writestr("counting finish "); // display message
led=1;
if(TL0>0xA6)
{ // if value more then
166
writecmd(0xC0);
writestr("RPM out of range");// send message
}
else flag=1; // if not then set the
flag
}
void display() // convert hex to desimal and
{ // decimal to ascii
| RPM Counter Using Microcontroller AT89C4051 11
unsigned int tmp1,tmp2,t,t1,i,j;
unsigned char asci[4];
tmp1 = (TL0 & 0x0F); // get lower nibble of
TL0
tmp2 = TL0 >> 4; // get upper nibble of
TL0
tmp2 = tmp2*16; // multiply upper
nibble with 16
t = tmp1+tmp2; // get decimal number
t=t*60; // multiply it with
60
i=3;
if(t>=1000) // if more then 4
digits
{
while(t>10)
{
t1=t%10;
asci[i]=t1+0x30; // convert them one by one
t=t/10; // into ASCII
i--;
}
asci[0]=t+0x30;
}
else // otherwise convert
{
while(t>10)
{
t1=t%10;
asci[i]=t1+0x30; // last three digits
t=t/10;
i--;
}
asci[1]=t+0x30;
asci[0]=0x30; // and put first digit as 0
}
writecmd(0xC0);
writestr("currentRPM:"); // display current RPM and
for(j=0;j<4;j++)
writedata(asci[j]); // all four digits one by one
}
void main()
{
TMOD=0x15; // timer 0 in 16 bit counter
and timer 1 in 16 bit counter
P1 = 0x00; // P1 as output port
| RPM Counter Using Microcontroller AT89C4051 12
rs=0; // clear all LCD control
pins
en=0;
rw=0;
writecmd(0x3C); // initialize LCD
writecmd(0x0E);
writecmd(0x82);
writestr("RPM Counter"); // initially display message
TH0=0x00; // clear T0
TL0=0x00;
IE=0x84; // enable external interrupt
1
while(flag==0); // remain within loop till rpm flag is clear
display(); // when flag is set display current RPM value
while(1); // continuous loop
}
8. SOFTWARE USED FOR CRICUIT
i) For Schematic circuit design
Dip trace Schematic
ii) Circuit Testing
Circuit Wizard
iii) For PCB design
Dip trace PCB design
| RPM Counter Using Microcontroller AT89C4051 13
9. PCB LAYOUTS
Top Current Mirror
| RPM Counter Using Microcontroller AT89C4051 14
Bottom Current Mirror
| RPM Counter Using Microcontroller AT89C4051 15
Top Current Contrast
| RPM Counter Using Microcontroller AT89C4051 16
10. REFERENCES
1. RPM Counter definition: McGraw-Hill Science &
Technology Encyclopaedia
2. Revolution Per Minute:
http://en.wikipedia.org/wiki/Revolutions_per_minute
3. AT89C4051 Datasheet
http://www.atmel.com/dyn/resources/prod_documents/doc1001.pdf
4. NE555 Timer IC
http://www.datasheetcatalog.org/datasheet/philips/NE_SA_SE555_C_2.pdf
5. Resistance Colour Coding: http://www.vishay.com/docs/28733/28733.pdf
Recommended