Intermittent DC Motor on H-Bridge

Thread Starter

Dalaran

Joined Dec 3, 2009
168
I am trying to run a DC motor using a L293DNE H-Bridge and PIC16F684. Pins 2 and 7 of the bridge are connected to 2 PORTC pins on the PIC. The PIc compares 2 analogue inputs and if A > B set PORTC.0 high and PORTC.4 low, and vice versa if A < B. There is a region in the middle that both ports go low if the inputs are sufficiently close. I can post code if anyone is interested but it was initially checked with LEDs connected to the ports and everything worked perfectly.

This is the connections of the H-Bridge.


Always when the PIC is first started the DC motor runs smoothly in the direction it is intended. I am currently using 2 voltage dividers to set the voltages on the two analogue pins on the PIC. CCW direction always works fine but when I try to set it to the CW rotation it gets all jittery and starts and stops a few times a second.

Any ideas what might be going on?

Thanks.
 

SgtWookie

Joined Jul 17, 2007
22,230
Do you have a 0.1uF cap across the PIC's Vdd/GND pins?

Do you have a non-polarized cap across the motor?

Do you have small caps from the middle of the voltage dividers to ground?
 

Thread Starter

Dalaran

Joined Dec 3, 2009
168
I do, I don't, I don't.

What size cap do you recommend across the motor? I realize if I put caps on the middle of the voltage dividers to ground I will most likely need to slow down my ADC time between acquisitions. Are these necessary since I was having no function problems with LEDs to the outputs?

Thanks.
 

SgtWookie

Joined Jul 17, 2007
22,230
I do (have a 0.1uF cap across the PIC's Vdd/GND pins)

I don't (have a non-polarized cap across the motor.)

I don't (have small caps from the middle of the voltage dividers to ground.)

What size cap do you recommend across the motor?
Try a non-polarized 0.1uF. If you have a larger non-polarized cap, try it.
I realize if I put caps on the middle of the voltage dividers to ground I will most likely need to slow down my ADC time between acquisitions.
Yes. However, you need a low-impedance input to the ADC anyway. If you're just using a voltage divider, you're presenting a high-impedance input to the ADC, which is not good.
Are these necessary since I was having no function problems with LEDs to the outputs?
The LEDs produce very little, if any noise. The motor produces a tremendous amount of electrical noise. It's like having a punk band concert in a library. :eek:

I don't know how often you need to take ADC samples.
If your divider network is around 250k Ohms total, and you use a 10nF cap, it'll take around 6mS for the voltage on the cap to get within 99% of actual.
 

Thread Starter

Dalaran

Joined Dec 3, 2009
168
I have placed 100nF non-polarized caps across the motor as well as from the middle of the voltage divider where the ADC samples to ground. This however has not helped the performance and I am still having the same issue, once in CCW it does not like going back to CW rotation. If it starts in CW rotation it is ok until you go to CCW and try to get back to CW. I have increased the time between acquisitions of ADC to almost 200ms just to play safe. I will need to sample fast than this but I figure lets get this thing to work first.

Any other ideas what might be happening?
 

Thread Starter

Dalaran

Joined Dec 3, 2009
168
Hi Thanks. Yeah, I've convinced myself that it is not the program. With the output pins floating or connected through LEDs i get the exact response I am looking for. However when I hook up to the motor and H-bridge I have the funky behaviour.

Thanks.
 

Thread Starter

Dalaran

Joined Dec 3, 2009
168
I've done a little more testing and it seems that when I switch back to CW rotation and the motor seems to almost jam up the output pins on the PIC are not driving the correct voltage. Under the CCW rotation that works fine I have almost exactly 0V and 5V at RC0 and RC4 respectively. However when the motor struggles I only measure ~0.35V on both RC0 and RC4.

What could cause this sort of behaviour in the PIC?

Thanks.
 

SgtWookie

Joined Jul 17, 2007
22,230
You might have a damaged L293, or a damaged output pin.

Try disconnecting the PIC from the L293, and see if the output voltage comes up to normal.

If it does, try a load test on it. Connect a 270 Ohm resistor from the pin that's low to ground, and try to output a logic high. It might not be right at 5v, but it should be above 4v.
 
Top