Hi - I am back on my model train control project after walking away from it for 4 months ie. I have forgotten everything I had research last year !!!!
** I am not undertaking this to find a simple solution, I want to learn more about electronics, coding and design and I'm using this project (for my Dad) to achieve this**
I am going back to basics trying to work out how I communicate between modules I am going to be building. I have a requirement for a LOT of I/O and had previously looked at, and prototyped, shift registers and the various MCPxxxx devices looking to expand I/O with decent current sink capability.
I am going to look at using the NXP PCA9698 which gives 40 I/O controlled via I2C and with the ability to sink 1100mA which is perfect for what I'm doing. When I originally looked at this I worked out that noise over extended I2C or SPI connections was going to be a problem along with fanout issues with large numbers of shift registers or MCPxxx devices. RS485 was ruled out because I wanted to be able to have any device talk on the wire and allow the hardware to handle arbitration.
I am going to try and prototype Teensy 3.2 MCU's, talking to NXP PCA9698's via I2C using CANBus to talk between the Teensy's as show below (more Teensy's and more NXP PCA9698's per Teensy in the actual project):
This diagram just shows I/O - I will have more CANBus connected Teensy's doing PWM for speed control and MOSFET lighting control but the idea is similar to the above.
My problem at present.... working out a 'simple' messaging format for use over CANBus.
Everything I find on the net searching for "arduino canbus", "teensy canbus" etc relates to integrating with motor vehicles.
Thinking about message ID length - 11bit ID's would be plenty for my use case, but do I break up the 11bits into a message 'type' as well as represent a source device ? I know CANBus is a message driven architecture ie. it doesn't matter where the message comes from or is going to - it is a broadcast message. The lower the ID the higher the message priority but why would one Teensy have a higher priority message tha
Refer to the diagram above - lets say SWITCH A triggers an input on a PCA9698, this in turn would cause the Teensy #1 to generate a CANBus message and broadcast it, Teensy #2 should see a message, process it and turn on an LED.
Now..... this is where I get stuck.... What is Teesny #2 looking at to decide whether or not to do something ? Is it based on the 11bit message ID or it is looking at the 8 bytes of data and looking for a 'message type' (would be a part of my little protocol)? If we split up the 8 bytes into, say, byte 1 telling it that it is an I/O frame (vs a speed control frame, or a lighting frame etc etc) and the following 7 bytes describe what should happen next - time of output, type of output (flashing, dim, steady etc) . If I did this then every CANBus node would be looking at every packet and that could be thousands per second.
Should a CANBus message only describe an event that has happened ? Thinking about a car... I press the door lock button, a message is probably sent on the 'body bus' stating the button has been pressed, a door lock solenoid then triggers based on the message and everything thing else on the bus ignores the message as it is not relevant to anything else but the door solenoid. How is that achieved - how do other MCU's ignore the door lock message ? By message ID ? By something in the 8 byte data field defining a message type (door lock type) or by something else ?
The next issue is if an inout on Teesny #1 needs to trigger an output on Teesny #1 - does it send the CANBus message to itself ? Can it read a message sent to itself ? Or do all inputs have to be on one Teensy and all outputs on another ?
Given the 'messaged oriented' architecture of CANBus what is the best way to get started thinking about the Teensy's communicating - I am trying to move my mind away from point to point based messaging ie source / dest addresses and think more about messages and message types.
I just need some pointers to get started to then go and start prototyping. Any help appreciated !
** I am not undertaking this to find a simple solution, I want to learn more about electronics, coding and design and I'm using this project (for my Dad) to achieve this**
I am going back to basics trying to work out how I communicate between modules I am going to be building. I have a requirement for a LOT of I/O and had previously looked at, and prototyped, shift registers and the various MCPxxxx devices looking to expand I/O with decent current sink capability.
I am going to look at using the NXP PCA9698 which gives 40 I/O controlled via I2C and with the ability to sink 1100mA which is perfect for what I'm doing. When I originally looked at this I worked out that noise over extended I2C or SPI connections was going to be a problem along with fanout issues with large numbers of shift registers or MCPxxx devices. RS485 was ruled out because I wanted to be able to have any device talk on the wire and allow the hardware to handle arbitration.
I am going to try and prototype Teensy 3.2 MCU's, talking to NXP PCA9698's via I2C using CANBus to talk between the Teensy's as show below (more Teensy's and more NXP PCA9698's per Teensy in the actual project):
Code:
+------------------------+
| +------->
I2C | +-------> OUTPUTS
+------------+ NXP PCA9698 | +-------------+
| | | | |
| | +---------------------->+ SIGNAL B |
| +------------------------+ | |
| +-------------+
+---------------------+--+ +------------------------+
| | | <------+
| | I2C | <------+ INPUTS
| TEENSY 3.2 #1 +---------+ NXP PCA9698 <------+
| | | <------+
| | | <------+
+---------------------+--+ +------------------------+
|| |
|| | +------------------------+
|| | | +------> +----------+
|| | I2C | | MIXED INPUTS / OUTPUTS | |
|| +------------+ NXP PCA9698 <--------------------------------------+ SWITCH A |
|| | | | |
|| | +------> +----------+
|| +------------------------+
||
||
CANBUS ||
||
||
|| +------------------------+
|| | +------->
|| I2C | +-------> OUTPUTS
|| +------------+ NXP PCA9698 | +----------+
|| | | | | |
|| | | +------------------------------------->+ LED A |
|| | +------------------------+ | |
|| | +----------+
+---------------------+--+ +------------------------+
| | | <------+ +-----------+
| | I2C | | INPUTS | |
| TEENSY 3.2 #2 +---------+ NXP PCA9698 <---------------------------+ SENSOR B |
| | | | | |
| | | <------+ +-----------+
+---------------------+--+ +------------------------+
|
| +------------------------+
| | +------>
| I2C | | MIXED INPUTS / OUTPUTS
+------------+ NXP PCA9698 <------+
| |
| +------>
+------------------------+
This diagram just shows I/O - I will have more CANBus connected Teensy's doing PWM for speed control and MOSFET lighting control but the idea is similar to the above.
My problem at present.... working out a 'simple' messaging format for use over CANBus.
Everything I find on the net searching for "arduino canbus", "teensy canbus" etc relates to integrating with motor vehicles.
Thinking about message ID length - 11bit ID's would be plenty for my use case, but do I break up the 11bits into a message 'type' as well as represent a source device ? I know CANBus is a message driven architecture ie. it doesn't matter where the message comes from or is going to - it is a broadcast message. The lower the ID the higher the message priority but why would one Teensy have a higher priority message tha
Refer to the diagram above - lets say SWITCH A triggers an input on a PCA9698, this in turn would cause the Teensy #1 to generate a CANBus message and broadcast it, Teensy #2 should see a message, process it and turn on an LED.
Now..... this is where I get stuck.... What is Teesny #2 looking at to decide whether or not to do something ? Is it based on the 11bit message ID or it is looking at the 8 bytes of data and looking for a 'message type' (would be a part of my little protocol)? If we split up the 8 bytes into, say, byte 1 telling it that it is an I/O frame (vs a speed control frame, or a lighting frame etc etc) and the following 7 bytes describe what should happen next - time of output, type of output (flashing, dim, steady etc) . If I did this then every CANBus node would be looking at every packet and that could be thousands per second.
Should a CANBus message only describe an event that has happened ? Thinking about a car... I press the door lock button, a message is probably sent on the 'body bus' stating the button has been pressed, a door lock solenoid then triggers based on the message and everything thing else on the bus ignores the message as it is not relevant to anything else but the door solenoid. How is that achieved - how do other MCU's ignore the door lock message ? By message ID ? By something in the 8 byte data field defining a message type (door lock type) or by something else ?
The next issue is if an inout on Teesny #1 needs to trigger an output on Teesny #1 - does it send the CANBus message to itself ? Can it read a message sent to itself ? Or do all inputs have to be on one Teensy and all outputs on another ?
Given the 'messaged oriented' architecture of CANBus what is the best way to get started thinking about the Teensy's communicating - I am trying to move my mind away from point to point based messaging ie source / dest addresses and think more about messages and message types.
I just need some pointers to get started to then go and start prototyping. Any help appreciated !