PWM Problems

Thread Starter

Dalaran

Joined Dec 3, 2009
168
I am using the PWM of the PIC16F886 to control the "enable" pin of an H-Bridge. By doing this I hope to achieve speed control of the DC motor attached. I am using 2 PIC pins to control the motor direction and the PWM on the enable.

Scoping the CCP1 pin of the PIC PWM output looks exactly as expected. Having a frequency generator simulating the PIC PWM also works as expected giving speed control to the motor.

However when I connect the PIC PWM to the enable pin I have weird things happening. Another pin is simply connected to an LED/resistor to light up when the motor is on, this LED blinks violently when the PWM output is attached to the h-bridge. Oscilloscope results shows that the output port pins of the PIC all remain low ~90-95% of the time and then spike high (if they should be in the high state or remain low if they should be low). The power to the PIC however is quite stable. When PWM is set to 100% duty cycle and acts as a logic high everything works as expected.

Anyone with any ideas what is going on here? This has had the best of me for 48 hours now. All help appreciated thanks.

edit: Further confused, when the motor supply of the h-bridge is connected to a different PSU the PWM output of the pic works. When connected to the un-regulated supply (~6.5V dropped to 5V for the PIC/H-bridge I/O) using the same PSU I get the above action...
 
Last edited:

Thread Starter

Dalaran

Joined Dec 3, 2009
168
Attached is the schematic. I forgot to add in the unpolarized 100nF cap across the motor as well.

I am using the L293DNE H-bridge.

Pin 1 is the enable pin, pins 2 and 7 are to control direction, 4 and 5 ground and 3 and 6 drive the motor. pin 8 is the motor supply and pin 16 is the I/O supply of the h-bridge.

The pots on the other side are going through the ADC and determine which way the motor is to turn. Everything with these performs as expected.

Thanks.

edit: Sorry schematic was put together quickly, there is also the caps as recommended by the datasheet across the voltage regulator, 330nF on the input and 100nF on the output.

 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
Your result with separate supplies suggests that you have inadequate decoupling of the L293 from the supply when it is common. Try more or larger decoupling capacitorsnear the power pins of both the PIC and particularly the L293.

John
 

Thread Starter

Dalaran

Joined Dec 3, 2009
168
Thanks for the reply. I tried 1, 10 and even 100uF caps on the power pins of the h-bridge and PIC but it had no effect.

All opinions are welcome. Thanks.
 

jpanhalt

Joined Jan 18, 2008
11,087
Your motor is probably sagging the supply to the VR. What do you see with an oscilloscope at #6 shown in your schematic? It seems that when the motor is powered off the same supply as the logic/drivers, you get crazy results. When it is not, everything works as expected.

Can you use a separate supply for the motor? If not, how about some large capacitors on the input to the VR?

John
 

Thread Starter

Dalaran

Joined Dec 3, 2009
168
Thanks again. I am not able to scope out that spot until later today. I have used a separate supply for the motor (pin 8 of L293) and everything behaves fine. I will try adding some large capacitors to the input of the regulator. 100uF large enough?

Thanks.
 

jpanhalt

Joined Jan 18, 2008
11,087
It's low voltage. I would try whatever works. Something more than 1000 uFd is probably not out of the question for that filter and would not be too big physically.
 

THE_RB

Joined Feb 11, 2008
5,438
What on earth are you making that you would think it was wise to run the motor from the same +5v as the PIC itself?

Why not run a separate 5v reg for the motor and hbridge (assuming it MUST have regulated 5v)?

Or at the very least put a big cap on the +5v power pin of the hbridge IC and decouple it from the +5v of the PIC with a series resistor.

But using the PIC +5v rail as motor power is just nuts. :)
 

Thread Starter

Dalaran

Joined Dec 3, 2009
168
Hehe thanks. I'm not really using the 5V rail of the PIC but instead the unregulated ~7V. This 7V goes to the h-bridge motor supply as well as a 7805 to regulate 5V for the PIC. Is this still a no-no?

I've also tried adding some large caps on the h-bridge supply as well as the input of the regulator and still no luck.

Cheers.
 

THE_RB

Joined Feb 11, 2008
5,438
The 7v rail is ok. Use 2 large caps, say 1000uF, and put one on the Vin pin of the regulator, then run a resistor to the +pwr pin of the hbridge IC, then the other cap from that pin to ground. Choose the resistor to drop maybe 0.5v (maybe 1 ohm? 2.2ohm?) when the motor is at full current, the higher the resistor value the better it will decouple the motor/driver noise from the 7805.

I would also add a small cap across the motor pins, if you pulled the motor from commercial equipment it probably already has a cap there, if not try maybe 10nF ceramic.
 
Top