motor control 1

25
Motor Control DAE32203 MICROCONTROLLER

Upload: jay-leong

Post on 20-Jan-2015

250 views

Category:

Engineering


5 download

DESCRIPTION

chapter 6, microcontroller (dae32203)

TRANSCRIPT

Page 1: Motor control 1

Motor ControlDAE32203 MICROCONTROLLER

Page 2: Motor control 1

At the end of this topic, students are able to explain:

Hardware Interface ConceptSoftware ControlApplication 1: Brushed DC Motor and Feedback

System.Application 2: Stepper MotorApplication 3: Servo RC Motor

OBJECTIVES:

Page 3: Motor control 1

Motion Control, in electronic terms, means to accurately control the movement of an object based on either speed, distance, load, inertia or a combination of all these factors.

There are numerous types of motion control systems such as:Brushed DC Motor Stepper motorServo motor

Introduction

Page 4: Motor control 1

DC Motor

Page 5: Motor control 1

Stepper Motor

Page 6: Motor control 1

Servo Motor

Page 7: Motor control 1

DC Motor and L293D We can’t drive a DC Motor (depends) directly with a

Microcontroller, as DC Motors requires high current and high voltage than a Microcontroller can handle. Microcontrollers usually operates at +5 or +3.3V supply and it I/O pin can provide only up to 25mA current. Commonly used DC Motors requires 12V supply and 300mA current, moreover interfacing DC Motors directly with Microcontrollers may affect the working of Microcontroller due to the Back EMF of the DC Motor. Thus it is clear that, it not a good idea to interface DC Motor directly with Microcontrollers.

Hardware Interface

Page 8: Motor control 1

The solution to above problems is to use H-bridge circuit.

What to do?

Page 9: Motor control 1

It is a special circuit, by using the 4 switches we can control the direction of DC Motor.

Depending upon our power requirements we can make our own H-bridge using Transistors/MOSFETs as switches.

It is better to use ready made ICs. L293D and L293 are two such ICs.

H-Bridge

Page 10: Motor control 1

These are dual H-bridge motor drivers, ie by using one IC we can control two DC Motors in both clock wise and counter clockwise directions. 

The L293D can provide bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V.

L293 can provide up to 1A at same voltages.  Both ICs are designed to drive inductive loads such as dc

motors, bipolar stepping motors, relays and solenoids as well as other high-current or high-voltage loads in positive-supply applications.

All inputs of these ICs are TTL compatible and output clamp diodes for inductive transient suppression are also provided internally.

These diodes protect our circuit from the Back EMF of DC Motor.

ICs: L293D & L293

Page 11: Motor control 1
Page 12: Motor control 1

In both ICs, drivers are enabled in pairs, with drivers 1 and 2 are enabled by a high input to 1,2EN and drivers 3 and 4 are enabled by a high input to 3,4EN.

When drivers are enabled, their outputs will be active and in phase with their inputs.

When drivers are disabled, their outputs will be off and will be in the high-impedance state.

Page 13: Motor control 1
Page 14: Motor control 1

Interfacing with PIC Microcontroller

Page 15: Motor control 1

Note: VDD and VSS of the pic microcontroller is not shown in the circuit diagram. VDD should be connected to +5V and VSS to GND.

We can drive two DC Motors with one L293D, in this example we are using only the first pair of drivers to drive one DC Motor. First pair of drivers are enabled by connecting EN1 to Logic HIGH. IN1 and IN2 are connected to RB0 and RB1 of PIC Microcontroller respectively which are used to provide control signal to the DC Motor.  

DC Motor is connected to OUT1 and OUT2 of the L293D.

Page 16: Motor control 1

void main() { TRISB = 0; // PORT B as output port PORTB = 1; // Set RB0 to high do { //To turn motor clockwise PORTB.F0 = 1; Delay_ms(2000); //2 seconds delay //To Stop motor PORTB = 0; // or PORTB = 3 Delay_ms(2000); //2 seconds delay //To turn motor anticlockwise direction PORTB.F1 = 1; Delay_ms(2000); //2 seconds delay //To Stop motor PORTB = 0; // or PORTB = 3 (3 = 0b00000011) Delay_ms(2000); // 2 seconds delay }while(1); }

C Code 1:

Page 17: Motor control 1

Function Table:

Page 18: Motor control 1

In our robotics applications we may have to control the speed of the DC Motor.

By using PWM we can easily control the average power delivered to a load and by thus we can easily control the speed of the DC Motor.

Control the speed of a DC Motor using Pulse Width Modulation

Page 19: Motor control 1

There are three reasons for “Resistor is not a good choice for controlling the speed of a DC Motor” The main problem is that the motor is a varying

electrical load so a resistor can’t do this task. It needs more power during start up than in running state. It draws more current also when a mechanical load is applied to motor shaft.

The resistor drops excess energy as heat. Thus it is not good for a battery powered device.

We all know that motor requires more current, so resistors with higher power rating are required to drop excess energy.

Why not use variable resistor?

Page 20: Motor control 1

PWM can be easily generated using the inbuilt CCP module of a PIC Microcontroller.

CCP stands for Capture/Compare/PWM. CCP modules are available with a number

of PIC Microcontrollers. Most of them have more than one CCP

module. MikroC Pro for PIC Microcontroller provides

built in library routines for PWM which makes our task very simple.

Pulse Width Modulation

Page 21: Motor control 1
Page 22: Motor control 1

In this example project DC Motor is interfaced with PIC Microcontroller using L293D Motor Driver.

Two Push Button switches are provided to control the speed of the motor.

Here we are using 12V DC Motor and average DC value delivered to motor can be varied by varying the duty ratio of the PWM.

The average DC Voltage of 0% duty cycle is 0V, 25% duty cycle is 3V, 50% duty cycle is 6V, 75% duty cycle is 9V and for 100% duty cycle 12V.

Example

Page 23: Motor control 1
Page 24: Motor control 1

Two push button switches are connected to 1st and 2nd pins of PORTD which is used to control the duty ratio of the generated PWM.

Pressing the UP switch increases the duty cycle, which increases the motor speed while pressing the DOWN switch decreases the duty cycle, which decreases the motor speed.

Here we use CCP1 module of PIC 16F877A to generate PWM and it is given to the enable pin of L293D.

The direction of rotation of motor can be control using the 1st and 2nd pins of PORTB.

Page 25: Motor control 1

Coding:void main() {

short duty = 0; //initial value for duty TRISD = 0xFF; //PORTD as input TRISC = 0x00; //PORTC as output TRISB = 0x00; //PORTB as output PORTB = 0x02; //Run motor in anti clock wisePWM1_Init(1000); //Initialize PWM1 PWM1_Start(); //start PWM1 PWM1_Set_Duty(duty); //Set current duty for PWM1 while (1) // endless loop {

if (!RD0_bit && duty<250) //if button on RD0 pressed {

Delay_ms(40); duty = duty + 10; //increment current_duty PWM1_Set_Duty(duty); //Change the duty cycle

} if (!RD1_bit && duty >0) //button on RD1 pressed {

Delay_ms(40); duty = duty - 10; //decrement duty PWM1_Set_Duty(duty);

} Delay_ms(10); // slow down change pace a little

} }