How to connect 2 MCU (ATMEGA328p) over cat5 30m wire using PC123 Photocoupler ( low frequency 1hz digital pin on / off ).

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

Thread Summery (save you some reading time):

 

I would like to thank everyone for the great help :-)

 

It seem like something I thought to be simple (dc slow signaling over long wires) got too complex for my knowledge and skills to implement.

Normally we deal with small DC circuits of few centimeters, dealing with DC circuits size of house (20m) is a different game.

the RS485 seems to be the correct approach, the only *drawback with ATMEGA328p is that it has only one Rx/Tx usart which I am currently using for debug tracing.

(*drawback - you can use any available pin on the MCU for simple "high" / "low" signaling transmission)

 

There are many types of RS485 and they differ in the level of protection, isolation, bit rate etc. 

The following MAXIM "parametric search" url is an interactive online page that ease the task choosing the correct RS485  IC (I haven't choose one yet)

http://para.maximintegrated.com/...

 

Note: before you attempt to implement a RS485 network you should read the "Guidelines for Proper Wiring of an RS-485 (TIA/EIA-485-A) Network" by maxim.

http://www.maximintegrated.com/e...

 

Note, that I am still curios to understand how to protect the following components:

1. output pins - solution seems to involve "protected MOSFETS". there are many kinds and it is not easy to choose.  (attached schema for output pin using RFP30N06LE N-Channel MOSFET)

http://bildr.org/2012/03/rfp30n0... (example)

https://www.sparkfun.com/datashe... (datasheet)

2. Input pins - solution seems to involve diodes ( zener, TVS, ESD ), capacitors and resistors. (attached schema for "high" and "low" inputs from the digikey docs)

http://www.digikey.com/en/articles/techzone/2012/apr/protecting-inputs-in-digital-electronics

http://www.atmel.com/images/doc1619.pdf  - (AVR040)

3. power supply and regulators (the wire loop). 

Seems like methods used to protect "input pins" and "output pins" can be used to protect the "voltage regulator" inputs and outputs.

 

Interesting project "The Ruggeduino" by Rugged Circuits:

http://www.ruggedcircuits.com/ru...

 

If there is an expert on forum that can share detailed schema for each item (1,2,3) it will be grate :-) thanks.

 

Thanks

TechSgin

 

 

How to connect 2 MCU (ATMEGA328p) over cat5 30 meter wire using PC123 Photocoupler ( low frequency 1hz digital pin on / off ).

 

Notes:

1. Each MCU have it's own regulated voltage 3.3v.

2. low frequency 1hz digital pin on / off.

3. using PC123 Photocoupler (can order any other part)

 

I have ordered several PC123 Photocoupler and read/watched several papers and videos in regards.

 

Open Questions (I still have):

 

1. the PC123 seems to have 5KV spike protection but for which direction (I need to protect both the input MCU and the output MCU) ?

      a. led -> transistor

      b. transistor -> led

      c. both (will simplify my design).

 

2. Does my design really effective ? ( against ESD (Electrostatic discharge) , RF static noise ? )

see attached design image.

 

Sharing with you A cool optocoupler hack:

 

I have read about a cool optocoupler hack using a "green led ~540nm", "GL55 Series Photoresistor (540 nm 5k-50K ohm) " and sealed heat shrink.
*It not a proper solution and need to be protected as well but still cool idea

 

I have attached the design I made.

 

Datasheets:

GL55 Series Photoresistor ( 540nm Spectrum peak value )
see:
http://akizukidenshi.com/downloa...

 

540nm is "Pure Green" Led
see: LED Color Chart
http://www.theledlight.com/color...

 

Regards

TechSgin

Attachment(s): 

This topic has a solution.

Last Edited: Sat. May 23, 2015 - 05:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to AVRFreaks.

 

Leaving aside your questions about ESD protection... how do you expect the receiver side to work? The emitter is pulled to ground via a 10K resistor. What pin is to detect the incoming data? Prove it to me...

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

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

An optocoupler gives you galvanic isolation, not ESD or EMC protection. Besides, where does the 3V come from? Is it isolated from both the micros? Otherwise the optos do very little for you.

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

Hi Ross

 

Many thanks for your time and efforts.

 

I will add some info:

* The communication required is only one way, i.e. MCU1 is always the transmitter and MCU2 is always the receiver. 

* When MCU1 Transmit "high" it will be seen as "low" by MCU2 at the receiver side.

 

pseud flow: 

MCU1 (transmitter) -> OPTO1 (led - transistor) -> Isolated wire loop with 3v or higher -> OPTO2 (led - transistor) -> MCU2 (receiver) 

 

When MCU1 generates "high" then OPTO1 led lights-up and open the gate\base of the transistor connected to CAT5 3v "wire loop". 

When the CAT5 3v "wire loop" is "high" OPTO2 led lights-up and open the gate\base of the transistor connected to MCU2 which is connect to the ground i.e. MCU2 see "low".

the same chain take place when MCU1 generates a "low" where MCU2 will see "high".

 

pseud code of MCU 1 (transmitter) and MCU 2 (receiver): 

 

 transmitter code:

 // set pin as output

 DDRC |= (1 << PC3);

 PORTC |= (1 << PC3);

 // set start state to low

 PINC &=  ~(1 << PC3);

 

 while(1)

 {

    // transmit high (will show as low on the receiver)

    PINC |=  (1 << PC3);

    // wait for 1 second

    delay(1000);

     // transmit low (will show as high on the receiver)

    PINC &=  ~(1 << PC3);

    // wait for 1 second

    delay(1000);

 }

 

 receiver code:

 // set pin as input 

 DDRD &= ~(1 << PD2);

 // pull up pin ( input  )

 PORTD |= (1 << PD2);

 

 while(1)

 {

    if ( PIND &  (1 << PD2) )

    {

      // transmitter mcu is low

    }

    else

    {

       // transmitter mcu is high

    }

 }

 

p.s :

 My knowledge is at high school level and I am 40 years old :-) 

 I have only one hour a day after midnight to play with my project.

 leaved in Melbourne for about 6 months and it was great fun.

 

Many Thanks

techsgin

Attachment(s): 

Last Edited: Thu. May 21, 2015 - 02:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many thanks Kartman.

 

Most chances Is that you have better knowledge than mine to determine the level of isolation this schema provides and still based on the PC123 datasheet:

 

" Applications

I/O isolation for MCUs (Micro Controller Units)

Noise suppression in switching circuits

Signal transmission between circuits of different potentials and impedances

Over voltage detection...

          ...High isolation voltage between input and output ( Viso(rms) : 5.0 kV... "

 

does "Noise suppression" and "High isolation voltage" doesn't mean ESD ?

 

pc123 datasheet: see: http://sharp-world.com/products/...

 

as for the 3v, they come form a regulator that I will need to protect as well (thanks for that). (any ideas ? recommendation, design may be diodes ?  )

 

Regardless any design you can suggest will be a great help. I am fighting with this for a very long time :-) ( each time I wait for the parts order to arrive and figure that i am wrong :-) )

 

Thanks TechSgin

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I'm not a sparky.  Indeed, our designs often have optocouplers on input circuits.

 

For transmission, you haven't made it clear what the aims and requirements are of your design.  In particular, is isolation required or not?  Also, is this one-way or bidirectional signal?

 

For that slow a signal, and if no isolation is needed, then just use a decent drive transistor or MOSFET or similar?

 

Anyway, we put a lot of RS485 into our industrial AVR8 apps to talk to remote modules and such.  We pick transceivers with decent ESD protection and haven't seen problems with that.  The differential nature of the RS485, properly biased and properly terminated and using the twisted pairs of the CAT5 properly, should give very good to excellent noise immunity.

 

If you really need isolation, then we have a few applications where we used isolated RS485 transceivers.  More costly but do the job nicely.

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

Or just RS232 ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Info: Midi data transfer is 31250 kBit and max 15 Meters. Lower data rate is more Meters !

 

Link: http://www.personal.kent.edu/~sb...

 

Greetings Rolf

 

 

Windows 10 Home 64Bit, ASUS M4A89GTD-PRO/USB3, AMD Phenom II X6 1055T, Ram 2x 4GB, SSD Samsung EVO840 250GB, SATA HD 2.0TB, NVIDIA GeForce GTX 750

Last Edited: Thu. May 21, 2015 - 03:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi theusch

 

The real project is to reuse an existing CAT5 wiring in side my house ("country side") for simple state sensors like PIR sensors (HCSR501) or reed switches, hall effect sensors etc

Please note I have an MCU (328p) per room and a central MCU (328p) which tells my in which room there is activity (any type). 

 

At the beginning i thought that it is a very simple design but i didnt took into account long DC wires consecrations :-(.

 

What I am looking for is the "long wire loop" design (the MCUs code is already written), If one of you have any suggestion it will be great help, and thanks in advance.

 

 

Thanks TechSgin

 

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

Thanks awneil

 

I have three open issues with the RS232 solution:

1. Wouldn't I still need to protect the MCU pins.

2. The capacitance of CAT5 is 50pF per meter, by wikipedia the RS232 is not recommended for cables longer than 15 meters unless the capacitance is very low 30 x 50pF = 1500pF not sure if that's high or low capacitance for RS232.

3. I like using Rx\TX for debugging and bluetooth. ( not a big deal )

 

thanks

TechSgin

 

 

 

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

one other reason not to use rs232 is that it is "peer to peer" and the relation of my mcu design is many mcu transmiters (rooms) and a single reciver mcu ( central control ).

I think that if i will understand how to protect a single wire loop properly then the idea of dc long wires will be clear for me. Thanks.

Last Edited: Thu. May 21, 2015 - 06:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks about the midi, I have learned a new thing.

Still i belive that midi has the same disadvantages as rs232 has for my project.

RS232 solution:
1. Wouldn't I still need to protect the MCU pins.
2. The capacitance of CAT5 is 50pF per meter, by wikipedia the RS232 is not recommended for cables longer than 15 meters unless the capacitance is very low 30 x 50pF = 1500pF not sure if that's high or low capacitance for RS232.
3. I like using Rx\TX for debugging and bluetooth. ( not a big deal )
4. The mcu relation is one (center pin per room) to many (rooms).
5. I would like to learn how to protect a single long distance dc wire loop as it will give me the better understanding on how to protect mcu pins.

Thanks TechSgin

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

If you want cheap n cheerful whilst being robust, use relays.
With your opto setup, what is protecting the optos? You get a nearby lightning strike and it blows the opto led as its ratings have been exceeded and the sender opto transistor is its rating have been exceeded and probably the power supply as well.
You also need to provide a bit of a load so that stray induced voltages don't wrongfully activate your input. A relay does this by design as well as giving a bit of hysteresis.
For your opto, you would need some resistors and a transzorb on the receiver side. The resistors to limit the current and the transzorb to limit the voltage and give reverse voltage protection to the opto led.
For your receiver code, you need to filter the inputs. At the moment you code can interpret a transient as being on. You need to read the input at a regular interval and keep a count of if it is on or off. This is usually referred to as debouncing. A common interval would be 10ms and at least three times. Industrial controllers might do it 20 times.

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

Good morning Techsgin,

 

I was challenging your basic idea for the receiver interface which I have redrawn below.

 

 

My R9 is the effective pullup resistor within the mega328. Can you see that you have a voltage divider when the transistor is conducting? If we allow you to have a "perfect" transistor with a zero Vcesat voltage, you have in the worst case a 10K/(10K + 20K) voltage divider being presented to PD2. It will not be seen as a LOW because the voltage will never be small enough.

 

I suggest that you make R8 zero ohms (a direct connection to Gnd) and use a real 10K resistor in place of your internal pullup resistor. Only then will you have a chance to detect a low at PD2.

 

Best of luck with your project.

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

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

I would look at NMEA-0183 ,  that short is RS422 with optocouplers.

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

Hi theusch

 

I really enjoyed reading about the RS485 design and history smiley .

It really looks like the perfect/professional solution for "long distance" "multi-point" "low rate" "data transfer" ( I was considering CAN bus in the past ).

One drawback is, that the ATMEL328p have only one Rx\Tx TTL which I am currently using for debug. ( I guess I will need to live with that )

 

1. Open question: which chip / module to buy ? ( I prefer either DIP socket or "ready module" (x10 units) )

 

Maxim RS485 types:

Fault-Tolerant Applications
Space-Constrained Applications
Multiple Transceiver Applications
Low-Voltage Applications

 

http://www.maximintegrated.com/e...

 

Maxim online RS485 selector tool (cool !!)

http://para.maximintegrated.com/...

 

Note, that I am still interested in understanding how to protect a single pin (input and output).

It seems like for output pins the general solution is to use "protected MOSFETS", and again there are many so which one ?

It seems like for input pins the general solution is to use a set of diodes , zener diodes, capacitors and resistors.

 

Official AVR guidelines by ATMEL:
AVR040: EMC Design Considerations
http://www.atmel.com/images/doc1...

 

AVR042: AVR Hardware Design Considerations 
http://www.atmel.com/Images/Atme...

 

Digikey - Protecting Inputs in Digital Electronics

http://www.digikey.com/en/articl...

 

Many Thanks TechSgin

 

 

 

Last Edited: Fri. May 22, 2015 - 09:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Ross

 

Thanks for the pull-up resistors advice, I will consider this in my design if I will not choose RS485.

1. Is there a reason you choose pc110 over pc123 ? (I already have lots on pc123 :- ) )

 

Regards

TechSgin

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

Hi sparrow2 and thanks for your time.

 

I have read about the NMEA-0183 it looks very much like the RS485 and it seems like that RS485 have "ready made" protected versions (still reading about that)

 

the open questions i have with RS485 are:

1. Which one of the available implementation (chips/modules) suite my project ( and are available to order in a reasonable price as I will need x10 ).

2. The ATMEGA328p has only one Rx\Tx port which I am currently using as a trace terminal (debugging).

 

Thanks

TechSgin

Last Edited: Fri. May 22, 2015 - 09:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

techsgin wrote:

Hi Ross

 

Thanks for the pull-up resistors advice, I will consider this in my design if I will not choose RS485.

1. Is there a reason you choose pc110 over pc123 ? (I already have lots on pc123 :- ) )

 

Regards

TechSgin

 

Simple really. The PC110 was available for the drawing... I didn't have the PC123 in my drawing package.

 

Ross McKenzie ValuSoft Melbourne Australia

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

Hi Kartman

 

It seem like something I thought to be simple (dc slow signaling over long wires) get too complex for my skills to implement.

the RS485 seems to be the correct approach.

 

I am still curios to understand how to protect the following components:

1. Protecting output pins - solution seems to involve protected MOSFETS.

2. Protecting input pins - solution seems to involve diods, zener diods, capciators and ressitors.

    http://www.digikey.com/en/articl...

    http://www.atmel.com/images/doc1...  - (AVR040)

3. Protecting (power supply) regulators. 

 

Thanks

TechSgin

 

 

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

One drawback is, that the ATMEL328p have only one Rx\Tx TTL which I am currently using for debug. ( I guess I will need to live with that )

???  If you care to use e.g. an RS485 transceiver for low-speed signalling, there is no reason why it must be connected to an AVR's USART.

 

[In the end over moderate distances, you can probably just use an AVR's digital output as-is and create your pulse just as you might e.g. an active-high LED.  Yes, perhaps use rudimentary precautions on the signal line to protect the AVR pin (and perhaps the other end as well) with e.g. series resistor, small cap to ground between pin and resistor, and perhaps a pair of protection diodes to the rail.]

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.