Maker Pro
Maker Pro

24Vac, 24Vdc or 12Vdc universal input interface to 3.3V microcontroller

Hi guys,

I consider myself a beginner in electronic and i am trying to interface field control boards working in either 24Vac, 24Vdc or 12Vdc (depending on the site) with a 3.3V microcontroller (right Side). After reading a lot on the best way to do it, i came up with the schematic below:
upload_2017-2-18_8-5-52.png

I need your feedback on this design and if there is any way to improve it.
Thank you in advance.
You guys rock.

[mod note -- fixed image]
 
Last edited by a moderator:

Harald Kapp

Moderator
Moderator
Welcome to EP.

A few issues:
  • T3 needs a resistor in the base to limit base current.
  • The relay should have a flyback diode in parallel to protect the transistor from overvoltage spikes when turning off the relay.
  • The optocouplers are not necessary. The potential isolation they provide is bypassed by the common ground. You can replace them by transistors directly driven by the input voltage and a suitable series resistor.
  • The voltage regulator IC1 should have an EMI filter at the input as suggested by the datasheet.
 
My advice. If this is a self educational project, then go for it. But if this is for a commercial manufacture, then I would suggest using proprietary power supplies produced in large numbers by a specialist manufacturer with all the problems ironed out.

Psu design looks quite simple on the surface, and can be great fun, but bubbling under the surface are some very critical issues that need to be taken care of and are not always obvious. As an example just look at the "simple" fuse in a catalogue, and then go and look at a data and application book on them. The book I have on fuses is 250 pages long!

To mangle a well known saying, your power supply is the STRONGEST link in your electronics chain. If it goes there is going to be a big mess of the rest of your circuitry and a lot of tears! Pay the small premium to buy in power supplies, giving yourself more time to develop your main circuits and give you confidence in the reliability of the final result. This will also be a selling point you can use with your customer.

All the best and Rock On!
 
Thank you TCSC47 for the advice. The main input (12/24V) is already regulated and is part of a separate control board. I looked at meanwell DC to DC converters but they are not cheap ! Any other brand suggestion ?

Thank you Harald for your comments, I have revised the schematic (see attached)

upload_2017-2-18_8-9-10.png

Question: Should I use a 6.2V Zener diode instead of C6 ?

Thank you so much for your help

[mod note -- fixed missing image]
 
Last edited by a moderator:

davenn

Moderator
Thank you so much for your help

you still have a number of problems in your relay section
as it is, the relay will never operate .... no one picked that up in your first post

1) pin 2 of the relay, D9 and C5 negative need to go to the gnd rail, NOT back to the collector of T3
2) the diode D9 is reversed
3) the LED3 and it's 470 Ω resistor need to be in parallel with the relay

OK looking at all that again ... it needs redone .......

upload_2017-2-18_9-11-40.png
what is the drive going into R24 and base of T3 ?
A 1k ( at the most 4k7) would be the best value there

Also note, I have added a 0.01uF cap on the output of the reg chip .... it wouldn't hurt to have one on the input as well

the 3 lines off the 3 transistors emitters, labelled INPUT1 3v3 etc .... do you expect 3.3V at those points ?
it wont happen .... you are going to get 2-3 V drops across the LED's (2,4,5) some more across the resistors (14,17,20)
and yet a bit more across the collector-emitter junction of the transistors ..... there isn't going to be 3.3V on those 3 labelled points
there isn't likely to be anything


Dave
 
Last edited:
Thanks Dave,
1) pin 2 of the relay, D9 and C5 negative need to go to the gnd rail, NOT back to the collector of T3
3) the LED3 and it's 470 Ω resistor need to be in parallel with the relay
I can see that my schematic was not very clear on the relay part, and the way you did it is much clearer.
However it seems that it was correctly wired.

2) the diode D9 is reversed
Thank you, my mistake

what is the drive going into R24 and base of T3 ?
A 1k ( at the most 4k7) would be the best value there
This is a 5mA 3.3v output from a microcontroller

Also note, I have added a 0.01uF cap on the output of the reg chip .... it wouldn't hurt to have one on the input as well
Noted, I will add it to the to the output. For the input side, adding another 0.01uF cap will not be redundant with the EMI filter?

where are those inputs coming from ?
what is the max voltage you are likely to see there ?
Input 1/2/3 are coming from a separate control board. These inputs will be 24Vac or 24Vdc or 12Vdc depending on the board I am connected to (same voltage as the Main input before the regulator)
 

davenn

Moderator
This is a 5mA 3.3v output from a microcontroller

OK ... a 1k is all you need there

Noted, I will add it to the to the output. For the input side, adding another 0.01uF cap will not be redundant with the EMI filter?

no it wont .... The 0.01uf caps are for high frequency oscillation suppression

Input 1/2/3 are coming from a separate control board. These inputs will be 24Vac or 24Vdc or 12Vdc depending on the board I am connected to (same voltage as the Main input before the regulator)

OK no probs .... for them I'm not sure how that will work ...
24V into the 3.3V regulator may be a nit of a worry tho .... dropping 20V across the regulator is going to produce a lot of heat
depending on the current you are expecting out of the regulator on the 3.3V rail

just for example .....say all your circuitry is drawing 500mA total ( including whatever is to the right off the page of the diagram

20V drop x 0.5A ( 500mA) load = 10W of power to dissipate .... that is a crap load of heat !!

ohhh and you didn't answer my other query ......

the 3 lines off the 3 transistors emitters, labelled INPUT1 3v3 etc .... do you expect 3.3V at those points ?
it wont happen .... you are going to get 2-3 V drops across the LED's (2,4,5) some more across the resistors (14,17,20)
and yet a bit more across the collector-emitter junction of the transistors ..... there isn't going to be 3.3V on those 3 labelled points, there isn't likely to be anything






Dave
 
24V into the 3.3V regulator may be a nit of a worry tho .... dropping 20V across the regulator is going to produce a lot of heat
depending on the current you are expecting out of the regulator on the 3.3V rail
k
I wanted to use optocoupler but due to the common ground, they are not really necessary as mentioned by Harald.
But would they not solve the heat problem?
Or should i use a Zener diode to reduce the voltage at the base of the transistor ?

the 3 lines off the 3 transistors emitters, labelled INPUT1 3v3 etc .... do you expect 3.3V at those points ?
it wont happen .... you are going to get 2-3 V drops across the LED's (2,4,5) some more across the resistors (14,17,20)
Yes I noticed that thank you (again i am a beginner :), what would you recommend to have the LED ON when the transistor is triggered? Should I put the LED on the emitter side instead ?
 
In post #1, the optocoupler outputs are saturated transistors, and the output signals always are below about 1.3 V (3.3 V rail minus the LED Vf). In post #4 the transistors are emitter followers, and the emitters (and output signals) can be pulled up to 32 V with a 24 Vac input. The LEDs might light because they have over 8 V of reverse bias, but the downstream circuits expecting a 3.3 V signal are in for a surprise.

And back to post #1, the outputs are labeled with 3.3 in the names, but with an LED and current limiting resistor in series with the opto collector, they never will approach 3.3 V. If you want a 3.3 V logic level output and also want the LED to light, tie the opto collector directly to the 3.3 V and put the LED and its resistor from the emitter to GND, in "parallel" with the output signal.

For the transistor version to make a non-inverted signal that never goes above 3.3 V, you will need two transistors per signal input. Or, it can be done with no transistors and two 1N4148 diodes per input. Welcome to the 50's.

ak
 

davenn

Moderator
I wanted to use optocoupler but due to the common ground, they are not really necessary as mentioned by Harald.
But would they not solve the heat problem?

This has nothing to do with those transistors you are using for switching ( where you originally had the opto=couplers)

I am referring to the 3.3V regulator and the heat it will have to dissipate


Davenn said:
the 3 lines off the 3 transistors emitters, labelled INPUT1 3v3 etc .... do you expect 3.3V at those points ?
it wont happen .... you are going to get 2-3 V drops across the LED's (2,4,5) some more across the resistors (14,17,20)

Yes I noticed that thank you (again i am a beginner :), what would you recommend to have the LED ON when the transistor is triggered? Should I put the LED on the emitter side instead ?

putting it in series in the emitter side is the same thing
maybe this will work ...... @Harald Kapp ??
I'm also not sure if the 3 x 10k's from the emitters to GND are needed ?

circuit.JPG

Those 4 inputs on the right side... where are they going ? to input pins on the micro ?

Dave
 

Harald Kapp

Moderator
Moderator
Using an NPN transistor to switch Vcc (3.3 V, high side) is not a good practice. If you can't ensure that the input voltage is higher than 3.3 V, the output voltage will not reach Vcc, only Vcc-Vbe.
Having a 10 kΩ pull down resistor in parallel to a 470 Ω resistor and an LED is pointless. The current through the LED will be much higher than the current through the pull down resistor.
I suggest the following circuit:
upload_2017-2-19_11-41-19.png
Without input signal the transistor is off and the output is high, pulled-up by R2 and D2. As the output will be connected to the input of a microcontroller (my understanding), the output current will be very low, so the LED will not visibly light up.
When the input voltage is greater than ~0.7 V, the transistor will become conducting, the output voltage will drop to nearly 0 V (Vcesat, to be precise, being ~0,1 V ...0.2 V). This is a good logic low signal to the microcontroller. At the same time the cathode of the LED will be at ~ 0 V and the LED will light up bright (how bright depends on the value of R2 and the resulting current).

Note that this circuit inverts the input signal:
No input signal -> high output voltage
High input signal -> low output voltage
This can easily be handled in software inside the microcontroller.

I am referring to the 3.3V regulator and the heat it will have to dissipate
Basically correct if it weren't for the R78E3.3 being a switch mode module which will dissipate comparatively little waste power.
 
First pass at a diode switch input that keeps the output at a max of Vcc. D2 clamps the anode of D3 at 1 Vf above Vcc, which places the D3 cathode at approx. Vcc.

If the input signal source can drive an LED, it (and a current limit resistor) can be added in parallel with R2 with a reduced R1.

ak
24V-uC-Input-1-c.gif
 

Attachments

  • 24V-uC-Input-1-c.pdf
    6.4 KB · Views: 67

Harald Kapp

Moderator
Moderator
This circuit will work in many, if not most, cases. In my view, however, it has two diadvantages:
  1. There will be a current flow from the external input into Vcc (3.3 V). This will power the µC circuit even with the main power supply off. The 3.3 V regulator may not be designed to be powered backwards, the bahvior is unpredictable.
  2. Any overvoltage (spikes, pulses, not unlikely when conneced to e.g. process control signals) will appear on Vcc, thus risking damage to the sensible µC circuit.
The 10 kΩ resistor R1 in post #14 will offer a bit of protection by limiting the current, but reducing R1 to allow drive of an LED also reduces the protective properties of this resistor.
Besides: powering the LED from 12 V ... 24 V will dissipate a lot of energy as waste heat in the current limiting resistor, much more than is required when powering the LED from 3.3 V.
 
The circuit is a first pass, and assumes everything is powered up and running. Still, nice catch on the input powering the uC when the 3.3 V is off.

As for the "lot of energy" lost if R1 powers the LED - not so much. With a 3.3 V rail, a saturated input transistor, a 2 V Vf LED, and 470 ohms, the LED current is only 2.7 mA. For a 12 V input with a series diode, that works out to R1 = 3.4K, dissipating 25 mW. At 24 Vin that increases to 6.3 mA and 130 mW.

ak
 
Last edited:

Harald Kapp

Moderator
Moderator
As for the "lot of energy" lost
A lot only in comparison to 3.3 V operation, right.

Let's take this "Gedankenexperiment" a bit further:
We don't know the source or the quality of the input signal. A typical process control signal (e.g. from a remote sensor or contact) may carry lots of noise, dips and spikes due to long wires leading to the input. The input as it is with its diode and capacitor will rectifiy any noise and charge the capacitor which may lead to false positives (signal detected where no signal is present). Also the large 100 µF capacitor will keep the input active even after the input voltage has disappeared. 24 V on 100 µF at an LED current of 3 mA will keep the LED alive for ~800 ms without input signal. This may be intended to suppress noise on the input, but this may also have unintended consequences if a change in sensor signal is detected 800 ms too late.
Recommendation: design the input capacitance to minimize delay at turn-off but large enough to keep the input alive during short dips in input voltage.

There is also no protection of the input circuit (neither in your circuit nor in mine) against overvoltaeg spikes as may be present due to e.g. capacitive coupling when the wires to the sensor are long and can couple to neighbouring wires carrying possibly high voltages and/or currents.
Recommendation: Add an overvoltage protection, e.g. a transient suppressor diode (TVS).
 
Hi guys,

Sorry I have been busy wiring it and trying it out. Attached is the modified schematic I am using.
I transferred the LEDs from the transistors collectors from @Harald Kapp post #12, to additional IC outputs.
The problem with post #12 was that the LEDs were not switching off (a light glow will still be there).

I still have an issue with the relay and LED2.
The 3V relay is a LEG3 from RAYEX, the LED is a regular green LED.
The relay will click when the T3 transistor's base gets 3.3V, but the LED2 (green LED) will not glow.
If I remove the relay, the LED2 will glow.
The output of the DC/DC is 3.3V / 0.5A.
I tried to short the 470Ohm resistance R12, but same scenario.
Any idea?
 

Attachments

  • Schematic V3.1.pdf
    153.9 KB · Views: 85

Harald Kapp

Moderator
Moderator
This sounds like there is not enough current for both relay and LED due to the transistor's limited current gain. Although it is fun ythat the relay comes on but not the LED. I'd have expected the other way round.
Anyway: Try a smaller value for R24, e.g. 1 kΩ.

And another thougt: the cathode of capacitor C7 should be connected directly to ground.
In your circuit transistor T3 has to carry the full charge current for C7 at turn on.
 

davenn

Moderator
This sounds like there is not enough current for both relay and LED due to the transistor's limited current gain. Although it is fun ythat the relay comes on but not the LED. I'd have expected the other way round.
Anyway: Try a smaller value for R24, e.g. 1 kΩ.

yeah, that was my first comment suggestion way back in post #8
it obviously wasn't followed ;)


And another thougt: the cathode of capacitor C7 should be connected directly to ground.
In your circuit transistor T3 has to carry the full charge current for C7 at turn on.

yup that's a good idea


Dave
 
Top