Author Topic: DCC++ HAT (Raspberry Pi)  (Read 10784 times)

0 Members and 1 Guest are viewing this topic.

kiwi64ajs

  • Posts: 7
  • Respect: +1
Re: DCC++ HAT (Raspberry Pi)
« Reply #30 on: May 17, 2017, 09:24:01 PM »
0
If I were to switch over to a CAN bus coming off the pi, would it be better to switch to a 32-bit AVR that could run at higher clock speeds and has more peripherals, like a SAM3X, or would I better sticking to something like the mega2560? Would you keep the LocoNet interface on the AVR?

If you do a RPi HAT with DCC++, then the lower risk option is to stick with the Arduino AVR Uno/Mega as it already works. Is there a good reason to change?

Having the DCC++ serial comms to the RPi on a different UART lets you separate the processing logic in the RPI, whereas if you multiplex DCC++, OpenLCB & LocoNet all up the same UART to the RPi then you have to peel that all apart in a single process in the RPi and maybe pass some of it on to other processes. A single RPi process can open multiple serial ports but multiple processes can't easily open the same serial port and help-themselves to only the data they want - something has to peel-it-apart and process it appropriately, so NOT mixing it all up at the source is probably better unless you're trying to reduce BOM costs and your making enough units to justify the increased software complexity.   

Ignoring exactly how (MCP2515 on SPI or a CAN to USB Adaptor), adding a CAN Bus interface that feeds directly into the RPi would be good in that it gets the OpenLCB/LCC data directly where you can do all the heavy-lifting in the RPi RAM / CPU as it will have lots of packet buffering capacity and ability to have RAM consuming look-up tables for PCER Event processing and Logic Evaluation and mapping/translating/gate-way between OpenLCB on CAN/Ethernet/Wi-Fi and other MRR LCBs like LocoNet, XpressNet, NCE Cab Bus etc.

My current thoughts were to develop a small LocoNet interface using the Tiny841 chip as it has 2 x UARTs and pretty much will work now using the ICP Bit-bashed LocoNet Rx/Tx with collision sensing. However, it also has some extra Wake-on-UART-data capabilities that I want to use to sense LocoNet traffic for collision avoidance. That will lets me remove a pile of complicated serial bit-bashing that will reduce CPU load. So we could end up with a LocoNet to UART Adaptor in the Tiny841 and then send that into the RPi. From the RPi perspective it would look like an existing LocoBuffer - problem solved. So this could end up looking like a small LocoBuffer Adaptor PCB with 2 x RJ12 on one side and a 1x6 header on the other side with GND, VCC Tx, Rx, CTS, RTS and look after the tricky LocoNet timing and collision sensing. I also have a few Teensy's as well but AFAICT they lack the Start-detection that Tiny841 has so you'd have to use a hardware interrupt of some kind to detect the LocoNet busy condition.

There was also a question that came up about sticking a small 4-pin header under each of the RJ11 connectors that would do CMRI. Since CMRI only uses RX and TX, it would be a pretty simple interface.

Hmmm... C/MRI uses a unusual "sort-of RS422 but not quite RS485 configuration, which is quite different to LocoNet, so it would not just be a connector change, you'd need different input electronics. If you were just wanting to re-use the PCB realestate then you could probably layout pads for different chips and swap the LM339 for a RS422chip maybe.

Alex

kiwi64ajs

  • Posts: 7
  • Respect: +1
Re: DCC++ HAT (Raspberry Pi)
« Reply #31 on: May 17, 2017, 09:33:42 PM »
0
The big advantage is MUCH more horsepower, but the existing code libraries may need work.  Alex Sheppard can probably weigh in here.

Yup I have an Arduino Due as well in my box of Arduino goodies. It certainly is appealing and capable board/chip with lots of useful peripherals. The main issue is porting the existing AVR-centric logic to the ARM platform. I'm sure it's do-able but will take time. The Due probably has enough resources to handle being a self-contained OpenLCB DCC Command Station - with CAN Bus Interfaces as well as maybe some legacy MRR interfaces as well. For many there would eliminate the additional complexity of developing software to run on Linux that the comes with adding a RPi.

We (not me) recently re-worked my NmraDcc library to use the normal Arduino External Interrupt capability and micros() time functions to do the DCC Signal decoding, which now makes it pretty much portable across many (all?) Arduino variants. I've got it working on the Tiny84/85/841, the AVR Mega's and someone got it working on the ESP8266. I need to try it on the Teensy's but they should just work. I'm looking to change the LocoNet library to have the same portability but it has more challenges.

Ed Kapuscinski

  • Global Moderator
  • Crew
  • *
  • Posts: 26062
  • Head Kino
  • Respect: +11543
    • Conrail 1285
Re: DCC++ HAT (Raspberry Pi)
« Reply #32 on: May 18, 2017, 09:33:38 AM »
0
I just wanted to chime in here and say, while I have nothing to add, I love what you guys are doing. Keep up the great work!

dcutting

  • Crew
  • *
  • Posts: 359
  • Gender: Male
  • Respect: -58
Re: DCC++ HAT (Raspberry Pi)
« Reply #33 on: May 18, 2017, 10:48:18 PM »
0
If you do a RPi HAT with DCC++, then the lower risk option is to stick with the Arduino AVR Uno/Mega as it already works. Is there a good reason to change?

Having the DCC++ serial comms to the RPi on a different UART lets you separate the processing logic in the RPI, whereas if you multiplex DCC++, OpenLCB & LocoNet all up the same UART to the RPi then you have to peel that all apart in a single process in the RPi and maybe pass some of it on to other processes. A single RPi process can open multiple serial ports but multiple processes can't easily open the same serial port and help-themselves to only the data they want - something has to peel-it-apart and process it appropriately, so NOT mixing it all up at the source is probably better unless you're trying to reduce BOM costs and your making enough units to justify the increased software complexity.   

Ignoring exactly how (MCP2515 on SPI or a CAN to USB Adaptor), adding a CAN Bus interface that feeds directly into the RPi would be good in that it gets the OpenLCB/LCC data directly where you can do all the heavy-lifting in the RPi RAM / CPU as it will have lots of packet buffering capacity and ability to have RAM consuming look-up tables for PCER Event processing and Logic Evaluation and mapping/translating/gate-way between OpenLCB on CAN/Ethernet/Wi-Fi and other MRR LCBs like LocoNet, XpressNet, NCE Cab Bus etc.

My current thoughts were to develop a small LocoNet interface using the Tiny841 chip as it has 2 x UARTs and pretty much will work now using the ICP Bit-bashed LocoNet Rx/Tx with collision sensing. However, it also has some extra Wake-on-UART-data capabilities that I want to use to sense LocoNet traffic for collision avoidance. That will lets me remove a pile of complicated serial bit-bashing that will reduce CPU load. So we could end up with a LocoNet to UART Adaptor in the Tiny841 and then send that into the RPi. From the RPi perspective it would look like an existing LocoBuffer - problem solved. So this could end up looking like a small LocoBuffer Adaptor PCB with 2 x RJ12 on one side and a 1x6 header on the other side with GND, VCC Tx, Rx, CTS, RTS and look after the tricky LocoNet timing and collision sensing. I also have a few Teensy's as well but AFAICT they lack the Start-detection that Tiny841 has so you'd have to use a hardware interrupt of some kind to detect the LocoNet busy condition.
 
Hmmm... C/MRI uses a unusual "sort-of RS422 but not quite RS485 configuration, which is quite different to LocoNet, so it would not just be a connector change, you'd need different input electronics. If you were just wanting to re-use the PCB realestate then you could probably layout pads for different chips and swap the LM339 for a RS422chip maybe.

Alex

From that I'm hearing you're talking about bit-banging another couple of UART interfaces on the Raspberry Pi. If that's the case, I'll get moving on the loconet tiny841 setup, moving back to the mega328p for the DCC+ system, and adding an MCP2515 to the board for the CAN system. I'll also add a converter to the board for C/MRI... does anyone have a schematic that I could use for that? I don't know if normal RS232 to RS485 adapter circuits will operate correctly (I've see the MAX232/MAX485 setups, as well as the BOM for the CMRI one), and there's no schematics on the JRI Electronics page.

I think I am going to be able to keep all of the interfaces on one HAT without any board expansions. All components would probably be populated but the connectors will be unpopulated so that the modeler can solder on what they need for their application.

David
David Cutting

railnerd

  • Crew
  • *
  • Posts: 764
  • Gender: Male
  • Respect: +230
Re: DCC++ HAT (Raspberry Pi)
« Reply #34 on: May 19, 2017, 12:49:11 AM »
0
I think I am going to be able to keep all of the interfaces on one HAT without any board expansions. All components would probably be populated but the connectors will be unpopulated so that the modeler can solder on what they need for their application.

So I guess I don't know why you'd want to cram all that stuff on there, when the Raspberry Pi has all those wonderful real USB ports.  I think if you focus on just the DCC++ stuff you have an easier to maintain, less expensive product.  If folks want LCC or Loconet, then they can hook up a USB CAN adapter or Locobuffer.  If you roll your own CAN controller and Loconet interface, you've gotta maintain those and make sure that your micro can keep up and multitask between DCC, LCC, and Loconet.

-Dave


kiwi64ajs

  • Posts: 7
  • Respect: +1
Re: DCC++ HAT (Raspberry Pi)
« Reply #35 on: May 19, 2017, 01:26:00 AM »
0
From that I'm hearing you're talking about bit-banging another couple of UART interfaces on the Raspberry Pi.
No the bit-banging happens on the LocoNet side of the Arduino. The transfers between the Arduino and the RPi would be via a normal UART.

The Tiny841 has a new "Start Detection" status flag in the UART to indicate that it has started to receive a byte. I'm hoping to use this a a new "LocoNet Busy" state detection. Then I can eliminate the current Bit-Bashing that's happening in the Mega328 (or any AVR to date) or at least create a new version of the LocoNet interface to use the Tiny841 UART and greatly simplify the Rx/Tx code.

EXCEPT - BIG SURPRISE FOR ME - there looks to ONLY be 1 hardware UART on the RPi 40 Pin header. As that's already being used for the DCC++ Arduino, I now wondering if there is any real point adding the LocoNet to the PCB. We'd probably be better off just using USB like a normal LocoBuffer USB.

I guess we could have interfaced the Tiny841 to the RPi via I2C as the Tiny841 does have I2C Slave capability in hardware but I've never used that before. We'd want to also have an extra pin to indicate RX Data Ready to the RPi so it can know when to read the LocoNet data from the Tiny841 without constant polling of state. Probably want a Tx Buffer Empty pin as well so the RPi can check if the LocoNet  Transmit buffer is empty before it tries to send another packet.

I'm fast loosing interest in this RPi device as any kind of gateway device due to the lack of UARTs. The BeagleBone Black has CAN, multiple UARTs and I2C & SPI on it's headers. It also has 2 extra Programmable Realtime Unit (PRU) CPUs for doing timing sensitive stuff like the DCC Command Station output. Some of the other OpenLCB guys have built a Command Station based around the BBB type of chip/device.

If that's the case, I'll get moving on the LocoNet Tiny841 setup, moving back to the mega328p for the DCC+ system, and adding an MCP2515 to the board for the CAN system. I'll also add a converter to the board for C/MRI... does anyone have a schematic that I could use for that? I don't know if normal RS232 to RS485 adapter circuits will operate correctly (I've see the MAX232/MAX485 setups, as well as the BOM for the CMRI one), and there's no schematics on the JRI Electronics page.

Details about one of the modern replacements for the C/MRI technology can be found here:

     http://www.modelrailroadcontrolsystems.com/cpnode-version-2/#cpNode_Documentation

I think I am going to be able to keep all of the interfaces on one HAT without any board expansions. All components would probably be populated but the connectors will be unpopulated so that the modeler can solder on what they need for their application.

Makes sense.

The lack of extra RPi UARTs is quite a dampener for me. You started with DCC++ on the UART, MCP2515 on the SPI. That only leaves 1 other SPI channel as there are 2 CS (Chip Select) lines for SPI and the I2C port for interfacing. Maybe you just stick to the original DCC++ and CAN... ;) 

Alex

dcutting

  • Crew
  • *
  • Posts: 359
  • Gender: Male
  • Respect: -58
Re: DCC++ HAT (Raspberry Pi)
« Reply #36 on: May 19, 2017, 01:46:34 PM »
0
So I guess I don't know why you'd want to cram all that stuff on there, when the Raspberry Pi has all those wonderful real USB ports.  I think if you focus on just the DCC++ stuff you have an easier to maintain, less expensive product.  If folks want LCC or Loconet, then they can hook up a USB CAN adapter or Locobuffer.  If you roll your own CAN controller and Loconet interface, you've gotta maintain those and make sure that your micro can keep up and multitask between DCC, LCC, and Loconet.

-Dave



True, good point. I could work on some USB interfaces to get the cost down on those... the current devices are exuberantly expensive. I understand that you have to have a USB to serial bridge, but still...

This brings up another point. Why should this thing even be a HAT? A USB interface would be better, especially if many modelers will use old laptops. Seems to me that putting the DCC++ controller onto one PCB that has a USB on it would be better. I could imagine that the serial line needed could even be hooked up to a bluetooth expansion module so that you could have remote booster stations or base stations. USB to loconet, USB to OpenLCC, and USB to CMRI all have existing interfaces but I think that redesigning those with a bluetooth module option would be a viable opportunity in the future.

If I create a 5A DCC++ booster station all integrate onto a single PCB, I think I will have accomplished what I started. And we don't have to mess with the Rpi mini serial port and the lack of others.
David Cutting

kiwi64ajs

  • Posts: 7
  • Respect: +1
Re: DCC++ HAT (Raspberry Pi)
« Reply #37 on: May 19, 2017, 09:10:28 PM »
+1
This brings up another point. Why should this thing even be a HAT? A USB interface would be better, especially if many modelers will use old laptops. Seems to me that putting the DCC++ controller onto one PCB that has a USB on it would be better. I could imagine that the serial line needed could even be hooked up to a bluetooth expansion module so that you could have remote booster stations or base stations. USB to loconet, USB to OpenLCC, and USB to CMRI all have existing interfaces but I think that redesigning those with a bluetooth module option would be a viable opportunity in the future.

If I create a 5A DCC++ booster station all integrate onto a single PCB, I think I will have accomplished what I started. And we don't have to mess with the Rpi mini serial port and the lack of others.

Hmmm... well I've also got a Arduino Due https://www.arduino.cc/en/Main/arduinoBoardDue ;)
It has lots of RAM (96k), FLASH (512k), I/O 4 UARTS, 2 I2C, 2 CAN, SPI and lots of PWM and Analog-in etc. The only negative is the absence of any on-board EEPROM. There is the ability to emulate it somewhat with FLASH but it doesn't survive a firmware upload. We could use external I2C/SPI EEPROM and cache the values in RAM.

The DCC++ firmware appears to really only rely on EEPROM, 2 Timer/PWM outputs driving the DCC Signals for Main Line and Programming Track and some and Analog Inputs for current sensing. It would take some effort to port it to run on the Due but probably not too much. The result would be a fairly extensible Command Station and lots of CAN and UART interfaces to interface to the different Legacy MRR Systems.

dcutting

  • Crew
  • *
  • Posts: 359
  • Gender: Male
  • Respect: -58
Re: DCC++ HAT (Raspberry Pi)
« Reply #38 on: May 19, 2017, 09:47:26 PM »
+1
Hmmm... well I've also got a Arduino Due https://www.arduino.cc/en/Main/arduinoBoardDue ;)
It has lots of RAM (96k), FLASH (512k), I/O 4 UARTS, 2 I2C, 2 CAN, SPI and lots of PWM and Analog-in etc. The only negative is the absence of any on-board EEPROM. There is the ability to emulate it somewhat with FLASH but it doesn't survive a firmware upload. We could use external I2C/SPI EEPROM and cache the values in RAM.

The DCC++ firmware appears to really only rely on EEPROM, 2 Timer/PWM outputs driving the DCC Signals for Main Line and Programming Track and some and Analog Inputs for current sensing. It would take some effort to port it to run on the Due but probably not too much. The result would be a fairly extensible Command Station and lots of CAN and UART interfaces to interface to the different Legacy MRR Systems.

I'm not totally against that. Where I am starting to see the issue is that many modelers aren't going to use OpenLCC. Some will use Loconet. Others will use C/MRI. Building a huge, expensive board that will easily cost $100 without even considering the Raspberry pi doesn't seem like the best way to go.

Here's what I've come up with on my side (I'll probably have to start a new thread because this clearly isn't a HAT  ;)):

https://github.com/cescalemodels/BaseStationHAT/blob/master/Hardware/BoosterHC%20HAT%20V1_0.pdf

The new base board is pretty simple, yet it should be pretty powerful. It's got the normal ATmega328P with an FT232RL USB to UART interface. I put a mini USB connector on the board so you can connect it to your computer. In addition, I added an FTDI header. You can toggle back and forth between the FTDI and the USB connection with a 2x3 right angle header and a pair of jumpers that I put on the board. The USB and FTDI interfaces are optically isolated, and the 5V line has a 500mA fuse on it to protect your computer.

I added the FTDI header to interface with bluetooth. You should be able to get one of Sparkfun's bluetooth sticks that has an FTDI header on it (https://www.sparkfun.com/products/12576 or https://www.sparkfun.com/products/12580) and plug it straight in to the board, then control it from your laptop/raspberry pi 3/etc.

The issue that I see, after the fact, is that you might need to hook this thing up to OpenLCC or what have you to run another block/booster station. I'm thinking that for this, I could create, essentially, an OpenLCC bus to FTDI converter board with an AT90CAN128. A different board could connect to loconet or C/MRI. Another type of board could hook up to the DCC bus and repeat that signal (autoreverser?). Is this viable, or even wise?

Going back to the Due... if the due costs $50 already, why wouldn't you just spend an additional $10 and buy a beaglebone black, which would make for a pretty epic feature set.
David Cutting