Maker Pro
Maker Pro

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

Ok I brought another lower power wattage zener off ebay, the smallest one I could find was 500mw yet this is still only giving 2.5V argghh! ok so I will replace ther zener with a capacitor.
At the moment my resistors are
R1 = 18k
R2 = 6.8k
So how do I go about calculating the cap?
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
Ok I brought another lower power wattage zener off ebay, the smallest one I could find was 500mw yet this is still only giving 2.5V argghh! ok so I will replace ther zener with a capacitor.
At the moment my resistors are
R1 = 18k
R2 = 6.8k
So how do I go about calculating the cap?

Why is R1 so high? R1=1K, R2= 100K would seem more logical to induce zener action. R2, in this case, is not used as a voltage divider. It's only purpose is to keep the uC's input pin from floating when no signal is present. Heavily shunting the Zener with R2 just makes it harder for the Zener to to what a Zener does. I see no purpose to use it as a voltage divider. ;)
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
I've been dropping in and out of this thread, but I haven't read it in detail.

I was under the (incorrect) impression that you were wanting power, not signal. My previous advice is probably still reasonably valid, but I can do better :)

Sure, you can place a capacitor across R2 in your diagram. This will smooth out any spikes (to a certain extent) but it will also slow down he response to an input signal -- this is less a concern for power than a signal).

Instead, I suggest something like this:

attachment.php


This has the same form as your original circuit, however instead of using a zener to clip transients, diodes are used. And excess voltage that appears at the input will cause current to flow in one of the diodes and it will either be shorted to ground (for negative transients) or to the positive supply rail (for positive transients).

The sort of diodes you want to use here are fast diodes with a low Vf and capacitance. Schottky diodes or small signal diodes are best. R3 exists to limit the current into the input if the voltage rises far enough to allow the protection circuit at the input of the microcontroller to start conducting -- we want the external diodes to do the work.

R1 and R2 should be chosen as before to get approximately 3V3, and R3 can be (say) 1k.

One potential problem with this circuit is that if the uC is unpowered, a high input will shunt voltage to the uC rail via the upper diode. This *may* be sufficient to power the uC with potentially confusing results.

The other (more serious) problem is that if R1 is too low, and a high energy spike appears at the input, the current through the upper diode to the 3V3 rail may exceed the current required from the 3V3 rail in total. This will then cause the 3V3 rail to go high, possibly causing problems. To cure this, you need some protection on the 3V3 rail. Depending on the environment, a sufficiently large capacitor on the output of your voltage regulator may be sufficient. In extreme cases you may need to provide some active shunt to keep the 3V3 rail down to a save level.
 

Attachments

  • Scan-120708-0001.jpg
    Scan-120708-0001.jpg
    16.1 KB · Views: 283

CDRIVE

Hauling 10' pipe on a Trek Shift3
Personally, I think he should scrap the whole direct connection approach and use something like this. It would be a heck of a lot safer.

I read some of the FAQs on the Raspberry Pi that says it's powered by a wallwart or 4 dry cells..6V. While I think that 2.79V is more than satisfactory to provide a logic 1 state, it can easily be increased to 3.3V by providing the full power supply voltage (6V) to the collector of Opto1 and use a voltage divider on the emitter. Fact is I modeled this with 3.3V only because that's the figure being tossed around in this thread.
 

Attachments

  • OptoInterface.JPG
    OptoInterface.JPG
    25.4 KB · Views: 9,073
If you are using this to read DC signals from a motor, I would highly recommend an optocoupler between the motor and the Pi. One for each signal!

TOK :)
 
Ok the optocoupler is the safest way so I will be going with that.

Now I know less about these then anything else, on Farnell the lowest voltage is 1KV.

Using it is simple enough, can almost wire it up like a transistor, but I'll be working with 12V or posisbly 24V, how do I go about selecting the correct specs?
 
Ok the optocoupler is the safest way so I will be going with that.

Now I know less about these then anything else, on Farnell the lowest voltage is 1KV.

Using it is simple enough, can almost wire it up like a transistor, but I'll be working with 12V or posisbly 24V, how do I go about selecting the correct specs?

The voltage you refer to is the isolation voltage, or the potential voltag difference between input circuit and the output circuit. It has little to do with the voltages you use to drive the signal through. What type you select is mainly depending on the frequency of the signal you want to supervise, this is due to the current transfer ratio through the optocoupler. If it is too high the coupler is also slow. Some of the fast types har inbuilt drivers, and need Vcc to supply the output or the Pi side in your case. Be aware of that.

TOK ;)
 
Well the voltage difference will be 8.7V... the smallest one on farnell is 1kv. (So this is ok to use one that's overkill?)

Also what do you mean by frequency? its not AC, both sides are DC.

Also speed is of no concern, the 12v will be on for about a second or two and all i need to know is that the 12v has been on at any point as its more of a logger type device.
 
Last edited:

CDRIVE

Hauling 10' pipe on a Trek Shift3
No, it's not overkill. The 'Isolation' breakdown voltage is very high for all OptoIsolators and, as stated by Gorgon, has little to do with your particular circuit, which has no voltages, on either side of the Opto, that are that high.

Regarding switching speed or frequency response.. This too is of little consequence in your circuit. It would only be an issue if the opto was transferring data or required state changes in the uS region. You're just logging run time of a motor. Nothing very speed (response time) demanding there.

BTW, can the Raspberry logic (via coding) be inverted?
 
Last edited:

CDRIVE

Hauling 10' pipe on a Trek Shift3
I'm writing all the code from scratch so no reason why it can't be.

If that's the case and you want a full voltage swing from 3.3V to near zero V you can move the emitter resistor to the collector and ground the emitter. The 3N33 is a Darlington, so the collector will never go far below ~ .7V but other model optos are not Darlingtons. Non Darlington models can be brought to within a few mV of ground when the LED is on.

In any case and as I said before, I think the circuit, as I drew it, (emitter follower) will work just fine. I've never seen a device that required a Logic 1 or 0 to be exactly the supply rail or the neg rail. There's always a window of what's considered a logic 1 or 0.
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
I've never seen a device that required a Logic 1 or 0 to be exactly the supply rail or the neg rail. There's always a window of what's considered a logic 1 or 0.

For CMOS, you're generally looking at 1/3 and 2/3 of Vcc, This page explain it well.
 
For CMOS, you're generally looking at 1/3 and 2/3 of Vcc, This page explain it well.

It could be that the IO on the Pi is 'TTL' compatible, and that will have an impact on the electrical logic levels. This should be defined in the electrical specification of the Pi's IO.

That said, it is always good to get as crisp levels as possible, due to the signal vs. noise quality.

TOK ;)
 
Top