Author Topic: Simple Pic Network  (Read 5070 times)

0 Members and 1 Guest are viewing this topic.

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 121
  • Country: be
Simple Pic Network
« on: January 24, 2015, 04:55:58 pm »
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?
 

Offline jaxbird

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Simple Pic Network
« Reply #1 on: January 24, 2015, 05:10:00 pm »
You could implement a simple Token Ring like network using UART.

Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline BlueBill

  • Regular Contributor
  • *
  • Posts: 169
  • Country: ca
Re: Simple Pic Network
« Reply #2 on: January 24, 2015, 05:41:43 pm »
I2C comes to mind, or RS485 / 422 if you want distance and noise immunity.
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 121
  • Country: be
Re: Simple Pic Network
« Reply #3 on: January 24, 2015, 07:51:30 pm »
How far does I²C go?
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: Simple Pic Network
« Reply #4 on: January 24, 2015, 10:00:50 pm »
as Jaxbird typed ....Serial UART ring token ... screened wires should be  OK at 5v TTL level
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 121
  • Country: be
Re: Simple Pic Network
« Reply #5 on: January 24, 2015, 11:22:51 pm »
as Jaxbird typed ....Serial UART ring token ... screened wires should be  OK at 5v TTL level

So 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?
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: Simple Pic Network
« Reply #6 on: January 25, 2015, 10:07:44 am »
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..
« Last Edit: January 25, 2015, 10:17:57 am by 22swg »
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 121
  • Country: be
Re: Simple Pic Network
« Reply #7 on: January 25, 2015, 12:14:22 pm »
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5313
  • Country: gb
Re: Simple Pic Network
« Reply #8 on: January 25, 2015, 12:27:18 pm »
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.
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 121
  • Country: be
Re: Simple Pic Network
« Reply #9 on: January 25, 2015, 01:22:23 pm »
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) 
« Last Edit: January 25, 2015, 01:36:30 pm by conducteur »
 

Offline jaxbird

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Simple Pic Network
« Reply #10 on: January 25, 2015, 01:53:02 pm »
as Jaxbird typed ....Serial UART ring token ... screened wires should be  OK at 5v TTL level

So 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?

Yes, 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 queue
C: 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. 

« Last Edit: January 25, 2015, 02:13:29 pm by jaxbird »
Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline conducteurTopic starter

  • Regular Contributor
  • *
  • Posts: 121
  • Country: be
Re: Simple Pic Network
« Reply #11 on: January 28, 2015, 10:14:08 pm »
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?
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
Re: Simple Pic Network
« Reply #12 on: January 29, 2015, 01:47:19 am »
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.
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: Simple Pic Network
« Reply #13 on: January 29, 2015, 10:10:30 am »
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 .
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline jaxbird

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Simple Pic Network
« Reply #14 on: January 30, 2015, 09:14:45 pm »
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?

Wouldn'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.

Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline Pack34

  • Frequent Contributor
  • **
  • Posts: 753
Re: Simple Pic Network
« Reply #15 on: January 31, 2015, 12:28:49 am »
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
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: Simple Pic Network
« Reply #16 on: January 31, 2015, 10:42:06 am »
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.   
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf