Problems with Microcontroller Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you the Codes for Registered Members of this site only, at free service...Follow Me.

Contact-less tachometer based on PIC16F628A uC

Introduction
Tachometer is a device that gives you the information about the rotational speed of any shaft or disc. It usually measures the speed in revolutions per minute (RPM). Today we are going to make a simple tachometer that could measure the rotation speed of a disk without making any physical contact (that's why it is contact less) with the rotating object. The range of this tachometer is 0 - 9999 RPM and displays the RPM on a multiplexed 4-digit seven-segment display. Of course, we are going to do this project on our usual PIC16F628A development board.

Infrared sensor
Contact-less measurement of RPM will be achieved through an IR sensor. An IR diode will send a beam of infrared towards the rotating disc, and any reflected pulse will be received by a photo diode. The resistance of a photo diode drops drastically when exposed to infrared. An infrared is reflected by a white surface and absorbed by the dark ones. The test disc for this project is shown below. You can see the disc is black and will absorb any infrared falling upon it. A small piece of white paper sticked to the disc as shown is just enough to reflect the infrared back. This will give one reflected IR pulse per rotation which is sensed by the photo diode.

The IR transmitter and receiver circuit is very simple. The IR sensor module built for this purpose is shown below followed by the circuit diagram.





 IR Tx is the control signal to turn On and Off the IR transmission. The PIC16F628A microcontroller will turn the IR diode on for 1 sec, and will count the reflected pulse during this interval through IR Rx Pulse output. During normal condition, the photo diode (IR Rx diode) offers high impedance (tens of K) and so the voltage across it will make the BC557 transistor in the receiver part (right) cut off. The IR Rx Pulse will be at logic low. When there is a reflected pulse, the resistance of the photo diode (IR Rx diode) will drop down and allow BC557 transistor to saturate. This gives a logic high at IR Rx Pulse output. The PIC 16F628A will count the pulses within the 1 sec interval to determine the RPM of the disc. Actually, it takes 3 samples of RPM and gives the average. So, the measuring time is 3 sec. The pulses will be counted by Timer0 counter.

Microcontroller Circuit
I suggest to see the circuit diagram of the development board (PIC16F628A Dev Board) first and then follow the instructions below.
  • Seven segment displays used are common cathode type. The seven segments (a-g) are driven through RB0-RB6 respectively. The 4 common cathodes are controlled by RA0 (units digit) through RA3 (thousands digit).
  • IR Tx is connected to RB7
  • IR Rx Pulse is connected to RA4/T0CKI 

Software
Compile this code with mikroC. I am using 4.0MHz external crystal for clock and MCLR is enabled.


/*
* Project name: Contact less digital tachometer

* Copyright:
(c) Rajendra Bhatt, October, 2010.

* Test configuration:
MCU: PIC16F628A runs @ 4.0 MHz external crystal oscillator
The common cathodes of the four seven segment dispalys are
controlled by RA0, RA1, RA2 and RA3
*/
//-------------- Function to Return mask for common cathode 7-seg. display
unsigned short mask(unsigned short num) {
  switch (num) {
    case 0 : return 0x3F;
    case 1 : return 0x06;
    case 2 : return 0x5B;
    case 3 : return 0x4F;
    case 4 : return 0x66;
    case 5 : return 0x6D;
    case 6 : return 0x7D;
    case 7 : return 0x07;
    case 8 : return 0x7F;
    case 9 : return 0x6F;
  } //case end
}
sbit IR_Tx at RB7_bit;
sbit DD0_Set at RA0_bit;
sbit DD1_Set at RA1_bit;
sbit DD2_Set at RA2_bit;
sbit DD3_Set at RA3_bit;
unsigned short i, DD0, DD1, DD2, DD3;
unsigned int Sample1, Sample2, Sample3, RPM;
void main() {

TRISB = 0b00000000; // Set PORTB direction to be output
TRISA = 0b00110000; // Set PORTA direction to be output
PORTB = 0x00; // Turn OFF LEDs on PORTB
CMCON = 7 ; // Disable comparators
RPM = 0; // Initial Value of Counter
OPTION_REG = 0b00111000; // TOCS=1 for Counter mode, PSA=1 for 1:1
IR_Tx = 0; // Turn OFF IR

do {

 DD0 = RPM%10;
 DD0 = mask(DD0);
 DD1 = (RPM/10)%10;
 DD1 = mask(DD1);
 DD2 = (RPM/100)%10;
 DD2 = mask(DD2);
 DD3 = (RPM/1000);
 DD3 = mask(DD3);

for (i = 0; i<=100; i++) {
PORTB = DD0;
DD0_Set = 1;
DD1_Set = 0;
DD2_Set = 0;
DD3_Set = 0;
delay_ms(5);
PORTB = DD1;
DD0_Set = 0;
DD1_Set = 1;
DD2_Set = 0;
DD3_Set = 0;
delay_ms(5);
PORTB = DD2;
DD0_Set = 0;
DD1_Set = 0;
DD2_Set = 1;
DD3_Set = 0;
delay_ms(5);
PORTB = DD3;
DD0_Set = 0;
DD1_Set = 0;
DD2_Set = 0;
DD3_Set = 1;
delay_ms(5);
}
DD3_Set = 0;

// First Sample
TMR0=0;
IR_Tx = 1;
Delay_ms(1000); // Delay 1 Sec
IR_Tx = 0;
Sample1 = TMR0*60;

// Second Sample
TMR0=0;
IR_Tx = 1;
Delay_ms(1000); // Delay 1 Sec
IR_Tx = 0;
Sample2 = TMR0*60;

// Third Sample
TMR0=0;
IR_Tx = 1;
Delay_ms(1000); // Delay 1 Sec
IR_Tx = 0;
Sample3 = TMR0*60;

RPM = Sample1 + Sample2 + Sample3;
RPM = RPM/3;

} while(1); // endless loop
}

Output
The tachometer is tested for various speeds of the rotating disc. The speed is varied by varying the voltage across the motor driving the disc. I got this motor-disc assembly from my old broken printer.

Setup

Slow speed

Fast speed 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Recent Comments

Popular Projects

Give Support

Give Support
Encourage Me through Comments

Microcontroller Projects

Total Pageviews