PDA

View Full Version : PWM using a 16F873



Gixxer
- 31st January 2008, 21:26
Hello,

I'm trying to drive two small 6v motors and want to be able to control both speed and direction independently. Currently I am running a dual H-bridge (L293) with the '873, but that only gives me direction control using four i/o lines (2 lines per motor,for/rev). Is it possible to drive these same control inputs to the L293 using PWM from the PIC ?

thanks,

John.

Gixxer
- 1st February 2008, 00:48
hmmmm......

Does anybody have any experience with this type of motor control ? Any info would be appreciated....

John.

Gixxer
- 1st February 2008, 02:56
Hi again(to myself),

I must have mistaken this forum for a place where answers are pleantifull OR this is mostly a programming based group. BUT for anyone who is interested in what I was trying to accomplish, it is possible to drive the L293 enable pins with PWM from a pic. I kinda hoped that some guru could have helped me regarding PWM frequencies and possible code EXAMPLES as I'm definately not the first to do this.
As they say, it's easy if ya know how !

John.

Darrel Taylor
- 1st February 2008, 03:08
Don't forget that you are asking Hardware related questions on a forum dedicated to a Programming Language.

I'm sure there are people here that can answer the question, but many of them only check the forum every few days or weeks.

It's only been 5+ hours since the first post.

Me, I'm a software guy. Can't help.

skimask
- 1st February 2008, 03:18
I'm sure there are people here that can answer the question, but many of them only check the forum every few days or weeks.
Not to mention that there are a lot of time zones and not everybody is on your sleep schedule.

But like DT said, there's a lot of people around who are good with PWM'ing 2 motors bidirectionally, which without some sort of method of counting rev's or speed, good luck trying to get the thing to run straight.

The big thing I can suggest... Get yourself 4 LEDs, wire them up in 2 pairs of opposing parallel before getting PIC driven MOSFETs connected to motors.
That way you can play with PWM (no matter what your method, software, hardware, off-chip driven, etc), watching LED brightness, and the opposing parallel pairs of LEDs will give you a visual indication of both direction and relative speed, with practically no chance of blowing up a PIC.

Dave
- 1st February 2008, 11:45
Gixxer, I built this circuit some years ago. There are 2 such circuits. Each has a pwm channel connected to the "F" terminal and a couple of direction bits associated with it. The reason for 2 direction bits? They set the output to either battery or to ground state. for braking. This circuit is used with a 16F876 which has 2 pwm circuits available. The completed circuit runs 2 motors, forward and reverse with 10 bit pwm values.

Dave Purola,
N8NTA

paul borgmeier
- 1st February 2008, 12:02
Is it possible to drive these same control inputs to the L293 using PWM from the PIC ?


John,

I do this all the time with the L293 - what you want to do is exactly what you are doing for direction control except use PWM on the enable lines (rather than leaving them on).

Is that enough to get you going? (I expect to hear back from you in the next 10 minutes:) - we have a schedule to keep ... its 5AM here)

Gixxer
- 2nd February 2008, 01:58
hahaha,

That actually cracked me up Paul. Thanks alot guys for the replies. Yesterday I was at a point in my project that you have all been I'm sure-STUCK. So you say to drive the enable pins with the PWM and continue to use my existing four control lines for direction? In other words six i/o are required from the pic. Seems like alot of io to use on motor control only, but I should be able to manage. I'm building a small tracked robot with half duplex rf tranceivers for telemetry and radio control-all digital R/C of course. It's such an involved project and I've had to break it up into sections and learn how to build it. Slowly but surely!
So does anyone have a small snippet PWM code that may get me going ?

thanks,

John.

paul borgmeier
- 2nd February 2008, 02:48
http://www.melabs.com/resources/samples/pbp/hardpwm.bas

Gixxer
- 2nd February 2008, 03:05
Thanks again Paul, that appears to be exactly what I need to get started on this. I'll give it a try when I get home tomorrow and let ya know.

John.