Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Driving a dc motor with PIC..

Status
Not open for further replies.

govinho88

New Member
Hello,

Can anyone guide me on how to drive two six volt DC motors using pic18f452? I know that it is possible to drive the motors using L293d. However, it is not clear to me how to control the speed of the motors?:confused: Can anyone please help? :eek:

Thanks in advance!:)
 
Hello,

Can anyone guide me on how to drive two six volt DC motors using pic18f452? I know that it is possible to drive the motors using L293d. However, it is not clear to me how to control the speed of the motors?:confused: Can anyone please help? :eek:

Thanks in advance!:)
hi,:)
Its by using PWM [ pulse width modulation] all thats means is varying the ON time for the period the current flows in the motor.

EDIT:
A simple example would be:
Consider the output pin from the PIC which is connected to the H Bridge, was switched at a 50% duty cycle.
The motor would run slower as its only been powered for 50% of the time.

Some PIC's have a PWM option built in.

Do you follow OK.
 
Last edited:
PWM? Ok. How do I do that? According to the motor driver circuit. I have to connect 4 pins of the L293D to the pic. I dont have a clue on how to modulate the pulse width..can anyone please help?
 
and here are some matching ICs to safely drive the motors without having the PIC sending indian smoke signals.

Use an L297 as translator and driver for the dual full H-bridge (L298) to follow.

Boncuk
 
PWM? Ok. How do I do that? According to the motor driver circuit. I have to connect 4 pins of the L293D to the pic. I dont have a clue on how to modulate the pulse width..can anyone please help?


hi,
Does the 18F452 have a PWM option.?
 
first select a frequency for the PWM. About 200 to 400Hz will be OK. Then write a program to increase and decrease the duty cycle of the output signals. Normal duty cycle for a square wave is 50%, meaning 50% of the cycle is high, and 50% is low.

PWM is nothing else than changing the duty cycle, hence the off cycle too.
20% means 20% of one period is "on" and 80% is "off". The frequency should remain constant.

At low duty cycles the motor speed decreases and at high duty cycles it increases. Advantage of PWM: almost full torque of the motor even at low rpm.


Boncuk
 
PWM? Ok. How do I do that? According to the motor driver circuit. I have to connect 4 pins of the L293D to the pic. I dont have a clue on how to modulate the pulse width..can anyone please help?

hi,
Get the datasheet from www.microchip.com

Extract:
 

Attachments

  • esp02 Aug. 05.gif
    esp02 Aug. 05.gif
    72.3 KB · Views: 230
hi,

I have used pwms before to drive a 24V DC brushless motor . But that motor had specific pin for the CCP1 pin on the PIC.So knew how to connect them. A L293 D however seems a little diffrent ...and i really dont know how to connect the CCP1 pin..any ideas?
 
hi,

I have used pwms before to drive a 24V DC brushless motor . But that motor had specific pin for the CCP1 pin on the PIC.So knew how to connect them. A L293 D however seems a little diffrent ...and i really dont know how to connect the CCP1 pin..any ideas?

hi,
Its a pity you didnt use this post as your first..:)
It would have saved us all some time, I thought you were asking about speed control using PWM, not the connection info.

Do you have the datasheet for the L293, it does show connection application data.?

A quick look at the data, as the D version is dual, you could connect the CCP's to 1A/3A and 2A/4A and use a PIC pin for the Enables.

Does this help.?
 
hi,

Yes I had a look at the datasheet. You are saying that the CCP pins should be connected to 1A/3A and 2A/4A? But this pins are used for motor direction control and not speed control right?

enable 1A 2A Function

H L H turn right
H H L turn left
H L L fast motor stop
H H H fastmotor stop.

This is the table from the datasheet.

So i guess the CCP pins should be connected to the enable pin? Am i right?And I can use and inverter for 2A and use only one PIC pin for each motor..right?

Please correct me if I am wrong. Cheers mate!:)
 
hi,

Yes I had a look at the datasheet. You are saying that the CCP pins should be connected to 1A/3A and 2A/4A? But this pins are used for motor direction control and not speed control right?
The PWM rate on these pins control the motor speed.

enable 1A 2A Function

H L H turn right
H H L turn left
H L L fast motor stop
H H H fastmotor stop.

This is the table from the datasheet.

So i guess the CCP pins should be connected to the enable pin? Am i right?And I can use and inverter for 2A and use only one PIC pin for each motor..right?

Please correct me if I am wrong. Cheers mate!:)

hi,
Consider you drive the 1A/2A pins from the PIC's PWM pulses, the width of the pulses will determine the speed of the motor and the relative pulse widths/period will determine the direction.

I am suggesting the use of the Enable pins on the Bridge to select the motor which gets the PWM signals.

EDIT:
Consider A1 has a 50% duty cycle pulse while A2 is low,, the motor rotates say clockwise at half speed.
Now A1 is low and A2 gets a 50% duty cycle pulse, the motor rotates counter clockwise at half speed.
Use the Enable to select either A1/2 or A3/4
 
Last edited:
hi,

I am suggesting the use of the Enable pins on the Bridge to select the motor which gets the PWM signals.

EDIT:


Select motor? ..err..now I am really confused ...:confused:can you tell me which pins are supposed to be connected where more clearly..pls?:D

These are the pins:

PIC L293D

CCP1 ?
CCP2 ?
? enable


Thanks for the help again.Mate:)
 
hi,

The Enable pins can be of your choosing.
 

Attachments

  • Image1.png
    Image1.png
    60.3 KB · Views: 193
hi,

had a look at the pin connections.Looks a little diffrent. When I used the PLC to drive a 24 V DC brushless..one CCP pin was connected to to one motor. This connection is different as a CCP pin is connected to both motors.I have attached the programme. Take a look. I am still a beginner with PICs ..can u tell me ...how different will be the program for driving a motor with L 293 d, based on your pin connections?

I was thinking of connecting the directional pins on L 293 d to PIC pins and connecting CCP1 to left motor enable and CCP2 to right motor enable. That way,I can use one particular CCP pin for one motor. I think by connecting the CCP pins which generate PWM to the enable I could still control the motor speed. Because, I works like turning the motor on and off very fast which regulates the speed, which depends on the duty cycle...right???:confused:
 

Attachments

  • linef.c
    6.7 KB · Views: 231
hi,
I was thinking of connecting the directional pins on L 293 d to PIC pins and connecting CCP1 to left motor enable and CCP2 to right motor enable. That way,I can use one particular CCP pin for one motor. I think by connecting the CCP pins which generate PWM to the enable I could still control the motor speed. Because, I works like turning the motor on and off very fast which regulates the speed, which depends on the duty cycle...right???:confused:

hi,
I dont use 'C' programming so I cannot help with that program conversion.

The CCP1/2 and Enable sounds like it should work.
I works like turning the motor on and off very fast which regulates the speed, which depends on the duty cycle...right???
Its how long the ON period is, thats Pulse Width Modulation, that is the duty cycle of the pulse going to the motor.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top