Convert 24V to -12V

Thread Starter

flyingsock

Joined Oct 21, 2017
16
Hello, how's it going?
I have switching sensor with 2 outputs:
output 1: NO - PNP 24V. Basically when the sensor detects something pin 1 will output 24V.
output 2: NC - PNP 24V. Basically when the sensor is NOT detecting something pin 2 will output 24V.

RS232 port understands +12V as low and -12V as high.
I need to connect both outputs to a PC serial port, let's say I'm going to use input pins 8 (CTS) and 6 (DSR),
BUT, I'd have to convert:
output's 1 24 V to -12V (high level)
and
output's 2 24V to +12V (low level)

Is it possible to be done with a simple circuit? Am I better off using a voltage converter?
Is it a stupid idea anyway?

Thanks a lot.
 

LesJones

Joined Jan 8, 2017
4,191
Why do you need to us both the NO and NC signal ? They both contain the same information even though one is the inverted form of the other. One trick you may be able to use is to set one of the modem control signals from the PC so that it is permanently at -12 volts. (Assuming it is not being used for any other purpose.) You could connect a pull down resistor to that point and have a PNP transistor with it's emitter connected to + 12 volts and it's collector connected to the pull down resistor. You could then just drive the base of this transistor via a couple of resistors between 0 volts and one of the signals from your sensor.

Les.
 

ericgibbs

Joined Jan 29, 2010
18,874
hi,
Have you considered using a MAX232 IC.? , resistive voltage divider on the 24V , down to 12V as inputs.
Strap pins on the MAX to give a + or - 9V signal out.
E
 

Thread Starter

flyingsock

Joined Oct 21, 2017
16
That is pretty clear, thanks a lot.

Why do you need to us both the NO and NC signal ? They both contain the same information even though one is the inverted form of the other. One trick you may be able to use is to set one of the modem control signals from the PC so that it is permanently at -12 volts. (Assuming it is not being used for any other purpose.) You could connect a pull down resistor to that point and have a PNP transistor with it's emitter connected to + 12 volts and it's collector connected to the pull down resistor. You could then just drive the base of this transistor via a couple of resistors between 0 volts and one of the signals from your sensor.
Les.
Sorry, I don't understand at all, what +12V are you talking about?
The model control signal you mean is pin 4 DTR, right? And I should be able to make set it to -12V via programming?

Also, I have a sensor with NO relay output. Would I be able to simply set DTR to -12V, then connect the DTR pin to the NO output, and wire it to an input on the serial port (let's say CTS pin)? So everytime the sensors detects something the NO contact will close, thus providing -12V on the CTS pin. Is that right? Thanks.

hi,
Have you considered using a MAX232 IC.? , resistive voltage divider on the 24V , down to 12V as inputs.
Strap pins on the MAX to give a + or - 9V signal out.
E
Sorry, I don't understand at all, can you elaborate?
MAX232 would recquire a 5V source, and as far as I'm concerned it is used to convert +-30V down to 5V or 0V, right?
How exactly does it solve my problem? Thanks a lot.
 

LesJones

Joined Jan 8, 2017
4,191
I was just assuming that you would know how to get +12 volts from the +24 volts that you from the sensor power supply. (I assume Eric was also assuming the same when he talks about + 5 volts to power a MAX232) To get +12 volts from the +24 you could use a linear regulator such as an LM7812. (Or for Eric's solution use an LM7805 to get the +5 volts.) Eric solution is better than the trick I suggested as it gives a more reliable signal level and avoids having to force one of the modem control signals from the PC to be a negative voltage level. (The serial port signal levels from many PCs is often lower than the normal RS232 signal levels.) For Eric's solution I would use an ST232 as it only needs 100 nF capacitors instead of the 10 uF capacitors required for the MAX232.

Les.
 

Reloadron

Joined Jan 15, 2015
7,523
This line of questioning runs along with this thread just so everyone understands in some detail what is going on. The simple solution in my thinking would be the MAX 232 chip as was also suggested here. Another option if permissible (as this relates to a school project) would be to simply get a USB to RS232 serial adapter. Anyway for the curious at heart you may want to read the other thread. :)

Ron
 

Thread Starter

flyingsock

Joined Oct 21, 2017
16
This line of questioning runs along with this thread just so everyone understands in some detail what is going on. The simple solution in my thinking would be the MAX 232 chip as was also suggested here. Another option if permissible (as this relates to a school project) would be to simply get a USB to RS232 serial adapter. Anyway for the curious at heart you may want to read the other thread. :)

Ron
I don't understand that all how the MAX232 is of any help here.
Afaik it's used to convert serial levels to TTL levels.
 

WBahn

Joined Mar 31, 2012
30,088
Let's say that you successfully get compatible voltages. How are you going to then get the information from the serial port on the PC? Do you have the ability to bit-bang the individual pins?
 

Reloadron

Joined Jan 15, 2015
7,523
I don't understand that all how the MAX232 is of any help here.
Afaik it's used to convert serial levels to TTL levels.
The idea being is that if you convert to simple TTL levels things become much easier. In your other thread, which I linked to in this thread, the example I gave you used a simple USB to RS 232 serial converter. If you try that program using a serial converter it makes things very easy to do.

Now if you want to pursue this with +/- 12 Volt logic then consider a DC to DC converter since you already have 24 VDC powering your sensor. Find a DC to DC converter from a distributor which takes 24 VDC In and Outputs +/- 12 VDC or even 15 VDC.

Ron
 

Thread Starter

flyingsock

Joined Oct 21, 2017
16
1. Use a 78L12 to decreases the voltage from +24V to +12V.
2. Use the +12V to provides the CMOS 555 as TLC555(ICM7555) and Build Your Own Negative Voltage Generator using CMOS 555.
I overthinked a bit.
Fair enough, when the sensor detects a box it will output 24V, which will be reduced to +12V and fed into the oscilator.
The oscilator keeps a square wave in C1, and due to coupling a negative voltage will remain constant in C2.
Finally we have -12V (a bit lower) to input into the serial port. YAY.

OK, SO now consider the sensor is not detecting a box anymore. There's no voltage being input in the oscilator, so C2 will start to discharge.
BUT as long as the negative voltage remains in C2 and is lower than -5V, the serial port input will still be receiving a logic high.
Serial port input impedance ranges around 4.3K.
Theoretically, the time of discharge of a capacitor is equal to 5 time constants.
t=R*C=4.3K * 3u = 0,43s. Discharge time = 5*t = 2,15s. That means 2,15s in a faulty state.
That's too much. I'm not even considering that C1 discharge might make this time longer.
Consider that there will be a box being detected every 2s.

Possible solutions: decreasing the value of the caps and also using a voltage divider somewhere so the final output is a little closer to -5V, and so the discharge will reach a safe value (>-5V) faster.
Is that right? What could possibly go wrong? (apart from everything)

Solution 2: as the 2nd sensor's output (NC) will also be input into the serial port (only via a simple regulator +24V to +12V) I could use logic to overcome this. Like...
i1 i2 result
0 0 0 (sensor is off)
0 1 0 (sensor on, not detecting)
1 0 1 (sensor on, detecting a box -> PRINT LABEL)
1 1 0 (sensor on, not detecting, but caps haven't discharged)

Thanks a lot!
 
Last edited:

Thread Starter

flyingsock

Joined Oct 21, 2017
16
Let's say that you successfully get compatible voltages. How are you going to then get the information from the serial port on the PC? Do you have the ability to bit-bang the individual pins?
I managed to get it from Ron. I can do it.

The idea being is that if you convert to simple TTL levels things become much easier. In your other thread, which I linked to in this thread, the example I gave you used a simple USB to RS 232 serial converter. If you try that program using a serial converter it makes things very easy to do.

Now if you want to pursue this with +/- 12 Volt logic then consider a DC to DC converter since you already have 24 VDC powering your sensor. Find a DC to DC converter from a distributor which takes 24 VDC In and Outputs +/- 12 VDC or even 15 VDC.

Ron
The problem is, I can only get +24V from my sensor's output. So converting it 5V will only get me a 0 low logic level into the serial port, I still need a minus something to input a high logic level.
... Or I probably did not understand what you meant.
 

ScottWang

Joined Aug 23, 2012
7,409
I overthinked a bit.
Fair enough, when the sensor detects a box it will output 24V, which will be reduced to +12V and fed into the oscilator.
The oscilator keeps a square wave in C1, and due to coupling a negative voltage will remain constant in C2.
Finally we have -12V (a bit lower) to input into the serial port. YAY.

OK, SO now consider the sensor is not detecting a box anymore. There's no voltage being input in the oscilator, so C2 will start to discharge.
BUT as long as the negative voltage remains in C2 and is lower than -5V, the serial port input will still be receiving a logic high.
Serial port input impedance ranges around 4.3K.
Theoretically, the time of discharge of a capacitor is equal to 5 time constants.
t=R*C=4.3K * 3u = 0,43s. Discharge time = 5*t = 2,15s. That means 2,15s in a faulty state.
That's too much. I'm not even considering that C1 discharge might make this time longer.
Consider that there will be a box being detected every 2s.

Possible solutions: decreasing the value of the caps and also using a voltage divider somewhere so the final output is a little closer to -5V, and so the discharge will reach a safe value (>-5V) faster.
Is that right? What could possibly go wrong? (apart from everything)

Solution 2: as the 2nd sensor's output (NC) will also be input into the serial port (only via a simple regulator +24V to +12V) I could use logic to overcome this. Like...
i1 i2 result
0 0 0 (sensor is off)
0 1 0 (sensor on, not detecting)
1 0 1 (sensor on, detecting a box -> PRINT LABEL)
1 1 0 (sensor on, not detecting, but caps haven't discharged)

Thanks a lot!
Do you have a schematic or block diagram which including the uC part(DB9 or DB25), black box and PC part(DB9 or DB25), and the timing diagram(mS, uS) of the output of sensor, the duty cycle of pins 8 (CTS) and 6 (DSR)?
 

WBahn

Joined Mar 31, 2012
30,088
I managed to get it from Ron. I can do it.



The problem is, I can only get +24V from my sensor's output. So converting it 5V will only get me a 0 low logic level into the serial port, I still need a minus something to input a high logic level.
... Or I probably did not understand what you meant.
It sounds like you can support power, since you are talking about considering a DC-DC converter. If so, the why not power something like a MAX232 and feed it the sensor signal and let it generate the RS-232 levels. They only cost a couple bucks and only need a single 5 V supply. They generate +/- 7.5 V signals. You then just need to reduce your sensor voltage levels to the supply you are using for the MAX232. Depending on the speed of the signals you are looking at, that can be done with a simple resistive voltage divider or a suitable zener diode and a resistor.
 

Thread Starter

flyingsock

Joined Oct 21, 2017
16
Do you have a schematic or block diagram which including the uC part(DB9 or DB25), black box and PC part(DB9 or DB25), and the timing diagram(mS, uS) of the output of sensor, the duty cycle of pins 8 (CTS) and 6 (DSR)?
Sorry, I don't have it.
I'm using a DB9/DB9 cable which I cut in half to expose the wires as "uC".
Thanks.
 
Top