Sunteți pe pagina 1din 4

Lab Notes 6

PIC16F877: DC Motor

Mechatronics Lecture Notes by Dr. Can U. Dogruer

L6. PIC16F877:DC MOTOR


Objectives 1. 2. Interface DC Motor Learn how to use PWM library to drive a DC Motor

PART LIST NO 1 2 3 6 7 8 9 0 1 2 3 4 5 6 7 PART NAME PIC16F877 / PIC16F877A Push Button 10K Resistor Potentiometer MAX232 1-micro Farad Polarized Capacitor RS-232 Connector RS-232 Cable 20 MHz Crystal 22-picoFarad Capacitor Copper Wire USB PIC Programmer [Hardware] PIC Downloader Program [Bootloader; Software] DC Motor L293D QUANTITY 1 1 9 1 1 5 1 1 1 2 2 meter 1 1 1 1

NOTE: Study PWM library of mikroC and read the relevant pages of PIC16877A about CCP (Compare/Capture/PWM) page:63-70 Chapter 8. Read also the mikroC web book whose address is given in the web page of the lecture L6.1 EXPERIMENT V: DC Motor Interfacing In this experiment you will interface a DC motor to a PIC microcontroller. You will control the sped and rotation direction of the DC motor. For this purpose you will use L293D IC and PWM library of mikroC. PWM stands for Pulse Width Modulation. By using this library you can control the HIGH time ratio of a typical square wave signal. Hence the average voltage may be changed by adjusting the HIGH/LOW time period ratio o the signal. Thus you can control the speed of DC motor. L6.DC MOTOR INTERFACING: Speed + Direction 1. 2. Construct the circuit shown in Figure 1. Write a C code that controls the speed of DC motor a. Start PWM library b. Set PORTC as OUTPUT i. TRISC =0x00; ii. PORTC =0x00; iii. PWM1_Ini(100000); iv. PWM2_Init(100000); c. Start PWM i. PWM1_Start()

Hacettepe University / Mechanical Engineering Department Automotive Engineering Program

L6-1

Lab Notes 6
PIC16F877: DC Motor
d.

Mechatronics Lecture Notes by Dr. Can U. Dogruer

e.

f.

g.

ii. PWM2_Start() Change Duty cycle in order to change the speed i. PWM1_Set_Duty(Mspeed) ii. Mspeed is between 0 and 255. 0 stalls 255 maximum speed Note that in order to rotate the DC motor CW i. PWM1_Change_Duty(Mspeed) ii. PWM1_Set_Duty(0) iii. Because to rotate CW, pin 2 of L293D must be LOW and pin 7 must be HIGH Note that in order to rotate the DC motor CCW i. PWM1_Change_Duty(0) ii. PWM2_Change_Duty(Mspeed) iii. Because to rotate CCW, pin 7 of L293D must be LOW and pin 2 must be HIGH Stop PWM i. PWM1_Stop(); ii. PWM2_Stop();

CONNECTIONS:
Connect the cables shown in circuit diagram and connect pin 5-6-13-14 of L293D to ground. Connect pin 8 of L293D to 5V note that this 5V and ground must be separated from PIC microcontroller power supply, use a separate channel for these pins. Connect pin 16 of L293D to 5V this must be connected to PIC microcontroller 5V line because this is a logic and use logic 5V. DO NOT FORGET TO INCLUDE PWM library of mikroC to code.

Hacettepe University / Mechanical Engineering Department Automotive Engineering Program

L6-2

Lab Notes 6
PIC16F877: DC Motor

Mechatronics Lecture Notes by Dr. Can U. Dogruer

SAMPLE CODE
char Mspeed; void Initial() { TRISC =0x00; PORTC =0x00; PWM1_Init(100000); PWM2_Init(100000); Mspeed =0; }

void main() { Mspeed=128; PWM1_Start(); PWM2_Start();

PWM1_Stop(); Delay_ms(100); PWM2_Start(); PWM2_Set_Duty(Mspeed); do { } while(1);

} void interrupt() { }

Hacettepe University / Mechanical Engineering Department Automotive Engineering Program

L6-3

Lab Notes 6
PIC16F877: DC Motor

Mechatronics Lecture Notes by Dr. Can U. Dogruer

Hacettepe University / Mechanical Engineering Department Automotive Engineering Program

L6-4

S-ar putea să vă placă și