ATMega328P Communication with PLC using optocouplers

Hi all,

I know this topic has been discussed before, but i was having a hard time wrapping my head around circuit design with optocouplers and wanted some feedback. Also wanted to be sure this would work with the PLC i am currently using. Also I hope this post is in the right category.

I am in the process of designing a custom ATMega328P-based PCB(5V) that needs to receive and send discrete digital signals to a PLC(24V). I will be communicating with this DL05 PLC from automation direct: https://cdn.automationdirect.com/static/specs/d005dr.pdf

I am using EL817(c) optocouplers: https://www.mouser.com/datasheet/2/143/EVER_S_A0008471837_1-2548735.pdf

below is the schematic that i have so far:

The notes indicate which sub-circuit is for the receiving of signals and which is for the sending of signals to and from my PLC and ATMega328P. The ATMega328P sub-circuit will be powered by 5V and i will receive 24V from the PLC power supply, but these two supplies need to be isolated. The signals from and to the PLC need to operate on 24V. The output from the PLC is a sinking output. The PLC can receive a sinking or a sourcing input. (i believe for the circuit up above it will be sinking input).

For receiving a signal from the PLC:
This will be a 24V signal going to a 5V signal. I aimed for 10mA to go to the LED. with Vf = 1.2V(1.4 MAX), i calculated a resistor value >2200Ohms, the max CTR = 400%(for the c version of the EL817) i settled on 2.7kOhms because the ATMega328P input can handle a max of 40mA input. With the max CTR, the ATMega328P will see a max of 33.6mA. Also i included a reverse voltage diode between pin a1 and 2 of the optocoupler to protect the PLC. Questions for this portion: 1. Is the LED portion and the collector/emitter version of the optocoupler wired in a way that when the 24V PLC signal is high i will get a 5V high signal on the D0_PLC channel? 2. is the current-limiting-resistor the correct resistance? 3. is the reverse voltage diode needed?(for the each circuit really)

For Sending a signal to the PLC:
This will be a 5V signal going to a 24V signal. Again, i aimed for 10mA going to the LED. With a 5V signal, i calculated a resistance value >360Ohms. With the max CTR of 400%, that would mean that 40mA would be output and headed for the PLC. According to the data sheet for the PLC, a 'ON' signal needs >5mA @ 10V. Will this output from the optocoupler alone be able to switch the PLC input signal on? or do I need some kind of transistor circuit? like the one below:
image

I again have a reverse voltage diode to protect the ATMega328P. Questions regarding this: 1. the above question regarding the transistor. 2. Am i correct to say that the above is a sinking input? 3. is the current-limiting resistor values correct for this sub circuit? 4. is the wiring correct?

Any input would be greatly appreciated.

Best,
KE

The ATmega328 OUTPUT can safely source or sink 20mA, 40mA is the absolute maximum and should never actually be used.

The inputs are extremely high impedance and effectively draw no current.

  1. The diodes D1 and D2 are not needed.
  1. Is the LED portion and the collector/emitter version of the optocoupler wired in a way that when the 24V PLC signal is high i will get a 5V high signal on the D0_PLC channel?

No, the optocoupler output to the ATmega will be LOW, as the phototransistor will be conducting. Correct for that in the ATmega328 code by detecting LOW == PLC output HIGH.

    1. is the current-limiting-resistor the correct resistance?

A 2.7K resistor connected to a 24V source will provide about 9 mA to the LED, which is more than enough to activate the phototransistor.

With the max CTR of 400%, that would mean that 40mA would be output and headed for the PLC. According to the data sheet for the PLC, a 'ON' signal needs >5mA @ 10V.

In that configuration, the optocoupler output does not source current. It can only sink current, and you must obey current specs on the optocoupler data sheet. 50 mA absolute maximum phototransistor collector current for the ELB17 optocoupler; 25 mA is safe.

Will this output from the optocoupler alone be able to switch the PLC input signal on?

The optocoupler controls the base current of the KTC3875 transistor, which in turn can only sink current. The current source is the 24V power supply. What you have there looks wrong, as there is no current limiting resistor in the KTC3875 collector circuit. Given that the KTC3875 transistor is rated for 150 mA maximum collector current, that circuit would burn out the KTC3875 transistor almost instantly.

I strongly suggest to look for more reliable interface designs.

1 Like

Thank you for the response. I think i need to understand sinking and sourcing current better. is your comment about a more reliable interface more directed to the use of the transistor? or would you recommend using something instead of optocouplers? Either way, do you have any recommendations i can look into for a more reliable design?

The design you posted will immediately self destruct. I'm sure that other people have posted better designs, which would not self destruct.

A transistor is not required, if the optocoupler ouput is rated for greater than 24V, the required current and power dissipation.

Thanks Doug,

That makes the sinking and sourcing concept more clear.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.