Interfacing 9-30V external input signal to logic level

Thread Starter

peckett

Joined May 9, 2021
18
Hello

I am trying to find the best solution to interface a 9-30V input signal to logic level so I can read the input on my AVR.
I am building a flasher unit that can be powered between 9-30V which will also power 2-4 beacons.
The beacons are enabled from a 555 timer switching a 9-30V trigger.
The beacons return a 9-30V input signal that tells the flasher unit if there is an LED fault.
To get the voltage from 9-30V to 5V the best solution I have come across is to use a optoisolator.
Because all the beacons are powered from the same source as the flasher unit the grounds will not be isolated.
So I was wondering if it is ok to use the same ground on both sides of the optoisolator?
Then the 9-30V fault signal will still have a reference to ground and will also still be isolated from the AVR if a technician wires it up incorrectly?
The only other way I have thought of is to use a zener diode so when there is an input voltage it is always clamped down to 5.1V instead of 9-30V?
I have managed to increase voltages but am having a hard time decreasing them, I can't use a voltage divider as the input voltage can vary and couldnt find a way of doing it using a transistor? so thought maybe zener diode?
Any advice appreicated

Thanks
 

Attachments

Papabravo

Joined Feb 24, 2006
21,157
Comparator with an open collector (drain) output. You can set the threshold where it needs to be and it will be compatible with any logic level determined by the pullup resistor. You can also add hysteresis. Typical part would be LM339 (Quad) or LM393 (dual). there may even be single versions of this part.
 

MrChips

Joined Oct 2, 2009
30,705
I think what you are doing is fine.
4k7Ω resistor will limit the opto-coupler LED current to 2-6mA. There is no need for a zener diode.
I see no problem with common ground on the opto-coupler.
 

Papabravo

Joined Feb 24, 2006
21,157
I'm puzzled about why you are asking for a solution when you already have one. I don't know if there is a secret way to see the detail on that schematic, but it is just too small and fuzzy to glean much information from.
 

ronsimpson

Joined Oct 7, 2019
2,985
Green trace is the incoming signal going from 0 to 30V.
Yellow (Z) shows a combination of 4.7V Zener and 2:1 voltage divider. Signal is sloppy but works.
Red (Q) has a transistor. It switches from 0 to 1 at 6 volts.
Just some thoughts. (could use a LED for a Zener)
RonS.
1620872593543.png
 

Thread Starter

peckett

Joined May 9, 2021
18
I'm puzzled about why you are asking for a solution when you already have one. I don't know if there is a secret way to see the detail on that schematic, but it is just too small and fuzzy to glean much information from.
I was asking if the solution is a good way to do what I am trying to do. If the grounds on either side of the opto are the same is that an issue? as the 9-30V input would still be isolated from the AVR?
 

Papabravo

Joined Feb 24, 2006
21,157
I was asking if the solution is a good way to do what I am trying to do. If the grounds on either side of the opto are the same is that an issue? as the 9-30V input would still be isolated from the AVR?
No they won't necessarily be isolated. If you have a common ground on both sides of the opto, the 9-30V IO can cause the AVR's ground to bounce depending on the the loads. I'm just curious about why you think the opto with the common grounds is an OK solution. It may or it may not be. You can however investigate the issue better than we can. BTW what is the cost of the optos? You may be spending money you don't have to.
 

Thread Starter

peckett

Joined May 9, 2021
18
No they won't necessarily be isolated. If you have a common ground on both sides of the opto, the 9-30V IO can cause the AVR's ground to bounce depending on the the loads. I'm just curious about why you think the opto with the common grounds is an OK solution. It may or it may not be. You can however investigate the issue better than we can. BTW what is the cost of the optos? You may be spending money you don't have to.
The opto's are 0.84 aud. I don't know if it is an OK solution that's why I was asking as I am inexperienced I am not sure of best practices. I have looked all over the internet to find a good way to drop a 9-30V input down to logic level, I just tested your suggestion out and seems to work good so I might do it this way.
Not sure if I have done it correctly will do some studying on op amps tonight.
Tied the inverting input to ground and the non inverting to ground through 10k resistor.
when input is high (9-30V) on the non inverting input it will turn on the output at 5V if the op amp has 5v supply?
 

Attachments

Papabravo

Joined Feb 24, 2006
21,157
The opto's are 0.84 aud. I don't know if it is an OK solution that's why I was asking as I am inexperienced I am not sure of best practices. I have looked all over the internet to find a good way to drop a 9-30V input down to logic level, I just tested your suggestion out and seems to work good so I might do it this way.
Not sure if I have done it correctly will do some studying on op amps tonight.
Tied the inverting input to ground and the non inverting to ground through 10k resistor.
when input is high (9-30V) on the non inverting input it will turn on the output at 5V if the op amp has 5v supply?
That is why we are giving you alternatives -- so you can make the best decision for your needs. I did not say to use an opamp. I said to use a comparator with a supply voltage grater than your input which has an OPEN COLLECTOR output. The pullup resistor used in conjunction with the open collector output will adjust the output to whatever logic level you are using. Using a high value input resistor will limit the input current and prevent other problems. The prototype parts I have in mind are the LM339 (Quad) and the LM393 (Dual). If required you may be able to find a single in a SOT23-5 package or smaller.

https://www.onsemi.com/pdf/datasheet/lm339-d.pdf

Note: This device can have a supply voltage up to +36VDC. This is why it is so useful in this application,; we used it for factory automation equipment all the time. It is a beast when it comes to robustness.
 

Thread Starter

peckett

Joined May 9, 2021
18
Ah sorry I thought a comparator was just a circuit type made from an op amp. Ye no idea what I did before but it is now working perfectly thank you, I will use the LM339 in my design :)
 

Papabravo

Joined Feb 24, 2006
21,157
Ah sorry I thought a comparator was just a circuit type made from an op amp. Ye no idea what I did before but it is now working perfectly thank you, I will use the LM339 in my design :)
No problem. That is why we go back and forth until we get it right.

Look carefully at the datasheet for "Common Mode Range". Basically it says that at least one of the two inputs must be within the "common mode range". As long as your threshold voltage satisfies this requirement you should have no trouble.
 

AnalogKid

Joined Aug 1, 2013
10,986
IF everything is common grounded

AND IF the 9-30 V signal is driven to ground (or womething less than 0.5 V) when in the "off" state

THEN

I think a 4.7K-to-10K series resistor and a 4.7 V-to-5.1 V zener diode will do everything you want. No transistors, opamps, whatever. If the input signal goes open circuit rather then being pulled to GND, then add a 100K resistor in parallel to the zener to assure a low logic level.

ak
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,157
IF everything is common grounded

AND IF the 9-30 V signal is driven to ground (or womething less than 0.5 V) when in the "off" state

THEN

I think a 4.7K to 10K series resistor and a 4.7 V to 5.1 V zener diode will do everything you want. No transistors, opamps, whatever. If the input signal goes open circuit rather then being pulled to GND, then add a 100K resistor in parallel to the zener to assure a low logic level.

ak
I can't quite picture what the words are saying. I understand the zener diode but not the arrangement of the two resistors.
 

AnalogKid

Joined Aug 1, 2013
10,986
9-to-30 V signal >> 10K series resistor >> shunt zener diode and 100K pull-down resistor in parallel to GND. Output from the 10K / zener node.

ak
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,157
9 to 30 V signal >> 10K series resistor >> shunt zener diode and 100K pull-down resistor in parallel to GND. Output from the 10K / zener node.

ak
Got it. I misinterpreted "4.7K to 10K" as referring to two parts connected in some fashion.
What would be the threshold for switching between "high" and "low" and vice versa?
Can there be hysteresis?
 

Thread Starter

peckett

Joined May 9, 2021
18
Got it. I misinterpreted "4.7K to 10K" as referring to two parts connected in some fashion.
What would be the threshold for switching between "high" and "low" and vice versa?
Can there be hysteresis?
The input would just be toggling between ground and supply voltage (9-30V0. I just need to convert it to 5V so I can use it on my AVR. So yes hysteresis is allowed. So this would probably the best/cheapest solution?

9 to 30 V signal >> 10K series resistor >> shunt zener diode and 100K pull-down resistor in parallel to GND. Output from the 10K / zener node.

Thanks guys
 

Papabravo

Joined Feb 24, 2006
21,157
You don't get those things for nothing you have to provide for
The input would just be toggling between ground and supply voltage (9-30V0. I just need to convert it to 5V so I can use it on my AVR. So yes hysteresis is allowed. So this would probably the best/cheapest solution?

9 to 30 V signal >> 10K series resistor >> shunt zener diode and 100K pull-down resistor in parallel to GND. Output from the 10K / zener node.

Thanks guys
You don't get those features, setting the threshold and hysteresis, for free. You have to provide for them.
 
Top