ATMega328P Communication with 24V PLC

Thread Starter

KRAZYEngineer567

Joined Feb 12, 2024
7
Hi All,

I am designing a ATmega328P based PCB control board that has a function of sending and receiving discrete digital signals to and from a PLC. The PLC has sinking outputs. The PLC can accept sinking or sourcing inputs.

I want the PCB to output Sourcing (PNP) signals to the PLC. (mostly because the rest of the switches we use are PNP output prox switches, so to stay consistent)

This is a motor control board and I would like to isolate the signals from the PLC using optocouplers. For the PNP output I used a PNP transistor. The 24V PLC and GND PLC is the PLC's power supply. The 5V and gnd is the power supply that is powering the ATMega 328P

For the output from the PLC, i expect that when the PLC output is LOW, the ATMega328P input is HIGH, when the PLC is HIGH, the optocoupler is activated, and the input on the ATMega328P is LOW. For the input to the PLC, I expect that when the ATMega328 output is LOW, the output of the PNP transistor is LOW, when the ATmega328P is HIGH, the PNP input to the PLC would show HIGH. Will this circuit work as intended?

1709836377933.png

Data Sheets:
PLC: https://cdn.automationdirect.com/static/specs/d005dr.pdf
PNP transistor: https://datasheet.lcsc.com/lcsc/220...*MTcwOTgyNTc2My42Mi4xLjE3MDk4MjU4NDIuNjAuMC4w
optocoupler: https://www.mouser.com/datasheet/2/143/EVER_S_A0008471837_1-2548735.pdf

I greatly appreciate any feedback!
 

panic mode

Joined Oct 10, 2011
2,808
that is a good way to try your output
when opto is on, Vce across the opto's output is small (0.1V). and Vbe of the PNP transistor is also low (0.7V). but you are connecting those two devices across 24VDC supply.

there need to be resistor to limit the current, something like this
1709837594879.png
 

panic mode

Joined Oct 10, 2011
2,808
there is no reason for R4 value to be so low, you would just burn more heat....
PLC inputs draw very little (couple of mA). and most PLC outputs (that you are emulating) are only rated for 100mA. typical loads are rarely drawing more than 40-50mA

you could completely remove it. or better yet, make it larger value like 4.7k. that way you can still check the state of output using multimeter (Even without output being connected to load such as PLC input).
also base resistor could be chosen to get the base current down to something like 0.5-2.5mA. 15-27k sounds good.
etc
 

dendad

Joined Feb 20, 2016
4,496
The extra transistor is not needed.
Just put the opto pin 4 to +24V and pin 3 to the PLC input with the pulldown resistor R4 as it is. That is one of the advantages of the optos, they can be sourcing or sinking just depending on how you hook them up.
 

Thread Starter

KRAZYEngineer567

Joined Feb 12, 2024
7
Thanks both of you guys for the responses!

Panic Mode: does this look more like what you're talking about? are the current limmitting resistor, base resistor and pull down resistor looking better?
1709843909934.png
Dendad: Would it look something like this?
1709844191819.png
Are we sure that this will provide >5mA@10V sufficient for the 'On Current/voltage level' that is cited in the DL05 data sheet? If i can get rid of that transistor, i would be all for it.
 

dendad

Joined Feb 20, 2016
4,496
Assuming it is a 'normal' PLC input, R9 is not needed. 24V can be fed via the opto directly into the PLCC input. And I would think R8 is not needed either.
You could make R7 330R to turn the opto on more.
 

Thread Starter

KRAZYEngineer567

Joined Feb 12, 2024
7
Assuming it is a 'normal' PLC input, R9 is not needed. 24V can be fed via the opto directly into the PLCC input. And I would think R8 is not needed either.
You could make R7 330R to turn the opto on more.
in this context, what would make the plc 'normal' vs 'abnormal'? or what should i look out for that would indicate it is not a 'normal' PLC input?
 

dendad

Joined Feb 20, 2016
4,496
I just had a look at the PLC data sheet...
1709848394406.png
The input can be just a switch as shown, so R8 and R9 are not needed. The opto transistor takes the place of the switch. And as the PLC inputs have bi-directional inputs (back to back LEDs in the PLC input optos), all the inputs can be configured to handle either sourcing or sinking signals, but as the inputs share a common, they must all be the same.
 

panic mode

Joined Oct 10, 2011
2,808
yup... that will work... and it is all you really need.

but if this is not one-off kind of deals, you may want to add diode across the output of the opto to protect it against reverse polarity (mistakes happen) and inductive spikes (if you ever use this to drive a relay or solenoid valve).


1709923390353.png

you may also consider adding some sort of overcurrent protection, perhaps a poly fuse (self resetting). that may not work for low current opto like EL817 (but it would work a treat if you had the external transistor)

1709923956053.png
 
Last edited:

Thread Starter

KRAZYEngineer567

Joined Feb 12, 2024
7
I really appreciate all the help. Very good input, i will consider adding a polyfuse and diode. One last question: would it still work if i chose a different optocoupler. Say the LTV-214? (only because the supplier I'm going through has this one in SMD and also a dual channel version in smd) I know its a bi-directional opto. Comparing the data sheets of the two, the power dissipation specs and output voltage specs are different. But would it work the same? I also changed the output on the optocoupler to the ATmega328P, so that now i am expecting a HIGH output from the opto when the LED is activated. Will this cause any issues? Do i need any current limiting resistor going to the ATmega328P input?
1710010160685.png
Data sheet for LTV-214: https://datasheet.lcsc.com/lcsc/181...*MTcxMDAwODMzMy43MC4xLjE3MTAwMDg2MDQuNTQuMC4w
 

panic mode

Joined Oct 10, 2011
2,808
you could ... but... that is an AC opto (which is fine) but it has very low CTR - the current transfer ratio is only 20%. this is not something you want to use in application like this without adding transistor.
this means to drive load that is 20mA for example, input current would need to be 5x larger or 100mA
i do not think your ATmega output can provide such current levels so circuit would need to be adapted. and that means adding either transistor at the input or better at the output side of the opto - which is something you wanted to avoid.

so for digital I/O and switching applications it is much better to use opto with large CTR.
there are also Darlington output types. they have very large CTR. the only downside is that their voltage drop is larger but in your application that does not matter since circuit is using 24V and 1V or so drop is insignificant and common for many sensors (for 2-wire proxy sensors it may be even bigger - up to 3-4V, without issues).
 

Thread Starter

KRAZYEngineer567

Joined Feb 12, 2024
7
Thank you for that breakdown. It was easy to get lost in all the stats for the optocoupler. As far as CTR goes especially. That makes optocoupler selection a lot more clear for me. I think i am going to go with the ISOCOM MOCD207, because i want a dual channel smd one. This one has a CTR of 100-200%. Are you able to tell me where the Collector-emitter Breakdown and emitter-collector Breakdown voltages would come into play? Are those values that you must stay below on the transistor side of the opto?

This optocoupler would probably be more suitable for my switching application right?

data sheet: https://datasheet.lcsc.com/lcsc/191...*MTcxMDE2NDgzMS43MS4xLjE3MTAxNjUzNTQuNjAuMC4w
 

panic mode

Joined Oct 10, 2011
2,808
Collector-emitter Breakdown is BVceo
note this is when positive is on collector and base is not connected (that is the "o" at the end of "BVceo" and it stands for "open" or not connected). This is max voltage or breaking point for this transistor.... do not use this product with such high voltage.
for applications that use 24VDC, you want want this to be at least 30V or higher. so this is ok...

same for BVeco. this means polarity is reversed. components do not like this and this is a good way to damage them fast. for MOCD207 this is 7V. higher values will likely destroy it. so it is safe to probe the transistor using DMM for example (diode test or continuity) as the test voltage in DMM is normally never above 3V. if you have an old analog meter, it may use higher voltage on some ranges and that could be destructive of course. a good way to protect against reverse voltage is to use antiparallel diode. (cathode to collector, anode to emitter of the NPN transistor). This way even if voltage is reversed, diode will conduct and clamp that voltage to 0.7V... or die trying....

consider you product and BVce0=80V, so it is safe to use the device in 24VDC circuit. easy right...?

also max current is 50mA so as long as you are sure it stays bellow those 50mA you should be fine...

so you say no problem, lets use it to drive some load that is only 30mA. great...

so you hook up scope and you turn everything on. you play with the load and then opto dies. you check the scope and see that output voltage was 14V at the moment optocoupler died so what happened? 14V is not that much, and the 30mA is also within limits....

well.. those individual limits are fine... but there are other limits too...

since the supply is 24V, and output was allowed to drop to 14V, the difference of 10V is across the output of the opto. dissipated power here is Pd=V*I so even if current did not change, Pd=10V*30mA = 300mW, and it happens to be double of what the optocoupler is rated for.

lesson is - all of the values must stay within safe limits (and all the time)
not JUST current... or JUST voltage... or JUST current and voltage...
 
Top