Sie sind auf Seite 1von 10

EXPERIMENT 6: DC Motor Control A.

OBJECTIVES: At the end of the practical session, student should be able: 1. To learn on how to control DC motor using L293 driver. 2. To control DC Servo Motor using PWM. 3. Write c18 program for PIC Microcontrollers to drive a motor clockwise and andticlockwise direction. B. REQUIRED1 EQUIPMENT 1. PC installed software: a. MPLAB IDE integrates with C18 compiler. b. PICkit 2 v2.61 c. PTK40A Trainer Kit. Introduction
DC Motor A DC motor is an electric motor that runs on direct current (DC) electricity. DC motors were used to run machinery, often eliminating the need for a local steam engine or internal combustion engine. DC motors can operate directly from rechargeable batteries, providing the motive power for the first electric vehicles. Today DC motors are still found in applications as small as toys and disk drives, or in large sizes to operate steel rolling mills and paper machines. Modern DC motors are nearly always operated in conjunction with power electronic devices.

How to control DC Motor? To control a DC motor we have a lot of method to control it either by relays, ULN2803, transistor or L293 and so many other methods. Therefore, we understand that to control a DC motor we need to put a driver motor. Different driver give different way to connect. We cannot put DC motor directly to our microcontroller because maximum current should be supply to it is 250mA only. But our DC motor needs more current to turn it on. Since DC motor just has only two terminals, it is positive and negative terminal. And these terminals dont have any polarity on it. It is changeable. Each time we change the polarity at the terminal it will give us different direction. Most servos rotate through 180. However, there are some that could rotate through a full 360 or more. Servos are widely used as the moving joints in robotic arms for their precise angular positioning. They also find applications in radio controlled (RC) toys. For example, in RC cars they are used in the steering mechanisms, and in RC boats to control the rudder.

Introduction to L293D IC

Fig 6.5: L293D IC L293D IC generally comes as a standard 16-pin DIP (dual-in line package). This motor driver IC can simultaneously control two small motors in either direction; forward and reverse with just 4 microcontroller pins (if you do not use enable pins). Some of the features (and drawbacks) of this IC are: 1. Output current capability is limited to 600mA per channel with peak output current limited to 1.2A (non-repetitive). This means you cannot drive bigger motors with this IC. However, most small motors used in hobby robotics should work. If you are unsure whether the IC can handle a particular motor, connect the IC to its circuit and run the motor with your finger on the IC. If it gets really hot, then beware... Also note the words "non-repetitive"; if the current output repeatedly reaches 1.2A, it might destroy the drive transistors. 2. Supply voltage can be as large as 36 Volts. This means you do not have to worry much about voltage regulation. 3. L293D has an enable facility that helps you enable the IC output pins. If an enable pin is set to logic high, then state of the inputs match the state of the outputs. If you pull this low, then the outputs will be turned off regardless of the input states 4. The datasheet also mentions an "over temperature protection" built into the IC. This means an internal sensor senses its internal temperature and stops driving the motors if the temperature crosses a set point 5. Another major feature of L293D is its internal clamp diodes. This flyback diode helps protect the driver IC from voltage spikes that occur when the motor coil is turned on and off (mostly when turned off) 6. The logical low in the IC is set to 1.5V. This means the pin is set high only if the voltage across the pin crosses 1.5V which makes it suitable for use in high frequency applications like switching applications (upto 5KHz) 7. Lastly, this integrated circuit not only drives DC motors, but can also be used to drive relay solenoids, stepper motors etc.

L293D Connections The circuit shown to the right is the most basic implementation of L293D IC. There are 16 pins sticking out of this IC and we have to understand the functionality of each pin before implementing this in a circuit 1. Pin1 and Pin9 are "Enable" pins. They should be connected to +5V for the drivers to function. If they pulled low (GND), then the outputs will be turned off regardless of the input states, stopping the motors. If you have two spare pins in your microcontroller, connect these pins to the microcontroller, or just connect them to regulated positive 5 Volts. Pin4, Pin5, Pin12 and Pin13 are ground pins which should ideally be connected to microcontroller's ground. Pin2, Pin7, Pin10 and Pin15 are logic input pins. These are control pins which should be connected to microcontroller pins. Pin2 and Pin7 control the first motor (left); Pin10 and Pin15 control the second motor(right). Pin3, Pin6, Pin11, and Pin14 are output pins. Tie Pin3 and Pin6 to the first motor, Pin11 and Pin14 to second motor Pin16 powers the IC and it should be connected to regulated +5Volts

2. 3. 4. 5.

6. 7. Pin 8 powers the two motors and should be connected to positive lead of a secondary battery. As per the datasheet, supply voltage can be as high as 36 Volts.

Truth table To control the direction of the motor, suppose you need to control the left motor that is connected to Pin3 (O1) and Pin6 (O2). As mentioned above, we require three pins to control this motor - Pin1 (E1), Pin2 (I1) and Pin7 (I2). Here is the truth table representing the functionality of this motor driver. Pin 1 High High High High Low Pin 2 High Low High Low X Pin 7 Low High High Low X Function Turn Anti-clockwise (Reverse) Turn clockwise (Forward) Stop Stop Stop

High ~+5V, Low ~0V, X=Either high or low (don't care)

In the above truth table you can observe that if Pin1 (E1) is low then the motor stops, irrespective of the states on Pin2 and Pin7. Hence it is essential to hold E1 high for the driver to function, or simply connect enable pins to positive 5 volts. With Pin1 high, if Pin2 is set high and Pin7 is pulled low, then current flows from Pin2 to Pin7 driving the motor in anti-clockwise direction. If the states of Pin2 and Pin7 are flipped, then current flows from Pin7 to Pin2 driving the motor in clockwise direction. The above concept holds true for other side of the IC too. Connect your motor to Pin11 and Pin14; Pin10 and Pin15 are input pins, and Pin9 (E2) enables the driver. PWM Pulse Width Modulation (PWM) is the preferred method to regulate motor speed because no additional heat is generated. In addition, it is energy efficient when compared to linear regulation. The PWM duty cycle is defined as Ton/Toff (%) in one period and the range is 0% - 100% (Figure 1). Controlling the Pulse Width Modulation of the system is an important aspect of this experiment. By controlling the Duty Cycle of the Peltier Junction, the heating or cooling rate of the water can be controlled. Moreover, implementing PWM will help in controlling and reducing the amount of current that is drawn from the battery, hence reducing power consumption.

Figure 1 PWM Square Wave PIC18F4550 has the capability of generating PWM signal with a period of approximately 400 s. However, turning the Peltier Junction on and off this frequently will actually cause the system to draw more current from the battery. Therefore, PWM has to be generated in a way other than the internal capability of the PIC, utilizing the timer of the PIC.

SETUP FOR PWM OPERATION The following steps should be taken when configuring the CCP module for PWM operation: 1. Set the PWM period by writing to the PR2 register. 2. Set the PWM duty cycle by writing to the CCPRxL register and CCPxCON<5:4> bits. 3. Make the CCPx pin an output by clearing the appropriate TRIS bit. 4. Set the TMR2 prescale value, then enable Timer2 by writing to T2CON.

5. Configure the CCPx module for PWM operation.

D. PROCEDURES Practical 6 Control DC Motor clockwise and anti-clockwise direction. 1. Create a new project file for PIC18F4550 with following setting:
i. ii. Set a project name as PRACTICAL6. Add a new file to project, set a source file name as practical6a-dc motor control.c

Show your created project file to your lecturer.

2.

Write a program in your source file based on the condition below then build the program until successful. If any error occurs, fix it.

Your program should be contains header PIC 18F4550 and delay. Configuration settings should be PLLDIV = 5, CPUDIV = OSC1_PLL2, USBDIV = 2, FOSC = HSPLL_HS Define a pin regarding to the schematic below as in PTK40A trainer:

Schematic 6.1: DC Motor circuit Where RB4 and RB5 as output for motor. To control a motor using L293D you have to trigger the Enable pin. Regarding to Schematic Circuit 6.1, an Enable pin at PWM pin. Based on datasheet, PWM in PIC18F4550 is RC2. Make sure to define enable in ypur programming. Without on the enable pin in L293D, motor cannot operate. Function prototype if any. It is recommended for you to make function for clockwise, anticlockwise and stop the motor direction. Main program. a) In your main program, make the motor to run CLOCKWISE direction. To make your motor running, either RB4 or RB5 should be HIGH. The other one is LOW. Show your program that successful Build to lecturer. And download your program to PIC

18F4550 via PTK40A.

Approved by:_______________ Date:______________ OBSERVATION What you can see after download the program to PIC? _____________________________________________________________________________ _____________________________________________________________________________ _____________________________________________________________________________

b) In your main program, make the motor to run ANTI-CLOCKWISE direction. To make your motor running, either RB4 or RB5 should be HIGH. The other one is LOW. And this direction should be different in clockwise direction. Show your program that successful Build to lecturer. And download your program to PIC 18F4550 via PTK40A. Approved by:_______________ Date:______________

OBSERVATION What do you see after downloaded the program to PIC? _____________________________________________________________________________ _____________________________________________________________________________ _____________________________________________________________________________ c) In your main program, make the motor to run CLOCKWISE DIRECTION IN 2S, STOP IN 1 and RUN ANTI-CLOCKWISE IN 2S and STOP IN 1S. Make sure that this program should be looping forever. Show your program that successful Build to lecturer. And download your program to PIC 18F4550 via PTK40A. Approved by:_______________ Date:______________ OBSERVATION What do you see after download the program to PIC? _____________________________________________________________________________ _____________________________________________________________________________ _____________________________________________________________________________

Practical 6b Controlling DC Motor speed using PWM. 1.


Create a new source file set a source file name as practical6b-dcmotor_pwm.c Drag source file practical6a to Other Files. Show your created project file to your lecturer. Write the given program in source file and than build the program until successful. If any error occurs, fix it.

2.

Figure 6.4: Main program for PWM

Show your program that successful Build to lecturer. And download your program to PIC 18F4550 via PTK40A. Approved by:_______________ Date:______________

4.

Download your HEX file to PTK40A trainer via PICkit2 software. Make sure to put a jumper to PWM on the trainer at PIN SELECTOR part.. What do you see after downloading the hex file to the trainer? Explain your observation.

Is there any changes speed for motor? Why this happened? Explain your observation.

Show your output to your lecturer.

Approved by:_______________ Date:______________

5.

Change your program and add line to make a motor turn anti-clockwise. Make your motor turn CLOCKWISE in 3 second with full-speed, then change the speed to 25% in 1second then stop the motor in 0.5s. After that, turn the motor ANTI-CLOCKWISE in 4second with 50% duty cycle. Show successful program to your lecturer and download the hex file to PTK40A trainer. Show your output to your lecturer.

Approved by:_______________ Date:______________

Assignment: Draw a schematic design using Proteus 7. Download your hex file to the circuit. Write a program to control a DC Motor with speed control as Practical 6b(5) condition. Submit this assignment with successful program via email to your lecturer. DISCUSSION Give an example of application that need to control motor speed in our daily life. ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________

__________________________________________________________________________________ CONCLUSION Write the conclusion of this experiment

_____________________________________________________________________________ _____________________________________________________________________________ _____________________________________________________________________________

Das könnte Ihnen auch gefallen