Вы находитесь на странице: 1из 4

A three digit contact less digital tachometer using 8051 microcontroller which can be used for measuring the

revolutions/second of a rotating wheel, disc, shaft or anything like that is introduced in this project. The tachometer can measure up to a maximum of 255 rev/sec at an accuracy of 1 rev/sec. What you just need to do is to align the sensor close to the reflective strip (aluminium foil, white paper or some thing like that) glued on the rotating surface and the meter shows the rev/sec on the display. The circuit diagram of the digital tachometer is shown below. The first section of the circuit is the optical pickup based on photo transistor Q4 and red LED D4. Every time the reflective stripe on the rotating object passes in front of the sensor assembly, the reflected light falls on the photo transistor which makes it conduct more and as a result its collector voltage drops towards zero. When viewed through an oscilloscope the collector waveform of the photo transistor Q4 (2N5777) would look like this: Next part is the signal conditioning unit based on the opamp LM324 (IC1). Only one opamp inside the quad LM324 is used here and it is wired as a comparator with reference voltage set at 3.5V (using resistors R16 and R17). The job of this comparator unit is to convert the spiky collector wave form into a neat square pulse train so that it can be applied to the microcontroller. Every time the collector voltage of the photo transistor goes below 3.5V, the output of the comparator goes to negative saturation and every time the collector voltage of the photo transistor goes above 3.5V, the comparator output goes to positive saturation resulting in a waveform like this: From the above two graphs you can see that the negative going edge of the waveform indicates the passage of the reflective patch across the sensor and that means one revolution. If you could some how measure the number of negative going edges occurring in one second, then thats the rev/sec of the rotating object and thats what the microcontroller does here. The 8051 microcontroller here does two jobs and they are: 1) Count the number of negative going pulses available at its T1 pin (pin15). 2) Do necessary mathematics and display the count on the 3 digit 7 segment display. For the counting purpose both the timers of 8051 (Timer0 and Timer1) are used. Timer 1 is configured as an 8 bit auto reload counter for registering the number of incoming zero going pulses and Timer0 is configured as a 16 bit timer which generate the necessary 1 second time span for the Timer1 to count.

Program.
ORG 000H MOV DPTR,#LUT MOV P1,#00000000B MOV P0,#00000000B MAIN: MOV R6,#14D // moves the addres of LUT to DPTR // Sets P1 as an output port // Sets P0 as an output port

SETB P3.5 MOV TMOD,#01100001B as Mode1 timer MOV TL1,#00000000B MOV TH1,#00000000B SETB TR1 BACK: MOV TH0,#00000000B MOV TL0,#00000000B SETB TR0 HERE: JNB TF0,HERE CLR TR0 CLR TF0 DJNZ R6,BACK CLR TR1 CLR TF0 CLR TF1 ACALL DLOOP the count SJMP MAIN DLOOP: MOV R5,#100D BACK1: MOV A,TL1 accumulator MOV B,#100D DIV AB SETB P1.0 ACALL DISPLAY pattern MOV P0,A ACALL DELAY ACALL DELAY MOV A,B MOV B,#10D DIV AB count CLR P1.0 SETB P1.1 ACALL DISPLAY pattern

// Sets Timer1 as Mode2 counter & Timer0 //loads initial value to TL1 //loads initial value to TH1 // starts timer(counter) 1 //loads initial value to TH0 //loads initial value to TL0 //starts timer 0 // checks for Timer 0 roll over // stops Timer0 // clears Timer Flag 0 // // // // stops Timer(counter)1 clears Timer Flag 0 clears Timer Flag 1 Calls subroutine DLOOP for displaying

// jumps back to the main loop // loads the current count to the

// isolates the first digit of the count // converts the 1st digit to 7 seg // puts the pattern to Port 0 // 1mS delay

// isolates the secong digit of the

// converts the 2nd digit to 7 seg

MOV P0,A ACALL DELAY ACALL DELAY MOV A,B accumulator CLR P1.1 SETB P1.2 ACALL DISPLAY pattern MOV P0,A ACALL DELAY ACALL DELAY CLR P1.2 DJNZ R5,BACK1 times RET DELAY: MOV R7,#250D DEL1: DJNZ R7,DEL1 RET DISPLAY: MOVC A,@A+DPTR current value in A CPL A RET LUT: DB 3FH DB 06H DB 5BH DB 4FH DB 66H DB 6DH DB 7DH DB 07H DB 7FH DB 6FH END

// moves the last digit of the count to

// converts the 3rd digit to 7 seg

// repeats the subroutine DLOOP 100

// 1mS delay

// gets 7 seg digit drive pattern for // (See Note 1)

// Look up table (LUT) starts here

Notes.

1) The LUT used here was made for a common cathode seven segment display (used in previous projects) and here we are using a common anode display. The instruction CPL A will just complement the digit drive pattern in accumulator so that it becomes suitable for the common anode display. This is done just because to save my time but not a text book method. The correct way is to make a dedicated LUT for common anode configuration and aviod the extra CPL A instruction. 2) LM324 is a quad opamp and only one opamp inside it is used here. I used LM324 just because that was the only single supply opamp with me at the time. You can use any single supply opamp that matches our supply voltage(5V). You can even use a dual supply opamp (like the popular 741) in single supply mode (+V pin connected to positive supply and -V pin connected to ground) but i wont recommend it unless you have an oscilloscope. Dual supply opamps configured in single supply mode will not give results like a dedicated single supply opamp in the same situation. 3) As we saw earlier the Timer 0 which generates the 1 second time span is configured in Mode 1 (16 bit timer). So the maximum it can count is 2^16 and that is 65536. In 8051 the crystal frequency is divided by 12 using an internal network before applying it as a clock for the timer. That means the timer will increment by one for every 1/12th of the crystal frequency. For an 8051 system clocked with a 12MHz crystal the time taken for one timer increment will be 1S (ie; 1/12MHz). So the maximum time delay that can be obtained using one session of the timer will be 65536S and it is looped 14 times to get the 1 second delay. Go through this article Delay using 8051 timer for a better grasp.

Вам также может понравиться