Maker Pro
Maker Pro

Correct way of converting 12v down to 3.3 for a pin input?

Pauly24

Jun 10, 2012
12
Joined
Jun 10, 2012
Messages
12
Hi,

I have a raspberry pi (http://www.raspberrypi.org/faqs) and looking to build a little project for it.

I wish to use the input pins to log what is happening with some DC motors.

High for the raspberry input pin is 3.3V and low is 0V.

The DC motors are running off 12V and every so often they get switched on for a few seconds then are off again. Could be off for minutes or hours.

(Think along the lines of a vending machine and I'm trying to log how many times a product is vended)

I'm looking for help on understanding what is the correct way of doing this.

What I would do (which is probably wrong) is put two resistors in the correct ratio across the motor terminals and tap into that to give me my 3.3v. (I don't even know if this would work)

Also when the motor isn't on the pin can't be floating (I know its obvious but i need to state the obvious for myself as I'm new to all this)

Any help is greatly appreciated.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
You're talking about a voltage divider. This is a suitable tool for this job, It will, at the same time, relief you from thinking about the floating input because the lower resistor of the divider (the one goung to GND) will pull down the input when the motor pins are floating.

A motor can generate a lot of spurious distortions. A 3.6 V zener diode parallel to the lower resistor plus a series resistor to the µController protect the µC from these distortions. The setup can look like this:
attachment.php

The series resistor should be 1kOhm or more, the divider you can calculate yourself, please.

Harald
 

Attachments

  • bla.jpg
    bla.jpg
    30 KB · Views: 997
Last edited by a moderator:

Pauly24

Jun 10, 2012
12
Joined
Jun 10, 2012
Messages
12
Ok so if the voltage is 12V, and I want 3.3

12-3.3=8.7

So the ratio is 3.3:8.7

R1=870
R2=330

Is this correct?

What about the overall value of resistance for R1+R2 or the power rating?

Do they matter or is it only the ratio we care about?
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
The ratio for R1, R2 is correct.
at 12 V this makes for 0.12 W (p=u²/r). While this is not very much, you might want to go for less, e.g. by scaling both resistors by a factor of 10, thus
R1= 8.7 k
R2 = 3.3 k

Harald
 

CocaCola

Apr 7, 2012
3,635
Joined
Apr 7, 2012
Messages
3,635
May I also suggest you look into a flyback diode if you are tying directly to the motors power, don't want to poof the input pin or whole device from a surge
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
That's the function of the zener-diode.
positive spikes will be limited by the zener function, negative spikes by thge normal diode function.

Harald
 

CocaCola

Apr 7, 2012
3,635
Joined
Apr 7, 2012
Messages
3,635
That's the function of the zener-diode.
positive spikes will be limited by the zener function, negative spikes by thge normal diode function.

Gotcha, I glazed right over your post with the recommend schematic and missed the diode in it...
 

Pauly24

Jun 10, 2012
12
Joined
Jun 10, 2012
Messages
12
How do i go about calculating what power rating I need for the Zener Diode?
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Use whar´tever you can get, the requirements are small:

Worst case is R2 missing,
then the current through the diode will be

I= (12 V - 3.6V)/R1 ~ 1mA

The power then is P = 1mA * 3.6 V = 3.6 mW
In practice less due to R2 = 3.3 kOhm.
A typical power rating for the zener would be 250 mW - far away from the real power dissipated.

Harald
 

Pauly24

Jun 10, 2012
12
Joined
Jun 10, 2012
Messages
12
Im having a problem when building the circuit, if I dont put the diode in and measure I get 3.3V, but when I put the diode in the voltage drops to 1.8V. Should the diode drop the voltage or have does this mean I've wired it up wrong?
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Check the polarity on the diode. Most likely you have it reversed. The Anode should be at ground.

Bob
 

Pauly24

Jun 10, 2012
12
Joined
Jun 10, 2012
Messages
12
If i swap it around I get 0.6V, does it matter on the rating of the diode? as I'm using a 1W 3.6V.

R1 is 18k and R2 is 6.8k as that's what I had around.

With no zener its 3.3V, with zener its 1.8V and when I reverse the zener I get more like 0.7V
 
Last edited:

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Sounds like it is actaully a 1.8V zener diode then.

Bob
 

Pauly24

Jun 10, 2012
12
Joined
Jun 10, 2012
Messages
12
Nope, I just got two fresh packets from farnell.
1 lot of 5W 3.6V zener diode, and another lot of 1W 3.6V zener diode.

If I put the 5W 3.6V I get a voltage of 1.5V, if i reverse it I get 0.6V

If I use the other diode I get what I mentioned before... :confused:
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
What are the part numbers for those diodes, and are they getting warm (or hot)?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
OK, if you take a look at the datasheet for the first diode, you'll see a current vs voltage graph. For low voltage zeners the knee is very soft (this is a "feature" of low voltage zeners).

Reading the graph, I would expect to see a voltage of 1.8V at 5 to 7 mA.

Lets do some math...

What current through the zener is required to cause the voltage divider to be loaded to 1.8V? This will be the current through the 870 ohm resistor required to drop 10.2 volts. That current is 11.7mA. Across 1.8V the 330 ohm resistor will pass about 5.5mA, so the current through the zener needs to be only 6.2mA.

Looks like reality is a close match to the datasheet. I suspect that you'll find something similar for the other zener.

There are several options.

1) use a lower value for R1 to increase the current through the zener. (and possibly remove R2)
2) use a lower wattage zener that will leak less current at voltages lower than the zener voltage.
3) use something stiffer than a zener (TL431?)
4) replace the zener with a capacitor (it will also help isolate the uC power from the 12V rail transients)

This voltage divider is problematic if your uC draws more than a mA or two for exactly the same reason.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Great explanation Steve! I have now learned something: be careful using a zener to clamp a voltage when the current through it will be low.

Bob
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Yeah. There's a rule of thumb that you should have zener current at significant (50%+) of the max current to ensure voltage stability. Most people ignore that, and for higher voltage zeners you can get away with it.

However lower voltage zeners have a knee that looks more like a banana than a knee and thus it is important to get the current up to maintain a reasonable voltage.

The tricky thing is that this feature is not obvious from the datasheet. You'll find that the 3.3V zener will be specced to be between (in this case) 3.14 and 3.47 volts. In this case the kicker is that this is at 380mA! Even the deltaVz hides the extent of the problem.

The current vs voltage graph is generally well hidden.

The problem often starts to become significant at zener voltages below 5.6V -- And I recall that there is an explanation of this, but for now I can't recall the details.

I'll also admit to being fooled at first, thinking that the wrong zener was fitted.

I have no excuse, it combines all the killer features, low current, low voltage, and a high power device. :( I'm embarrassed that I didn't spot it much earlier.

A note on using a TL431 as a replacement: don't let the current through it fall below about 500uA or it may start misbehaving very badly. Most are specced for a minimum current of 1mA.
 
Top