You are on page 1of 49

Simple Motor Control in Industrial Automation

PR307 - Advanced Topics in Industrial Automation
By Prasad Manorathna Dept. of Production Engineering University of Peradeniya Sri Lanka

2.) Stepper Motors
‡ Stator is a series of coils rather than permanent magnet. ‡ Rotor is a set of permanent magnets mounted on motor output shaft. ‡ User does commutation: Energize the coils in rotational sequence, rotor swings into alignment, alternate current when rotate T radians. ‡ When the coil is kept energized, ³holding torque´

Stepper Motors
‡ Adv: holding torque, speed and position control without needing encoders / feedback ‡ Angular resolutions of <1deg are available - high ‡ Precision is high. ‡ There are many kind of stepper motors. Unipolar type, Bipolar type, Single-phase type, Multiphase type.


2Ø PM Uni-polar Stepper
‡In the PM type stepper motor, a permanent magnet is used for rotor and coils are put on stator. ‡4 poles & step angle of the rotor is 90 degrees. ‡The turn of the motor is controlled by the electric current which pours into the coils. ‡ The rotor rotational speed and the direction of the turn can be controlled by this control.

Method of running a stepper motor
‡The rotor is stable in the middle of 2 poles of stator. ‡When one side of the stator polarity is changed, the bounce by the magnetism occurs. As a result, the direction of rotor's turn is fixed. ‡Angle can be correctly controlled. ‡Moreover, because the rotor is fixed by the magnetism in the stationary condition as shown in the principle, the stationary power(Stationary torque) is large. It suits the use to make stop at some angle.

Method of running a stepper motor
Clockwise control

³0´ - Grounding

Method of running a stepper motor
Counter-Clockwise control

³0´ - Grounding

Circuit to run a stepper motor


3.) Servo Motors
‡ Operates at low / medium voltages, ex: 5V, 24V ‡ Complete package of
± ± ± ± ± ± DC motor and gear train Limit stops Position sensing of shaft via a potentiometer / encoder Current sensing using CT / Hall sensor Integrated circuit for position control 3 wires:
‡ power, ground, pulse-width control input

‡ Servos to a position: ie. Electric circuit directs motor to rotate to commanded position and keeps it there. If you interfere, circuit reads pot and makes correction with increased current, which increases torque

Controlling a servo motor using a PIC
Servo Motor

Encoder feedback

‡Velocity , Position & Torque control is possible. ‡Precise & accurate

Amplifier PWM Signal PIC 18F4550


1) Velocity
The in-built timer of the microcontroller will be used to count the number of pulses per time period. Count = n


Velocity second


n / t counts per

2) Position
Position is proportional to the number of counts

3) Direction

Direction of rotation of motor can be found through phase difference

DC motor

Common Wide variety Most powerful Easy to interface Must for large robots All in one package Variety, cheap, easy to mount, interface Medium power required


Best For

Large robots Too fast, needs gearbox High current usually More expensive PWM is complex Low weight capability Little speed control Heavy for power High current Bulky Harder to mount Low weight capacity, low power Complex to control Small legged robots


Stepper Precise speed control Great variety Good indoor robot speed Cheap, easy to interface

Line follower


Interfacing the Motor and Microcontroller
‡ Need to control speed and direction via applied voltage and reversing polarity of current feed. ‡ Not enough current in microcontroller to drive the motor so use a separate power source and combine it with control signals from processor using some interface circuitry ‡ This circuit is called an H-bridge
± Direction of motor is determined by current direction ± Logic controls speed by opening and closing switches at different rates to yield an average voltage

H ± bridge concept


H ± bridge operation


Inside H Bridge circuit


H-bridge control using Microcontroller


Microcontroller pins
I/O Port 2 I/O Port 0

I/O Port 1


Speed Control using Pulse Width Modulation (PWM)
PWM applied here


Duty Ratio
‡ V_average is set by the Duty Ratio
Duty Ratio = pulse width / period

‡ Microcontroller output is a Digital Number ‡ Needs Digital to Analog converter


Getting Feedback from the Motor

‡ Incremental Encoder relates motor velocity via a series of pulses ‡ A circular disk (code wheel) mounted on motor shaft with many alternating black and white fractions ‡ An optical sensor reads the transitions ‡ Each fractional rotation of the attached shaft, the encoder changes its output from high to low or vice versa. ‡ Counting the pulses produced in a time interval will yield distance traveled 22

Encoder operation
‡ The reading system is based on the rotation of the radial graduated disk formed by opaque windows and transparent ones alternated. ‡ The system is perpendicularly illuminated by an infrared light source. ‡ The light projects the disk image on the receivers surface which are covered by a grating called collimator having the same disk steps. ‡ The receivers transduce the light variation occurring with the disk shifting, converting them into their corresponding electrical variations. ‡ Electrical signals raised to generate squared pulses without an interference must be electronically processed.

‡ Numbers

Microprocessor Basics

± Binary Numbers
‡ Each digit represents a value raised to a power of 2. ‡ Useful when need to see the value of each bit in a byte. Ex: To set, clear, toggle, or read a bit

± Hexadecimal Numbers
‡ Each character represents a value raised to a power of 16. There are 16 characters, with the letters A through F representing the decimal values 10 through 15. ‡ Each character in a hex number represents 4 bits. This makes hex numbers a convenient, compact way to express 8- or 16-bit numbers. ‡ Common ways of indicating hex values are:
± with a trailing h: 278h ± with a leading 0x: 0x278 ± with a leading $: $278


Microprocessor and Memory

Address Bus ‡ These wires are controlled by the microprocessor to select a particular location in memory for reading or writing. The block diagram shows a memory chip that has 15 address wires. Since each wire has two states (it can be a digital one or a zero), 2 to the 15th power locations are possible. 215 is precisely 32,768 locations; thus, the system is said to have "32K" of memory (1K = 1024 bytes).

Data Bus These wires are used to pass data between the microprocessor and the memory. When data is written to the memory, the microprocessor drives the data bus; when data is read from the memory, memory drives the bus. In our example, there are eight data wires (or bits). These wires can transfer one of 28, or 256, different values per transaction. The data size of 8 bits is commonly referred to as a byte. (a data size of 4 bits is frequently referred to as a nibble.) Read/Write Control Line This single wire is driven by the microprocessor to control the function of the memory. If the read/write control line is asserted as a logical one, i.e., ``true'', then the memory performs a ``read'' operation. If it is asserted as a logic zero, i.e., ``false'' then the memory performs a ``write'' operation. The relationship between logic level and voltage level can vary, depending on the implementation. Memory Enable Control Line This wire, also called the E clock, connects to the enable circuitry of the memory. When the memory is enabled, it performs either a read or write operation as determined by the read/write line.

#include <AT89X51.H> #define L293D_A P2_0 #define L293D_B P2_1 #define L293D_E P2_2

//Positive of motor //Negative of motor //Enable of L293D

C Code for 8051 processor

// Function Prototypes void rotate_f(void); //Forward run funtion void rotate_b(void); //Backward run function void breaks(void); //Motor stop function void delay(void); //Some delay void main(){ //Our main function while(1){ //Infinite loop rotate_f(); //Run forward delay(); //Some delay breaks(); //Stop delay(); //Some delay rotate_b(); //Run Backwards delay(); //Some delay breaks(); //Stop delay(); //Some delay } //Do this infinitely }


void rotate_f(){ L293D_A = 1; L293D_B = 0; L293D_E = 1; } void rotate_b(){ L293D_A = 0; L293D_B = 1; L293D_E = 1; } void breaks(){ L293D_A = 0; L293D_B = 0; L293D_E = 0; }

//Make positive of motor 1 //Make negative of motor 0 //Enable L293D

C code contd.,

//Make positive of motor 0 //Make negative of motor 1 //Enable L293D

//Make positive of motor 0 //Make negative of motor 0 //Disable L293D

void delay(){ //Some delay... unsigned char i,j,k; for(i=0;i<0x20;i++) for(j=0;j<255;j++) for(k=0;k<255;k++);


Limitations of microcontroller control
‡ Slow ‡ Requires a lot of support equipment and software (compilers, assemblers, linkers, function libraries, development platform, programming hardware, etc.). ‡ Program memory is limited and so as the code length ‡ Limited functions ‡ Coordination between microcontrollers need separate hardware and complicated software codes

Interfacing with PC
‡ Parallel Port ‡ Serial Port


Interfacing with PC: Universal Serial Bus (USB)


Interfacing with PC: Industry Standard Accessories (ISA)


Interfacing with PC: Peripheral Component Interface (PCI)


Interfacing with PC
‡ Parallel Port ‡ Serial Port


Interfacing with PC: Universal Serial Bus (USB)


Interfacing with PC: Industry Standard Accessories (ISA)


Interfacing with PC: Peripheral Component Interface (PCI)


Parallel Port
‡ port is a set of digital (logic 0 and 1) signal lines that the microprocessor uses to exchange data with other components as printers, modems, keyboards, displays, etc, except memory ‡ Parallel port transfers multiple bits at once ‡ Original PC¶s parallel port had
± 8 outputs ± 5 inputs ± 4 bidirectional lines

‡ In newer PC versions the 8 outputs may also be programmed to work as inputs ‡ Types:
SPP: Standard Parallel Port PS/2-type: Simple Bidirectional EPP: Enhanced Parallel Port ECP: Extended Capabilities Port

‡ Can output eight bits at once to a peripheral ‡ Doesn¶t have a eight bits for input. Uses Nibble mode to input 4 bits at a time ‡ Nibble mode is slow, but has become popular as a way to use the parallel port for input to PC

‡ The bidirectional port enables a peripheral to transfer eight bits at once to a PC ‡ Doesn¶t support the EPP or ECP modes




‡ Same as EPP together ‡ Data lines are with additional features bidirectional as ‡ Can read or write a ± Have buffers and support byte of data in one for DMA (direct memory bus cycle including access) transfers and data handshaking, compression. compared to four ± Useful for printers, cycles for an SPP or scanners, and other PS/2 peripherals that transfer ‡ Can switch large blocks of data directions of data transfer quickly ‡ Can also emulate either SPP PS/2

Pin assignment


Parallel Port Signals, arranged by pin number


System Resources
‡ Every port uses a range of addresses, though the number and location of addresses varies. ‡ Many ports have an assigned IRQ (interrupt request) level. ‡ The resources assigned to a port can¶t conflict with those used by other system components, including other parallel ports



Data register

Status register

Control register

‡ Standard parallel port uses three contiguous addresses, usually in one of these ranges:


‡ Peripheral device may use an interrupt to announce: ± ready to receive a byte ± it has a byte to send ‡ To use interrupts, a parallel port must have an assigned interrupt-request level (IRQ). ‡ If you select no IRQ level for a port, the port will still work in most cases, though sometimes not as efficiently, and you can use the IRQ level for something else


Finding Existing Ports
‡ Operating Systems include utilities for finding existing ports and examining other system resources. ‡ In WindowsTM, click on
± ± ± ± Control Panel, System, Devices, Ports,

to see the assigned address and IRQ level .


Analog-to-digital converter
‡ An analog-to-digital converter (ADC, A/D or A to D) is a device which converts continuous signals to discrete digital numbers. ‡ The reverse operation is performed by a digitalto-analog converter (DAC).


Analog-to-digital converter