Rotatory Shaft Encoder Speed-o-Meter

 Synopsis of 8051 Microcontroller Project For Speed Measurement:

The speedo-Meter will measure the speed of motor attached to an industrial production machine is being developed in this microcontroller experimental project. The application of this speed measurement project is comprised of a variety of field like it can be used in the home appliance to the production industrial machinery. In this 8051 Microcontroller project we will be doing to design a digital meter used as measuring device to be develop for measuring instantaneous rotational speed of the encoded shaft. The basic technique behind the measurement of speed to use a suitable incremental optical encoding-based algorithm. The sensor used to detect the motion of the shaft attached with the motor will be based on a custom-built optical encoder consisting of transmitter and receiver. Accurate real-time calculations for speed measurement will be performed in an Atmel AT89C51 microcontroller. The output will be shown on LED seven segment display in the form of Rotation Per Second (RPMs). The system’s functionality and implementation details are presented in the sections below.

Subject Descriptors:

  • Speedometers
  • Optical Encoding
  • Microcontrollers
  • Optical Encoder

Implementation of Software and Hardware for the development of speed measuring device:

Hardware will be based on the Atmel AT89C51 microcontroller, and the software will be written in Keil C51 Compiler and Micro vision IDE.

Introduction of the Final Year Degree Project based on 8051 MCU:

 The Speed measuring devices called speedometers of various types are often witnessed in automobiles, aircraft, traffic highways and industries - measuring and displaying linear and/or rotational speeds. These devices are basically classified and available as analog and digital meters (with respect to their output) and typically use mechanical, optical and acoustic means for their construction thus providing different degrees of accuracy. However, the basic objective behind using a speedometer is to control speed. Optical Encoding is a scheme that is commonly employed in a number of currently used digital speedometers, mostly for measuring rotational speed. This project is a prototype speed measuring system based on the technique afore-mentioned. Its function is to measure and display the rotational speed of a shaft. It provides a mechanical interface to input the rotary motion from external sources. The measured speed is displayed in the form of digits and is updated frequently following any change in the input motion. 

Scope of Project:

In current configuration, the system can measure only the rotational speed up to a few thousand RPMs (revolutions per minute) with a fine degree of accuracy using the number of microseconds elapsed as the time interval.

 Objectives

  •  To make it a lower-cost system as compared to other available such systems.
  • To provide a higher degree of accuracy than its counterparts.

 Significance and Common Applications

Optical Encoding base rotary speedometers can commonly be used as feedback devices for motor controllers.

  • They can also be utilized:
  • To provide visual feedback.
  • To increase compliance with traffic laws (e.g. on highways to check vehicle speeds).
  • For conducting speed studies.

Salient features Of Speed Measurement System

 Use of Optical Encoding:

Besides having low cost, fine accuracy and almost no parts to break, the Optical Encoding scheme is quite simple, flexible and easy to implement. Moreover, as the role of embedded digital systems and computers is getting more and more significant with time in every technological domain, digital interfacing capability has also become a mandatory feature in modern systems such as data acquisition systems, control systems etc. Using Optical Encoding scheme is the simplest way to incorporate such features into an application. 

 This project utilizes the same scheme to achieve the following goals.

  1. Lower Cost – Only a transmitter (infrared LED) and a receiver (phototransistor) are needed for the basic operation. Also there’s no wear and tear of components which ensures that no re-calibrations etc. are required.
  2. Better accuracy – Due to its fast response, less number of components required, discrete signal operation (digital output), no maintenance or calibration requirements, the Optical Encoding makes it easier to provide very accurate result over a high range of operation. 
  3. No Analog to Digital Conversion: Because of no analog to digital conversion involved, the system unsurprisingly has a number of significant plus points. 
  4. Finer accuracy – Analog to digital converters provide unique output value up to a certain number limited by the umber of output bits, which is a hardware dependency. E.g. a 12 bit ADC can provide only 2^12 (=4096) different speed values. On the other hand, this Digital Speedometer system performs its calculations using 32-bit software arithmetic operations, based on the revolutions per number of microseconds elapsed, which is far more accurate than a system using ADC. 
  5. Smaller time delays – The use of extra hardware components/stages introduces extra time delays, which is not desirable in any real-time application. Less hardware – Using lesser hardware than software is becoming a trend because it results in more flexibility, lesser design and debugging time hence more simplified overall design.

 Custom-Built Encoder Device:

 Instead of using commercially available Optical Rotary Encoders, there is a custom-made (built-from-the-scratch) device used in this project. The idea was simply to reduce the cost because their price in market ranges from $50, $70 to around $300.

 Use of 8051 based microcontroller device:

 The advantages in using a microcontroller are:

It allows one to move the whole logic and functionality in software, which is easily modifiable.  A number of development and debugging tools are available for this series of devices. Hence, the overall development time is reduced and a more reliable product results in.

 Architecture of the Speed-o-Meter

The speed measuring system based on microcontroller 8051 family has been divided in to following three subsystems:

  • Input scanning subsystem
  • Speed Measurement and calculation Subsystem
  • Display Control Subsystem

Detailed explanation of each of the above sub-system follows in the next section. The high-level architecture of the system is represented in Figure No. 1, below.

 

Block Diagram Of Speed Measurement System
Block Diagram Of Speed Measurement System


Functionality and Implementation

This section explains the function of each of the subsystem in detail with its implementation and related issues step wise.  The Atmel AT89C51 microcontroller (Intel 8051 derivative) is used in this project to implement the speed measurement and display control due to its low cost, simple architecture, re-programmability and good development tools available.

Input Subsystem (ENCODER):

Converts the mechanical rotary motion into digital electronic pulses, which are input to the speed measurement subsystem. The frequency of these pulses is directly proportional to rotational speed of the external source. The shaft encoder being sued in this project is a sensor associated with the detection of mechanical motion. 

Encoder with optical sensor
Encoder with optical sensor
The encoders are used to translate the physical or mechanical motion such as speed, direction, and shaft angle into suitable electrical signals in the form of pulses. These pulses are detected and interpreted in rest of the circuitry to acquire the final results. The incremental encoder is an encoder to convert the mechanical motion to electrical signal which is made up of two main parts namely the disk having some dots or holes and the optical sensor. It is normal practice that the disk of an incremental encoder is patterned with lines on disk. The quantality of lines in a specific pattern on the disk is a function of the encoder resolution.it means that the encoder resolution will be higher if the lines are more closed to each other and the quantity of lines is higher per unit the length. The incremental encoders produce outputs related to the speed, angle and direction of the shaft. Similarly, the rotary encoder sensor also uses the light to detect the speed, angle and direction of a rotary shaft attached to some moving part of a machine. the linear encoder observes the linear strip to provide the required information for linear motion like speed, direction of rotation, revolution per unit time etc. On the other hand, the Optical encoders are built to use light signal to detect position, therefore theses are inherently free from close contact wear. Most optical encoders are transmissive type. The collimated light consisting of parallel rays passes through the disk and detected on the other side of disk. The pattern is detected using a sensor and which converts the light beam signal into TTL digital outputs. Physically, the input subsystem is an assembly (shown in Fig. 2) consisting of: 

  • A Metal Encoder Disk having a shaft for external mechanical interface and 4 equidistant holes along its circumference.
  • An Infrared Emitting Diode [Device ID: F5E2]
  • A Hermetic Silicon Phototransistor [Device ID: L14G3]

As the disk rotates, the light from the diode to the transistor is blocked and passed continuously. Due to this, the output of the circuit is low when the light passes through the disk hole and is high when the light is blocked. This produces digital pulses (0V Low, +5V High), which are fed directly into INT0 pin of the microcontroller. The advantage of using optical encoder becomes evident here, as there’s no voltage level conversion circuitry required. 

Speed Measurement Subsystem:

It’s the software existing in the microcontroller, which calculates the instantaneous rotational speed in real-time. The calculated speed depends upon the frequency of pulses received at INT0 pin. The speed is calculated in following manner. On each high (+5V) to low (0V) transition detected at INT0 pin by the microcontroller, an event (interrupt) is triggered in the software. The speed is calculated at this event using [Speed = Distance/Time] formula. The distance is a fixed known parameter (1/4 rotation for 4 holes in the disk) and the time taken is provided by the internal timer of microcontroller in microseconds. The interrupts may occur at higher rates up to 40, 50 per second with speed values being calculated at the same rate. As these real-time values cannot be displayed at the same rate, some display control mechanism is necessary which updates the speed display at a rate suitable for human eye. There is a possibility that the wheel is moving very slowly and no event is triggered up to a particular time. A maximum interrupt waiting time has been adjusted after which the speed is taken as zero. Being in software, this parameter can be easily set to any practically desirable value (e.g. 1 sec to 30 sec).

 Selection of an optimal Speed Measurement Technique:

  •  Two alternate approaches were available for calculation of speed.
  • Count the number of interrupts per unit time.
  • Calculate the time elapsed between two successive interrupts.

The second approach is far more accurate than the other because of its resolution in microseconds.

Design Parameters:

MAX RPM

Maximum No. Of Interrupts per second

 

For 1 Hole

4 holes

8 holes

20,000

333

1333

2667

10,000

167

667

1334

MIN RPM

Maximum Wait Time (sec)

 

For 1 Hole

4 holes

8 holes

10

6

1.5

.75

1

60

15

7.5

 Display Control Subsystem:

Displays the instantaneous speed in RPMs (revolutions per minute). Updates the display at a rate suitable for human eye. Typically, a 1 sec update time is desirable and practical; i.e. a speed value is shown on the display for a minimum of 1 sec. As the speed is measured at the interrupt arrival rate, a number of speeds values may have been calculated within display update time. In this case, the most recent value is displayed as it best fulfils the definition of instantaneous speed.

Seven-segment display:

In current system configuration, a common anode seven-segment digit display is used for output. In order to use least possible hardware, there’s a slight trick involved here. The seven lines (N’s of diode) of each LED are connected to the 7 pins of port P1 of the microcontroller. As the 7 lines of each LED are common, each digit is updated one by one very frequently, which makes the display look stable. A separate transistor for each digit is used for switching.

Circuit Diagram of Speed Meter:

 

Circuit Diagram of Speed Meter using Microcontroller 8051
Circuit Diagram of Speed Meter using Microcontroller 8051

Work Breakdown Structure (WBS)

The work Breakdown structure of this project may involve the sub-tasks like, Formulation of Problem Statement Initial Study Objectives Definition Selection of the Optimal Solution Subsystems Design Circuit Design Selected Optical Technique Understanding the AT89C51 Architecture and Assembly Language Learning C51 Software Implementation Simulation and Testing Circuit Implementation and Testing Hardware and Software Integration Testing and Verification Implemented on Vero Board Bringing into a Demonstrable Form.

Summary:

The Digital Speedometer is an incremental optical encoder based real-time rotational speed measuring system having low cost, higher accuracy and practical operating ranges. Using this system, one can observe accurate instantaneous rotational speed of an object.

Limitations:

  •  Currently only rotational speed is measured.
  • Minimum measurable speed is limited by the maximum wait time. The wait time is in the software can be adjusted up to an adequate value.
  • Maximum measurable speed is limited by the oscillator speed (in microcontroller) and the number of holes in the encoder disk.

Future Enhancements:

  • Linear Speed, Velocity, Acceleration can be displayed on multiple display devices.
  • Direction of rotation can be detected by using the quadrature technique with two diode/transistor pairs.

Reference Microcontroller Books consulted during the development of speed measuring system

Title: “The 8051 microcontroller”, 3rd edition

Author: I. Scott. Mackenzie

Software coding:

The software of the microcontroller project based on MCU At89s51 is written in C-Language and compiled on Keil C51 compiler. The code listing is presented as below:

//The Software of Speed Meter
// To include the library file related to Microcontroller
//At89S51
#include <AT89X51.H>
// Initialization and declaration of some variable to be 
// used in rest of program
int digit1=0,digit2=0,digit3=0;
// An array is taken to stort the codes
// for the seven segment display
int seven_segment[]={64, 124, 18,24,44,9,1,92,0,8};

#define MAX_WAIT_TIME_uSECS 2000000 

#define DISPLAY_UPDATE_TIME_uSECS 2000000 

#define MAX_TIMER_DELAY_uSECS 65536

#define TIMER_DELAY_uSECS 50000

#define TIMER_DELAY_VALUE  (MAX_TIMER_DELAY_uSECS - TIMER_DELAY_uSECS)

#define TIMER_INIT_VALUE TIMER_DELAY_VALUE

#define MAX_OVERFLOWS (20) 

#define UPDATE_OVERFLOWS (21)



void ext0isr();

void timer0isr();

void startTimer0();

void my_delay(int usec, int iterations);

void mydivide();	// tmplong / elpsedTime //



int maxwait_timerOverflowCount=0;

int update_timerOverflowCount=0;

int temp=0;

int rpm=0;

long elapsedTime=15000000+1;

long tmpq;

int quotient;



void main()
{		

	EX0=1;			//Enable external INT0
	IT0=1;			//External 0 edge triggered		

	TMOD = 0x11;	//Timer 0 16-bit mode	

	ET0=1;			//Enable Timer0 interrupts

	startTimer0();

	EA=1;			//Enable all interrupts

	while(1)
	{					
			P3_3=0;
			P1=seven_segment[digit1];
			P3_5=1;
			my_delay(100,1);
			P3_5=0;
			P1=seven_segment[digit2];
			P3_4=1;
			my_delay(100,1);
			P3_4=0;
			P1=seven_segment[digit3];
			P3_3=1;
			my_delay(100,1);		
	}
}


void int0_ISR() interrupt 0
{
	TR0 = 0;	//Stop Timer; to read value//
	
	// Read current elapsed microseconds //
	elapsedTime = TH0;
	elapsedTime <<= 8;
	elapsedTime |= TL0;

	elapsedTime -= TIMER_INIT_VALUE;

	// Add microsecond due to overflows occured//
	elapsedTime += 
	maxwait_timerOverflowCount * TIMER_DELAY_uSECS;

	//Calculated factor. Dirty !!//
	elapsedTime += 25310;

	// Now we have the complete elapsed time //

//	mydivide();	
//Divides the distance by elapsedTime. Only calculates the quotient//

//	rpm = quotient;

	
	
	// Calculate RPM ; Multiply numerator by 1E6 to make it seconds //
	//rpm = 60 * ROT_PER_INT * 1.0E6 / elapsedTime;
//	rpm = 15000000 / elapsedTime;	
			
	// Reset time //
	maxwait_timerOverflowCount = 0;

	startTimer0();

}	


void timer0_ISR() interrupt 1
{		
	TR0 = 0;
		
	++maxwait_timerOverflowCount;
	++update_timerOverflowCount;

	// If Maximum-wait-time has elapsed; Set RPM to zero //
	if(maxwait_timerOverflowCount == MAX_OVERFLOWS)
	{
		maxwait_timerOverflowCount=0;
		elapsedTime=15000000+1;
	}


	// If update time has arrived //
	if(update_timerOverflowCount == UPDATE_OVERFLOWS)
	{		
		mydivide();	
//Divides the distance by elapsedTime. Only calculates the quotient//
	
		temp = quotient;	// RPM is in quotient //
		
		digit1 = temp%10;
		temp/=10;
		digit2 = temp%10;
		temp/=10;
		digit3=temp%10;

		update_timerOverflowCount = 0;
	}

	
	

	startTimer0();

}


void startTimer0()
{
	TR0 = 0; // Stop Timer //

	//Load high byte for timer delay into TH0 //
	temp = (TIMER_DELAY_VALUE & 0xFF00)>>8 ;
	TH0 = temp;

	//Load low byte for timer delay into TL0 //
	temp = (TIMER_DELAY_VALUE & 0x00FF);
	TL0 = temp;

	TR0 = 1;		

}



void my_delay(int usec, int iterations)
{
int temp;
usec=-usec;
	while(iterations>0)
	{
		temp=usec & 0xFF00;
		temp>>=8;
		TH1=temp;
		temp=usec & 0x00FF;
		TL1=temp;
		TR1=1;	
		while(!TF1);
		TR1=0;
		TF1=0;
		iterations--;
	}
}


void mydivide()
{
	quotient = 0;

	tmpq = 15000000;

	while(tmpq > elapsedTime)
	{	
		tmpq -= elapsedTime;
		quotient++;
	}
	//tmpq has the remainder//	
}


No comments:

Post a Comment

Please ask if you have any question regarding the programming of MCU, or have any problem in development of your electronics project. microcontroller51.blogspot.com

Popular Post (All Time)