Professional Documents
Culture Documents
Microcontroller Based TACHOMETER: Mini Project Report
Microcontroller Based TACHOMETER: Mini Project Report
INTRODUCTION
being finished. You may also want to measure the speed of fans you
PROBLEM DEFINITION:
SOLUTION:
In a situation as mentioned above, it is possible to use a
beam against the rotating element. The rotating element will have a
reflective spot, and the tachometer measures the rate at which the
engine life.
to infer the rate of blood flow from the speed at which the turbine
Circuit Description
1. AT89C2051 microcontroller
5. L14F1 photo-transistor.
Atmel Corporation. Port-1 pins P1.7 through P1.2, and port-3 pin P3.7 are
connected to input pins 1 through 7 of ULN2003. Port-1 pins are pulled up with
10-kiloohm resistor network RNW1. They drive all the seven segments of the
Port-3 pins P3.0 through P3.3 of the microcontroller are connected to the base of
transistors T1 through T4, respectively, to select one digit out of the four at a
time and to supply anode-drive currents to the common anode pin of respective
When pin P3.0 of microcontroller IC1 goes low, it drives transistor T1 into
saturation, which provides the drive current to anode pin 6 of 4-digit, 7-segment,
microcontroller IC1 drives the segment in multiplexed manner using its port
pulse for display are refreshed every 5ms. Thus, the display appears to be
reset the microcontroller, while the poweron-reset signal for the microcontroller
generate the basic clock frequency for the microcontroller. The circuit uses a 6V
battery for power supply or alternatively a mains derived low voltage supply.
Software:
AT89C2051’s internal timer for measuring the period of one cycle of the
25rps, and the time taken for one cycle is 40 ms. The timer uses an
counted by the timer program in this case will be ‘400.’ This is divided by
This gives the rpm. These digits are displayed on the 4-digit, 7-segment
WORKING:
When the light-sensitive probe tip is pointed towards a rotating shaft or disk (fixed
with a small reflector), the 4-digit, 7-segment displays the RPM of the shaft or disk.
Each time the reflector spins past the probe, the momentary increase in reflected light
counts the increase in the number of such light reflections sensed by it and thereby
The detected signal is amplified by transistor 2N2222 (T5) and further amplified by
operational amplifier CA3140 (IC3). The reference voltage point for the operational
amplifier is obtained by resistor divider network comprising R2 and R3. The output
from pin 6 of IC3 is fed to pin 12 of microcontroller AT89C2051. Note that pins 12
and 13 of microcontroller AT89C2051 are the inputs (+ and -) of its internal analogue
comparator. Pin 13 is adjusted to nearly half the supply voltage using a potential
divider comprising resistor R7 and preset VR1 across the supply. The pulses picked
through software, each pulse representing one rotation of the object is detected. By
counting the number of such pulses, on an average per minute basis, the RPM is
and further amplified by operational amplifier CA3140 (IC3). The reference voltage
point for the operational amplifier is obtained by resistor divider network comprising
R2 and R3. The output from pin 6 of IC3 is fed to pin 12 of microcontroller
AT89C2051. Note that pins 12 and 13 of microcontroller AT89C2051 are the inputs (+
and -) of its internal analogue comparator. Pin 13 is adjusted to nearly half the supply
voltage using a potential divider comprising resistor R7 and preset VR1 across the
supply. The pulses picked up by the phototransistor are sensed by the internal
average per minute basis, the RPM is evaluated. It is displayed by a software routine
CODE:
ORG 0BH ;TIMER 0 mov p3.5,c MOV B,#10 ; MOV 1AH,r5
INTERRUPT clr tr0 ;stop timer R7,R6,R5,R4,R3 MOV 1BH,R6 ; most
VECTOR clr et0 ;and interrupt DIV AB significant digit
AJMP TIMER0ISR by timer MOV R4,B (max:9999)
;Timer 0 Interrupt mov r3,#0 ;number MOV R5,A RET
service routine 600000 or 927c0 hex CJNE refresh1:
address as Dividend R1,#0H,HIGH_BYTE MOV R0,#1bh ;
ORG 30H mov r2,#09h ; 9 ; CHECK FOR HIGH 1b,1a,19,18, holds
MOV SP,#60H ;set mov r1,#27h ;27 BYTE values for 4 digits
stack pointer mov r0,#0c0h ; c0 SJMP ENDD MOV R4,#8 ; pin
MOV P3,#0FFH ;set mov r5,45h ;divisor HIGH_BYTE: MOV p3.3_ 0 made low
all port 3 bits high to is time for one cycle A,#6 one by one starts
enable inputs mov r4,44h ADD A,R3 wth 18
also call UDIV32 ;divide MOV B,#10 mov r7,#2 ; decimal
MOV P1,#03 ;set port 60000/t DIV AB pt.on 3rd digit from
1 to all zeros expect mov 40h,r0 MOV R3,B left (2 nd
bits 0,1 mov 41h,r1 ADD A,#5 fromright)
MOV mov r1,41h ADD A,R4 PQ2: CALL SEGDISP
TMOD,#01100001B ; mov r2,40h MOV B,#10 dec R0
TIMER 1 - MODE 2 CALL HEX2BCD DIV AB mov a,r4
COUNTER,TIMR-0 mov 50h,#0FFH MOV R4,B rrc a
TO 16 bit timer call refresh ADD A,#2 mov r4,a
BEG: MOV disp: call refresh1 ADD A,R5 jnc pQ2
TH0,#0ffH ;TIMER djnz 50h,disp ; so MOV B,#10 PV3:RET
REG.0 IS SET TO 0, many times for a DIV AB SEGDISP:mov
GIVES 64ms visible time limit MOV R5,B dptr,#ledcode
MOV TL0,#-99 ; jmp beg CJNE MOV A,@R0
timer low reg. is also ;16 Bit Hex to BCD R6,#00D,ADD_IT ANL A,#0FH
so Conversion for 8051 SJMP CONTINUE MOVC A,@A+dptr
setb et0 Microcontroller ADD_IT: ADD A,R6 segcode:MOV R5,A
setb ea ;This routine is for 16 CONTINUE: MOV ORL A,#03H ; WE
mov 44h,#0 bit Hex to BCD R6,A WANT TO USE
mov 45h,#0 conversion; DJNZ PORT 1 BITS 0
acall delay ;Accepts a 16 bit R1,HIGH_BYTE AND 1 FOR INPUT
ajmp lowsig binary number in MOV B, #10D ANLOG
delay: mov r2,#10 R1,R2 and returns 5 MOV A,R6 ; so retain them high
djnz r2,$ ;wait 20 us digit BCD in DIV AB S3: MOV P1,A ;
ret ;R7,R6,R5,R4,R3(upto MOV R6,B SEGMENT_PORT
lowsig: jb p3.6,lowsig 64K ) MOV R7,A MOV A,R5 ;we use
call delay Hex2BCD: ;r1=high ENDD: ret p3.7 for the segment
jnb p3.6,$ byte, r7 most DISP1: ‘a’ of display
setb tr0 ; start timer significant digit, R2 REFRESH:; content RRC A ;so get that
mov c,p3.6 ;high = LSByte of 18 to 1B memory bit D0into carry
begins MOV R3,#00D locations are rrc a
mov p3.5,c MOV R4,#00D output on LEDs mov p3.7,c ;segment
acall delay MOV R5,#00D ; only numbers 0 to 9 ‘a;
jb p3.6, $ MOV R6,#00D and A to F are valid S1: MOV A,R4 ; get
mov c,p3.6 ;low now MOV R7,#00D data in digit code from r4
mov p3.5,c MOV B,#10D these locations 00001000
acall delay MOV A,R2 MOV 18H,r3 ; least cpl a ;11110111
jnb p3.6,$ DIV AB significant digit rrc a ;11111011-1
mov c,p3.6 ;high MOV R3,B ; MOV 19H,r4 ; next
begins again significant digit
mov p3.0,c ; output add a, 44h ;count mov a,r0 ;shift mov 07,a
to drive transsitors time btwn pulses highestbit of X cpl C
for digit lighting mov 44h,a rlc a jnc div_321
rrc a ;11111101-1 mov a,#0 mov r0,a mov r7,7
mov p3.1,c addc a,45h ;add carry mov a,r1 ;shift next mov r6,6
rrc a ;11111110-1 to most sign. byte bit of X mov r5,dph
mov p3.2,c mov 45h,a rlc a mov r4,dpl
rrc a ;1111111-0 yes pop acc mov r1,a div_321: mov a,r0
low makes left most reti mov a,r2 ;shift next rlc a
digit show subroutine UDIV32 bit of X mov r0,a ; shift result
msdigit 32 bit /16 bit to 32 bit rlc a bit into partial
mov p3.3,c quotient and mov r2,a quotient
S5: remainder unsigned mov a,r3 ;shift next mov a,r1
S4: ACALL input r3,r2,r1,r0 = bit of X rlc a
DELAY1 ; let it burn dividend X rlc a mov r1,a
for some time input r5,r4 = divisor mov r3,a mov a,r2
MOV A,#0ffH ; y setb rs0 ;reg. bank 1 rlc a
extinguish the digit output r3-r0 = mov a,r4 ;lowest bit mov r2,a
after that time quotient Q of X/Y of remainder mov a,r3
MOV P3,A ; to r7,r6,r5,r4 rlc a rlc a
prevent shadow =remainder mov r4,a mov r3,a
s6: RET alters acc, flags mov a,r5 ;shift next djnz B,div_lp32
ledcode:DB UDIV32: push 08 bit of rem mov 7,r7
7EH,0CH,0B6H,9EH, ;save reg. bank 1 rlc a mov 6,r6
0CCH,0DAH,0FAH push 09 mov r5,a mov 5,r5
;these are code for push 0AH mov a,r6 ;shift next mov 4,r4
the numbers 0 to 9 push 0BH bit of rem mov 3,r3
and A to F push 0CH rlc a mov 2,r2
DB push 0DH mov r6,a mov 1,r1
0EH,0FEH,0CEH,0E push 0EH mov a,r7 ;shift next mov 0,r0
EH,0F8H,72H,0BCH, push 0Fh bit of rem clr rs0
0F6H, push dpl rlc a pop B
0E2H push dph mov r7,a pop dph
DELAY1:MOV push B mov a,r4 pop dpl
55h,#0ffH ; 1ms setb RS0 ;select clr C pop 0Fh
N: NOP reg.bank 1 subb a,04 pop 0EH
DJNZ 55h,N mov r7,#0 mov dpl,a pop 0Dh
RET mov r6,#0 mov a,r5 pop 0Ch
TIMER0ISR:mov mov r5,#0 subb a,5 pop 0bh
th0,#0ffh mov r4,#0 mov dph,a pop 0ah
mov tl0,#-90 ; in 100 mov B,#32 ;set loop mov a, r6 pop 09
us steps count subb a,#0 pop 08
push acc div_lp32:clr RS0 mov 06,a ret
mov a,#1 ;selet reg.bank 0 mov a,r7 END
clr c clr C subb a,#0
Advantages:
This tachometer requires no physical contact between the
instrument and the device being measured. Hence less wear and