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.

Using single channel hardware PWM to control H-bridge

Status
Not open for further replies.

ravix

New Member
I am having a terrible time getting efficient motor control using my 18f2585. I have my h-bridge built using 4424's and IRF9Z30 (p-channel) and IRFZ40 (n-channel) mosfets. Now I understand I have four inputs to the h-bridge circuit , but I have only 1 channel of PWM. How do you all recommend driving the circuit? Is there a way to build an "intelligent" h-bridge using smaller transistors or logic chips? I have a lot of spare output pins I can use to adjust the circuit.

Until now I have been using anti-phase locked PWM using a couple of 2n3904's to invert the PWM and feed it into the opposite side of the h-bridge, but when I do this the transistors get HOT. There has to be a better way.

:confused:




Edit: I've been reading about the 16f684, and it seemed to support for h-bridge control using the P1M1 bit in the CCP1CON register. In the 18f chips I have looked at this functionality seems to have been removed. Is there a good reason this feature was removed?
 

Attachments

  • hbridge.gif
    hbridge.gif
    19.5 KB · Views: 1,427
Last edited:
With anti-phase PWM the high portion of the wave drives the motor one way and the low portion the other way. You are always driving the motor at 100%, even when at rest. Wastes power.

You can always do the PWM in software. A single timer interrupt at the 100X the desired PWM frequency can be used to generate any number of PWM outputs with a resolution of 1/100. (any number of steps is possible, 100 is often finer then needed but it allows the PWM on time to be set as a percentage)

In the main program you set a percentage on for each PWM output.
The timer ISR generates a 0-100 cyclic count. At zero all PWMs go high.
At each interrupt the cyclic count is incremented. Each PWM setting is checked and that PWM set to low if the count exceeds the setting.

You did not say what language you were using.

Yesterday I posted a program that used timer0 to multiplex the Junebug LEDs using timer0. With very little work that same framework could be used to do software PWM.

If you would like I could post C18 code to do this.
 
Last edited:
Really the problem is he's only got part of a full H-bridge, you should have an input for PWM and then either one or two inputs for direction control. You do still need two PWM channels for driving two motors though, so something like a 16F876, which is smallish and has two PWM channels is ideal. My PWM 'tutorial' is designed like this, and gives seperate PWM and two direction outputs per channel.

As I understand it, there are now 18 pin PIC's available with two PWM channels?.
 
Thanks nickelflippr, I ordered a couple of those from microchip to use in the future.

However, I only need to control one motor for this project, so it seems I should be able to do this with PWM without using anti-phase locked inputs. Can anyone suggest a mosfet driven h-bridge circuit that accepts some kind of logic input for direction and PWM for power?

I know I can use an intelligent H-bridge IC for this (I have a couple on my bench), but I'd really like to build one so I know how and can tweak it for future projects.

edit: I also want to point out that I am using C to program the pic because I am already very comfortable with it. However, I'd like to continue to use hardware PWM because the rest of the PIC will be handling a significant amount of I/O and calculations.
 
Last edited:
I am surprised that there is no 28 pin 18 series chip with the eccp module. If you can accommodate a 40 pin device (18F4585 being the logical selection) then there is a wide selection. You could even dedicate a 18F1220 to running the bridge.

Mike.
 
Last edited:
Even a 8 pin have it... the smallest one i know is PIC12F615 :eek: Not sure why they don't do 8 pins with USART...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top