Maker Pro
Maker Pro

Help with dc motor connected to a PIC microcontroller.

diego

Dec 31, 2010
16
Joined
Dec 31, 2010
Messages
16
Hi, I've been trying to make an encoder, but I've run into some problems with the DC motor.

I built an intermediate circuit which counts the amount of times an IR sensor detects light bounced back (I use the CNY70 which is just an IR diode and a phototransitor) and displays it in binary on six LED's. This works just fine, the problem comes when I connect a DC motor to the same power source, the LED's go wild and starting flashing very fast.

This does not happen if I connect the motor to a sepparate power source or if I stop the motor with my hands even though the motor remains plugged in to the power. My guess is that it has something to do with back EMF but I'm unsure (I've already tried a few things that didn't work).

Any help would be appreciated. I've attached a diagram of the circuit I've been using.
 

Attachments

  • PICT0361.jpg
    PICT0361.jpg
    92.8 KB · Views: 870
Last edited:

Resqueline

Jul 31, 2009
2,848
Joined
Jul 31, 2009
Messages
2,848
As usual, no decoupling capacitors..
And I don't understand how you manage to make the LED's & optocoupler work with 330k resistors btw..
 

Attachments

  • PICT0361.jpg
    PICT0361.jpg
    97 KB · Views: 325

diego

Dec 31, 2010
16
Joined
Dec 31, 2010
Messages
16
Yes there is a mistake in my drawing, indeed every resistor that says 330k is not 330k but 330 ohms. Thanks for pointing it out.

How would you connect decoupling capacitors? Because I've been thinking it with my brother and came to the conclusion that some sort of cicuit like the following might do the trick.
 

Attachments

  • PICT0368.jpg
    PICT0368.jpg
    86.3 KB · Views: 494

Resqueline

Jul 31, 2009
2,848
Joined
Jul 31, 2009
Messages
2,848
Ah, yes, 330 ohms sounds better..
100 ohms in series with the motor might be a bit much, but if it runs with that then all the better. Also take a look at my picture attached above, it's not there for no reason.
 

diego

Dec 31, 2010
16
Joined
Dec 31, 2010
Messages
16
All right i'll try that thanks. Btw it's been sometime since I use electronics so I'm a bit rusty can you recomend me a book to read?
 

diego

Dec 31, 2010
16
Joined
Dec 31, 2010
Messages
16
Sorry but could you explain to me your fix, because I see a resistor connected to the power source a two points?? How can this be I mean no current will go through the resistor.

I supposed you meant having the motor and the resistor in series and all of this in parallel with the capacitor but I am still getting the problem.
 

Resqueline

Jul 31, 2009
2,848
Joined
Jul 31, 2009
Messages
2,848
I'm sorry but I'm not up to date on books, it's been 20 years since I read any.. ;)

In my fix the 9V supply is not Vcc but is fed directly to the motor. Vcc is then derived from this via a 10 ohm resistor & a 100uF cap before being fed to the PIC.
I'd try this first, it's essential, and if any quirks remains you can also add a res & a cap to the motor itself.
 

diego

Dec 31, 2010
16
Joined
Dec 31, 2010
Messages
16
Oh, I see what you were trying to do, but suppose you only had 5 V supply no 9 V and those 5 V also need to go to the motor, what would you do then?? (funny thing my 5 looks like a 9)
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Same deal :) I read it as 5V and it still makes sense.
 

diego

Dec 31, 2010
16
Joined
Dec 31, 2010
Messages
16
Would you care to explain to me why is it the same deal? Having the 10 ohms resistor connected to +5V on one end and to +5 V on the other end. Should I just discard the resistor??
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
No, the resistor is required. This GENERATES Vcc from your 5V.

+5V is +5V

Vcc is the Vcc

So connect +5V to your source of 5V

And your Vcc connections go to the Vcc.

This simple (1 resistor, one capacitor) circuit provides a filtered Vcc from your raw (and noisy because of the motor) +5V.

This is a method of decoupling the power supplies.

The capacitor holds the Vcc stable and the resistor prevents the spikes and dips generated by the motor from affecting the voltage too quickly. The end result is a stable Vcc very close to 5V, but without the noise.

The small resistor should not produce a significant voltage drop for the currents demanded by the uC.
 
Last edited:

diego

Dec 31, 2010
16
Joined
Dec 31, 2010
Messages
16
You're absolutely right, I've forgotten some things about electronics, and for some reason I kept the idea in my head that Vcc meant the voltage supply.

I tried the solution, that is treated the Vcc node as a seperate node from the power supply separated by a resistor of 10 Ohms, and a capacitor in parallel, but I am still getting noise, any ideas? If non don't worry I'll search over the internet for decoupling capacitors, I think you've done quite a lot.

Thanks for all the help.
 
Last edited:

Resqueline

Jul 31, 2009
2,848
Joined
Jul 31, 2009
Messages
2,848
The actual physical layout may introduce noise if not done by good design rules, so I guess we'll need a picture (or a physical layout diagram) to be of further assistance.
What does your power supply consist of, and how big is the motor btw.?
 

diego

Dec 31, 2010
16
Joined
Dec 31, 2010
Messages
16
I'll upload pictures tomorrow (right now I'm going to sleep) but I can tell you I am using a small motor (4 miliHenries of inductance) with a couple of gears and 4 AA rechargeable duracell batteries which give me between 4.6 and 5.5 volts (they're 1.2 volts according to the label and about 2200 mAh).

Btw I also did some changes that reduced quite a lot the noise though there is still a little bit of noise:
1) I implemented the resistor and capacitor as suggested.
2) I put also an RC circuit to the motor as suggested (which reduced its speed),
3) I put a capacitor connected to the pin T0CKI of the pic which id the counter for the signal sent by the optocoupler.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Yes, there are lots of ways. And as you've discovered, you often need to use a combination of more than one of them.

Congratulations on your success!
 
Top