Simple Pic Network - Page 1
Forum section: electronics / general

author: conducteur
author_rank: Regular Contributor
timestamp: January 24, 2015, 04:55:58 pm
content: I have a similar problem as described in another topic that's currently going on this forum. (https://www.eevblog.com/forum/microcontrollers/microcontroller-mesh-network/)I start this topic, because i have a different setup/requirements...I want to connect my PIC 16F/18F µC together with a "network" (shared bus system?). Max number of nodes? I don't think it will be more than 10... It's for my scale train layout (3m² large). One node is for the control panel, another one for the fiddle yard, another one for the railway station, ...If possible, with PIC16f/18f built-in serial ports without complex extra hardware.Bus-speed doesn't need to be ultra high speed... My idea is to send one byte (4 bit address, and 4 bit command) a data byte and possibly a checksum byte. If the system can transmit 50 of these in a second, that would be enough. (more is better, but not essential).Is this possible in a relatively simple way?

author: jaxbird
author_rank: Frequent Contributor
timestamp: January 24, 2015, 05:10:00 pm
content: You could implement a simple Token Ring like network using UART.

author: BlueBill
author_rank: Regular Contributor
timestamp: January 24, 2015, 05:41:43 pm
content: I2C comes to mind, or RS485 / 422 if you want distance and noise immunity.

author: conducteur
author_rank: Regular Contributor
timestamp: January 24, 2015, 07:51:30 pm
content: How far does I²C go?

author: 22swg
author_rank: Frequent Contributor
timestamp: January 24, 2015, 10:00:50 pm
content: as Jaxbird typed ....Serial UART ring token ... screened wires should be OK at 5v TTL level

author: conducteur
author_rank: Regular Contributor
timestamp: January 24, 2015, 11:22:51 pm
content: Quote from: 22swg on January 24, 2015, 10:00:50 pmSo TX pin node 1 connected to RX pin node 2, TX node 2 to connected with RX node 3? Doesn't that create a lot of overhead?

author: 22swg
author_rank: Frequent Contributor
timestamp: January 25, 2015, 10:07:44 am
content: Conducteur, Not really , I did uart ring with 4 x PIC16F628/7 (in asm ! ) 628 was the MAIN, it sends out serial data to node 1, the message has a node destination byte ( or address all say for a reset command ) node either acts on message and / or sends it on to node 2 etc , possible for all nodes to have same code. also just a 2 wire system , if you wanted to be clever nodes could return status back to the MAIN. Nice project..

author: conducteur
author_rank: Regular Contributor
timestamp: January 25, 2015, 12:14:22 pm
content: Anyone here who tried this:http://www.romanblack.com/blacknet/blacknet.htm

author: Howardlong
author_rank: Super Contributor
timestamp: January 25, 2015, 12:27:18 pm
content: I2C or a MIDI-style daisy chain solution were my first thoughts on this. You should be OK with the distance you're considering.Another option is 1-wire, so for some things you wouldn't even need to supply power. One wire is a bit more complicated in e software than I2C although there's plenty of example code out there. The industrial solution is RS422 multidrop, but I fear it's a little over-engineered for the OP.Maybe 25 years ago or so wasn't there some sort of signalling thing developed that worked over the tracks? That would save you having to add extra wiring. Perhaps the bit rate would be too slow.Is this a write-only protocol or bidirectional? If it's write-only, just a simple UART TX pin is all you need.

author: conducteur
author_rank: Regular Contributor
timestamp: January 25, 2015, 01:22:23 pm
content: Yeah that system is called "dcc", you can decode that with a µC, but only the master (command station is master) can write on the bus.The most important node in the system is the control panel node, if a master is required this node should be the master.When pressing a button or switch or ... this node sends data, then the correct node should react to that command. The control panel should also control the feedback leds. So feedback from al the nodes to the control panel node is important. Communication between different nodes is not important. If required, the master can ask node 1 to send data to the master and then redirect it to the other one...Since DCC is a single master thing, i can't transfer my data over this bus. (or i have to make my own command station, but that's a future project)

author: jaxbird
author_rank: Frequent Contributor
timestamp: January 25, 2015, 01:53:02 pm
content: Quote from: conducteur on January 24, 2015, 11:22:51 pmYes, and then Tx node 3 connects back to node 1 to form a ring. As 22swg said, not much overhead as your messages will be fairly small.A great advantage of this model is that any node can initiate communication with any node, you don't need a master doing polling, so you can implement a more async model where e.g the individual nodes send out status and events regularly.It's very simple to implement, your message format should start with a header containing destination address and sender address.Of the top of my head, it goes like this:When a message is received: (from the perspective of a node)A: You are the destination, you absorb and process the message.B: You are not the destination or the sender, you just push the message onto the Tx queueC: You are the sender, you absorb the message and know the destination doesn't exist.You can then optionally implement a Token, as in only the node holding the token message is allowed to transmit, this can be used for flow control and help solve potential concurrency issues. As in you have the Token, you transmit everything on your Tx queue, followed by the special token message.The token can be created by having a timeout on nothing received for x amount of time. Then wait a random amount of time, still nothing received => create a new token.Edit: on the create token, you also need to send out a token announce message (e.g. token announce: new token ID created by xx node) to prevent multiple tokens.

author: conducteur
author_rank: Regular Contributor
timestamp: January 28, 2015, 10:14:08 pm
content: I think i'll do tests with I²C... I don't trust the method were the message needs to pass in some cases almost all nodes. Is there a way to improve my I2C transmission over (longer) distances? Lowering the pull-up resistors?

author: codeboy2k
author_rank: Super Contributor
timestamp: January 29, 2015, 01:47:19 am
content: A train setup can be quite a distance and there's lots of noise, with lighting, train controls, etc. I wouldn't even try I2C here.In the past I've done I2C about 1 meter and it had trouble; it could have been the cable or the environment, I don't know, I didn't design the board and I did not have a choice in the cables or the environment. I was just coding that board. It was I2C to a 12 digit 7-segment display controller that had an I2C expander and some I2C based latches for the seven segment displays.I started at 400Khz and I had to slow it way down to about 50Khz before I could make it work well. You might have the same problem if you try to use I2C around your train table. My speed issues tell me that it was likely that the I2C maximum capacitance was exceeded.There are also I2C line drivers that you can use that supposedly help but I never tried it.

author: 22swg
author_rank: Frequent Contributor
timestamp: January 29, 2015, 10:10:30 am
content: My serial ring intentionally sent to all nodes and back to main as a error check . There are methods to resend 'lost' packets but I doubt that would be too much of a problem. I2C distances will be a greater problem , you could use a level shift to boost the signal or use a carrier .

author: jaxbird
author_rank: Frequent Contributor
timestamp: January 30, 2015, 09:14:45 pm
content: Quote from: conducteur on January 28, 2015, 10:14:08 pmWouldn't recommend it, but if you've made up your mind, have fun with I2C at "long" distance, I believe you'll discover some issues with signal integrity.

author: Pack34
author_rank: Frequent Contributor
timestamp: January 31, 2015, 12:28:49 am
content: If you need some distance, why not go RS485 or CAN? A simple RS485 transceiver can wire in directly to your PIC's UART or there are some nice CAN over SPI transceivers from microchip that you could look at. The nice thing about the CAN over SPI transceiver is that the chip itself takes care of a lot of the overhead.http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010406

author: 22swg
author_rank: Frequent Contributor
timestamp: January 31, 2015, 10:42:06 am
content: Pack34's RS485 Idea looks made for the job, I have not opened up that muc chapter only long distance serial I did was with 433Mhz.