Seeking tips on interfacing to 24VDC

Go To Last Post
26 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I need to interface an ATTiny841 to an industrial controller that uses 0V - 5V for a logic 0 and 12V - 24V for a logic 1.  To output from the 841 to the controller I'm just planning on using a transistor with the collector connected to 24V (via a resistor, of course) and switch the base from the 841; that'll give me 0V and 24 V.  Inputting from the controller to the 841 is a little trickier, though.  From the 841's datasheet, o low ranges from -.5V to .3VCC, or 1.5V since I'll be running the 841 off of 5V.  A high is 3V - 5.5V (at VCC = 5V).  If I use a 27% voltage divider followed by a 5.1V zener, I can convert the controller's high to a range of 3.24V - 5.1V and the low to a range of 0 - 1.35V.  I may put optocouplers between the 841 and controller which, of course, would change these specs, but the circuit would stay the same.

 

On paper this looks fine, but there's not a lot of margin.  Just wondering if anyone has any tips about this approach, or can provide a better one.  Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure your industrial controller is not using 0-20ma loop?   If so, use a 250 ohm resistor to convert to 0-5v output.

Use 20ma Loop as a search term for find suitable interface circuits.

 

 

Jim

 

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Tue. Jan 5, 2016 - 07:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I assume the industrial controller signal is serial comm's, for feeding into a USART, and not just a status signal, (On/Off, Error, etc.)?

(And, as Jim mentioned, it isn't a 20 mA current loop controller.)

 

You could certainly use an opto-isolator, that could be made to work.

Note that with the low of up to 5 V you would still need to be careful to make sure the LED was off with a low.

Stacking an extra diode or two in series with the resistor and LED might be helpful in this case, and easy.

 

I can always make a project overly complex...

Know that the "24 V" isn't likely to be tightly regulated, and might exceed that value.

Also, in an industrial environment, there might be some extra noise picked up on the line, again making it exceed 24 V.

So, you probably want to attenuate the input a fair bit below just making 24 V map to 5 V.

 

If you used a divide by 10 attenuator on the input, then 24 V maps to 2.4 V.

12 V becomes 1.2 V

5 V becomes 0.5 V.

0 is still 0.

 

If you feed this into a comparator you can set the threshold wherever you wish, say 0.85 V, midway between 0.5 and 1.2 v. 

(The Low and High thresholds)

 

By swapping the inputs to the comparator you can make the signal "true" or "inverted".

 

If you put a 10K pot (5V/Gnd) as the input for one side of the comparator you can use your voltmeter to set the comparator threshold to 0.85 V.

If you put a 20K resistor on top of the pot, (V+ to 20K to pot to Gnd), then the pot's range is only 1/3 of the 5 V input, i.e. 0-1.66 V.

This makes the pot setting much less sensitive to fine positioning, and 0.85 would be about the midpoint of the pot, which is good.

 

One could certainly use a "comparator" chip for this, but for years one often just used a cheap op-amp, especially if another op-amp in the package was being used for other front end signal conditioning.

 

The comparator output can then feed the USART input.

 

If you are good with coding, you could use the Tiny's internal comparator, (still with an external pot to set the threshold), and use the comparator output, either in a polled or interrupt driven mode, to drive a software USART receiver.  That is a lot more work to write and debug, and uses a fair amount of your Tiny's memory, but avoids using an external comparator (or op-amp) chip.

 

JC

 

Edit: Typo

 

Last Edited: Tue. Jan 5, 2016 - 08:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, Jim and JC. Strictly digital signals, though no UART, just a bit I need to be able to read. You gave me a lot to digest, Jim. I'll reply more later (on my phone right now).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess my first thought would be to indeed use the optocoupler on the input, to protect the AVR board.

 

Then the input "scaling" becomes moot, right?  The opto either "trips" to one on the AVR side, or it doesn't.

 

Now, will the opto trip to one at 5V?  Dunno.  [I have people for that. ;) ]

 

Anyway, while

lautman wrote:
From the 841's datasheet, o low ranges from -.5V to .3VCC, or 1.5V since I'll be running the 841 off of 5V.
take a peek at the input hysteresis chart in the datasheet...

Most AVR8 have similar "typical" charts, with a no-man's-land of a couple tenths on either side of Vcc/2.  IMO/IME I'd feel safe at say 2V.  [Side note:  I had an app with analog comparator, and the trip level about Vcc/2.  I actually ended up using pin-change instead of analog comparator, as the ~0.4+V of hysteresis gave fewer "false trips" on a noisy real-world signal.]

 

Oh, yeah -- if only one channel of this, have you thought of using the analog comparator?

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Tue. Jan 5, 2016 - 09:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The opto is an implementation detail; I don't think it's a solution since its input would still have to be scaled. As for the comparator, I thought of that but I'm already planning on using it for something else.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

lautman wrote:
The opto is an implementation detail; I don't think it's a solution since its input would still have to be scaled.

Not in my experience, but I'm not the board designer.  Here is half (4 channels) of one of our 8-input boards, set up for 24VDC input signals.

 

 

What the sparkies will need to comment on is whether the PS2705 will trip or not at ~5VDC.

 

http://www.cel.com/pdf/datasheet...

 

Does this chart imply that it "trips" at about 1V?

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The trip voltage is set by the led forward voltage. Below that, no current flows. You can 'tune' the trip voltage by putting leds in series or a zener diode.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, of course!  The LED in the opto doesn't care what voltage is driving it as long as it's enough for it to conduct, > 1.4V in this case, according to the datasheet.  So, no need for a zener.  Just an appropriate voltage divider.  So, 12/1.4 = 8.6, so an 8.5 divider will convert 12V to just over 1.4 (may want to use 10V instead of 12V to be safe); 24V will be even higher, so still good (as long as the divider limits forward current to < 50 mA).  5V converts to .6, way too low for conduction, so good on the low end, too.  It might still be a good idea to put a zener in there to clamp any transients (something around 30V probably).  Looks like all you guys have on your input is a voltage divider, though I can't tell what the ratio is since some of the resistors have no value indicated.  You may be able to count on a cleaner 24V signal than I can.  Anyway, thanks for showing me the way!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

since some of the resistors have no value indicated

Its written in text at the bottom of the schematic.

 

I suggested a diode or two in series with the opto, Kartman mentioned stacking an LED or two, (i.e. a diode or two).

 

Doing this essential increases the Vforward of the opto, making the voltage divider less critical, and increasing your noise margin.

 

Do the calculations both ways, and you will see.

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, if I raise the opto's Vforward to, say, 4V, and set the divider to .5, a high input will be between 5V and 12V (if I use 10V as my noise floor), which will still trigger the opto, and a low will be between 0V and 2.5V, which won't trigger.  It's not clear to me why this makes the circuit less sensitive to the voltage divider.  In this (admittedly somewhat arbitrary) example, I have lower noise immunity on the low end.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I take it back. I see that by raising Vforward anything less than that will be interpreted as 0.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

do you need to be optically isolated? or is the ground common and the noise limited?

you could use a zener diode of lets say 6,8V in series with a FET or transistor, then with 0-5V the gate/base is not high enough to have the F/T open and with 12V-24V it is fully open.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is a device called a tl431. This might be of use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This rs-232 interface IC may work for you, It can handle +/- 30v input and have an output logic voltage of vcc.

Although the DS14C89AN ic shows it  inverting the logic in the data sheet, you can put the them in series or choose a non-inverting interface ic. 

 

http://www.digikey.com/product-d...

 

 

~William

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just designed a quick logic converter that should suit your needs, depending on your data speed you may have to or can tweak the resistor values. I am not sure of your current limits or speed requirements, but its nice sharp edges in the simulator.

How it works: Q1 has its base held at +5v through resistor R1, the high voltage clock data goes into the emitter of Q1. When Q1's emitter is below 5.5 volts (0-5v logic low requirement) Q1 is turned off.

If Q1 is turned off then R2 pulls Q2's base to ground causing it to turn on and drop the voltage at the R3/Q2 emitter junction to +0.6v.

When the +12-24v logic high voltage is on Q1's emitter this turns Q1 on and puts a high voltage on Q2's base thus turning off Q2 and leaving Q2s emitter to sit at +5v through R3.

The great thing is that there is no inversion of the high voltage logic input to the +5v logic output! 

~William

Last Edited: Wed. Jan 6, 2016 - 09:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

vertamps wrote:

 I am not sure of your current limits or speed requirements, but its nice sharp edges in the simulator.

 

Hmm, does LTSpice not simulate the reverse Vbe Zener ?

There is a fatal flaw in that circuit, that will fry the logic, if you apply 24V in.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

lautman wrote:

...0V - 5V for a logic 0

and 12V - 24V for a logic 1.  

... If I use a 27% voltage divider followed by a 5.1V zener, I can convert the controller's high to a range of 3.24V - 5.1V and the low to a range of 0 - 1.35V... 

On paper this looks fine, but there's not a lot of margin.  Just wondering if anyone has any tips about this approach, or can provide a better one.  Thanks.

That's broadly fine.

You can also work by threshold, the indicated crossover point there is just under 8V, and the curve in #5

This gives a divider of 32.27%, and with +/- 200mV Hyst the switch points are 7.12V and 8.36V, and 5 Vin occurs at 15.5V

24V in needs that Zener you mention, and the values are similar to yours, but 27% has points of 10V and 8.5V, which is maybe marginal for 12V signals.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Adding a resistor to the logic high input of Q1 divides the voltage down to safer levels at +5.6v. 

~William

Last Edited: Wed. Jan 6, 2016 - 09:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

meslomp wrote:

do you need to be optically isolated? or is the ground common and the noise limited?

I like the elegance of this solution, but there's no common ground and the circuit will be physically (though not electrically) attached to a robot, so I'm assuming a lot of noise (haven't been able to characterize it yet); hence the need for isolation.  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
There is a device called a tl431. This might be of use.

 

Thanks, Katman.  Wasn't aware of that.  It's not clear to me from the datasheet what the advantage is in my application.  Maybe I'm misunderstanding something, but the need for a Vref seems like a drawback.  At least with the opto approach it's easier for me to understand what's going on.  ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

vertamps wrote:

I just designed a quick logic converter that should suit your needs, ... The great thing is that there is no inversion of the high voltage logic input to the +5v logic output! 

 

Jeez, vertamps, thanks for all the work!  Simple as your solution is, it's still more complicated, and harder to analyze, than the opto approach.  As long as that works, I think I'll stay with it.  Inverting the logic isn't a big deal in s/w.  Next step is to track down appropriate parts and breadboard it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The suggestion was for a tl431 and an opto. The vref sets your trip point. Just a resistor or two. If you've got some dead PC power supplies lying around, you'll most likely have a tl431 and an opto. These are used to regulate the output voltage. You want the opto to go on at a specific voltage point? This is what it does.

For a non- isolated solution, a lm339 might be useful

Last Edited: Thu. Jan 7, 2016 - 01:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

lautman wrote:

... than the opto approach.  As long as that works, I think I'll stay with it.

 

Opto should work fine. The newer InGaAs opto couplers from eg Toshiba, have more stable temperature transfers.

Toshiba also have multi optos in one package.

The H11L1 is a useful Logic coupler, if you want to include a Schmitt.

 

The Sch above has AC IP optos, (back to back IR diodes) which cost more, but they have natural reverse clamping and you could sneak in some test modes by driving with AC instead of the usual DC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
The suggestion was for a tl431 and an opto. The vref sets your trip point.

 

In that case, what makes the tl431 better than one or two or three diodes?  I guess if I needed a lot of diodes to get the optimal trip point, a single small package would be better.  Using a tl431 would also allow me to easily change the trip point (by swapping a resistor) down the road if that became necessary.  I could certainly see that happening between the time I test with a  breadboard and the time I embed the PCB into the system.  Anything else?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Who-me wrote:

The newer InGaAs opto couplers from eg Toshiba, have more stable temperature transfers.

Toshiba also have multi optos in one package.

The H11L1 is a useful Logic coupler, if you want to include a Schmitt.

 

Thanks, I'll check them out.