Modifying DCC++ for multiple power districts

crusader27529 Aug 19, 2016

  1. Keith Ledbetter

    Keith Ledbetter TrainBoard Member

    279
    195
    12
    Dan is it possible to start a github with the info? Very interested in this as it also solves my Frankenstein hookup currently with the IBT2 drivers. I probably wont use all 8 districts but even having a clean ibt2 hook in with right sized code on a nano seems worth it.
     
  2. Softec

    Softec TrainBoard Member

    27
    9
    6
    @Keith,

    I know just enough about github to be dangerous. I will try to learn more on setting up an account and post information there. In the mean time I will post everything here.

    I am very early in the breadboard stage and am happy with initial progress on the multiple power district portion of the project. Not as happy with the block monitoring portion.

    The plan is to have multiple Nano’s around the layout, each with a 15-18v power supply and up to four motor driver boards. The DCC signal will come from an Arduino Mega head-end and will be distributed to the Nano power districts over cat5 cable. The Nano’s will only provide block power protection/control and gather block status. This will be transmitted to the Mega over RS485. I was hoping to do block detection with the motor driver board but so far it does not appear to have the low current resolution to detect occupancy. If I cannot resolve this the backup plan is to use current transformers but not happy with initial results either.

    @crusader

    In your description you indicated a test to determine the length that the DCC signal could be sent without the RS485 signal switch. Did you ever perform those tests and if so what were the results?
     
  3. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    No, because the rs485 modules I use are so rediculously cheap. With the 'smart' remote controllers, they don't return the actual current signal, but an artificial signal that's either obvious to be an overload or not. Since the signal is a TTL logic compaible siugnal with extremely low bandwidth, I tested that it worked fine at 60' plus.
     
  4. Softec

    Softec TrainBoard Member

    27
    9
    6
    @crusader, thanks for the feedback. I have tested the DCC++ signal over a 50ft length of Cat5 cable and see no noticeable degradation of the signal. See the signal trace below. The blue trace is the source; the yellow trace is at the end of the cable. Small spikes are evident at the leading edge of the square wave but I suspect that 100ft will be possible without a problem. I will test that later.

    On another note, I am using the IBT-2 H-Bridge (BTS7960) as the motor driver for each power district / block. While the DCC++ function has been excellent, the current monitoring function has been extremely inconsistent. The R_IS and L_IS signals rarely scale properly or even work at all. This has led me to use Current Transformers (CT’s) for both over current detection and block detection.

    Testing on small 5A, 1000:1 CT’s has been very good. I can reliably detect occupancy and trip on overcurrent. I have a spreadsheet to predict proper values for the settings. The readings are fairly linear.

    https://www.ebay.com/itm/5A-Sensor-...e=STRK:MEBIDX:IT&_trksid=p2057872.m2749.l2649

    BTW, the burden resistor values indicated in the ebay listings are often wrong. They say 100ohm, the image of the resistor is 1000ohm and the ones I received are 200ohm.

    I am using raw readings from the Arduino Analog to Digital Converter (ADC). This removes any necessity of conversion to current which requires the use of the floating point library, all values are either INT or LONG (size reduction and speed of processing increase). The NANO will forward the raw ADC readings to the head end MEGA for scaling and display of current.
     

    Attached Files:

    vasilis likes this.
  5. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    do you have a circuit diagram available for the usage of the CTs instead of relying on the CS pins on the IBT_2?
     
  6. Softec

    Softec TrainBoard Member

    27
    9
    6
    Attached is the breadboard layout for the entire NANO power district The CT’s use a voltage divider to offset the positive and negative voltages to a 2.5v base line. It is based on the following discussion.

    https://openenergymonitor.org/forum-archive/node/156.html

    I will be posting the spreadsheet for the CT’s and Arduino sketch this evening.
     

    Attached Files:

    vasilis and Atani like this.
  7. Softec

    Softec TrainBoard Member

    27
    9
    6
    Attached are the CT calculation spreadsheet and the Sketch for the NANO.

    The sketch monitors the output of the Power District (PD) CT’s takes appropriate enable, disable action and outputs to an RGB led its status.

    LED off, Power District OFF.
    Green LED, Power District ON.
    Blue LED, Power District OCCUPIED.
    Red LED, Power District TRIPPED.

    The sketch is setup to monitor up to four PD’s however only one is used for the proof of concept breadboard

    Right now the NANO will detect a trip and disable the circuit for 2.5 seconds. When re-enabled if the trip still exists it will Lockout the PD. I am contemplating an auto reset of the Lockout after a longer time period, otherwise it will have to reset by the head end MEGA.

    None of the communication routines are programmed at this point.
     

    Attached Files:

  8. vasilis

    vasilis TrainBoard Member

    110
    39
    10
    This is a very interesting topic. I'm returning to it often. A lot of aspects about the PD handling and a lot of food for thought.
    Crusader, thanks for sharing your work and ideas though I have some "objections" :p.
    The "low-fat" DCC++ command station having the abillity to control more locos, is very nice, but imho, has to stay a command station without the control of the power districts.
    I like Dave Bodnar's booster as a standalone device. It has a display that shows it's status and I think that is usefull for the troubleshooting. I didn't understand why he didn't put a low pass filter before the current sensing pin, but it is easy to add it. The powerfull h-bridge gives the oportunity to handle short circuits and overcurrent with an arduino and without the stress of self-triggering. Also the auto-reversing is an easy thing to add with only 2 xor gates and an arduino pin. The booster lacks the feature of cut the power to the district and stay on. I'm saying this because I find the daisy chain boosters a good solution for the dcc signal transmission. The DCC signal from the DCC++ CS goes to the first booster and the booster' output to the next. The boosters who are controlling reversed sections has to be bypassed. Off course the transmition of the PWM signal through the rs-485 or maybe better(?) through the synchronous rs-422, is a better alternative and in this case there is no need the booster to stay on. It is a must to have a central control of the boosters and the PDs, but as I said before I woudn't add it as a part of the CS. It is a must to have a central control of the boosters and the PDs, but as I said before I wouldn't add it to the DCC++ CS. I think that limits the whole idea of the PDs and its portability. The centralized remote control of the PDs boosters can be done through the rs-485 with a simple protocol. The boosters arduinos will be the slaves and the arduino for the PDs control will be the master. The master polls each slave and receives it's status and can control each booster. This way the “multiple power districts” are limited only by the rs-485 max nodes and can work with any DCC CS.
    Of course it’s just my point of view and not a demand. :>)
     
  9. vasilis

    vasilis TrainBoard Member

    110
    39
    10
  10. Softec

    Softec TrainBoard Member

    27
    9
    6
    Sorry for the delay in responding, I have been on vacation, or “on holiday” as our friends in Europe tend to say.

    Yes, I have verified the IS signals with both a volt meter and a scope (see attached images, each with a 200ohm load at 18volts =90mA). The schematic’s I have seen (attached) show all resistors as 1K, the actual IBT-2 boards have either 10k or a mix of 10K and 30K resistors (see pictures). This is just two random boards selected from a batch of 20 I have. I believe the reason these are so cheap ($6.51 per board) is these did not pass QC. They seem to work ok for my application, DCC++, but I don’t trust the IS signals and have chosen to go the CT route. Also my design uses the CT signal for both block detection and short circuit protection. The multiplier used in the IBT-2 provides for a 5 volt signal at the full 43 amp rating of the board (VIS = (IL / 8.5 A)V from the BTS7960 datasheet, based on a 1K resistor). At the 20mA level for detection the IBT would provide a signal of 0.002 volts well below the resolution of the Arduino 10bit ADC.

    20190727_064143.jpg 20190727_064200.jpg
     

    Attached Files:

  11. Softec

    Softec TrainBoard Member

    27
    9
    6
    Here is the most recent version of my prototype Multi-District controller. This prototype is only two blocks, the final version will be four blocks. I have decided to use CMRI at the protocol over RS485. Starting on the communication routines.
    nano proto.jpg PD2 Prototype.jpg PD4 Proposal.jpg
     
  12. vasilis

    vasilis TrainBoard Member

    110
    39
    10
    Thanks for the extended answer. A lot of info.
     
  13. vasilis

    vasilis TrainBoard Member

    110
    39
    10
    I'm just letting here two thoughts. One is about rectifying the current sensor output, so there is no need for multiple reads and averaging.
    The second is about the reversing the ibt-2 output with an arduino pin and two xor gates.
    CT SENSOR rectif.PNG xor reversing PWM to IBT-2.PNG
     
    Erik84750 likes this.
  14. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Hi Softec,

    would it be possible to upload a schematic of this multi-district controller; it is virtually impossible to deduce one from the fritzing drawing you made; even a handsketched drawing will do as long as pin numbers and component identification is visible?
    Thanks,
    Erik
     
  15. Softec

    Softec TrainBoard Member

    27
    9
    6
    Erik,

    Here is a quick copy of the schematic. I can post the eagle files if desired.
    This is part of a modular DCC++ / CMRI system i am building for my layout. I have most of the system designed and prototype boards build and am in final testing.

    Dan
     

    Attached Files:

  16. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Hi Dan,

    this is great; such a neat and superbly documented project! I came in late for the show, but it is very much worth it. If it is ok with you, I will develop Eagle files for SMD and a Pro Mini, and publish them here (.sch, .brd and .lbr).

    Since you work with C/MRI you might have seen this 24 in / 48 out Arduino C/MRI emulator board by nopxor?

    Grts,
    Erik
     
  17. vasilis

    vasilis TrainBoard Member

    110
    39
    10
    Hi Dan,
    I don't understand the need of 74ls04 not gates. In my previous upload I use two xor gates to reverse the pair of PWM and (INV PWM) controled by an arduino pin. The pair of outputs ms1,ms2 can feed an IBT-2 if I want to act as auto reverser.
    An xor gate acts as "repeater" when one input is constantly low and as a not gate when the one input is constantly high. So in my scheme the xor1 gate is either a repeater or not gate according the input from the arduino. The xor2 gate acts constantly as a not gate and inverses the signal from xor1.
    An additional xor gate have to be used as not gate, to obtain the inverted signal for all the other IBT-2's that they don't need to act as autoreversers.
    So for each ibt-2 I want to act like autoreverser (controled by arduino pin) I need a pair of xor's, and one xor to invert the PWM for all the other common boosters.
     
    Erik84750 likes this.
  18. Softec

    Softec TrainBoard Member

    27
    9
    6
    Vasilis;
    Regarding the 74LS04, the signal I receive from the DCC++ Arduino MEGA is the raw 5vdc pulse, not bipolar, so the 74LS04 inverts one side of it to create a 5v bipolar pulse to send to the IBT-2’s. The MEGA DCC signal goes through the opto-isolator, 6N137 to isolate it from the MEGA ground bus (caused noise problems).

    Power District #1 can optionally be configured as an AutoReverse through the 74LS86 controlled by pin A2 of the local NANO.

    Erik;
    I am going to take your advice and start a new thread called “DCC++ and CMRI, A Modular Approach” most likely in the “DCC++ & Electronics” root level. I will set it up this weekend and copy and consolidate the relevant portions of this thread to it.

    Yes I did see the 48/24 port board from nopoxor. I think additional sources of CMRI related hardware are great! CMRI is a proven interface and protocol supported by NMRA and JMRI.
     
    Erik84750 likes this.
  19. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Next to Vasilis' comments I would add the following:
    1. if you want to use a current transformer, it would be more efficient/faster/cheaper to rectify its signal (as proposed by Vasilis a bit higher here) instead of sampling by an ADC. Even better, I had tested the IBT-2 booster and its current sense output using David Bodnar's design, the only thing required was to adjust the current sense calibration variable in the DCCpp file (somewhere in one of the tabs).
    2. why use a RS485-to-serial converter module if you can do the same with a single MAX485 chip: you could even use a SOP8 variant: virtually no space used, cheaper and more efficient, especially since you design your own pcb.

    Grts,
    Erik

    EDIT: posted this without noticing Dan's reply a few minutes ago.
     
  20. Erik84750

    Erik84750 TrainBoard Member

    334
    134
    12
    Dan, you do not need anything "bipolar": the IBT-2 can be driven straight from an Arduino without making anything "bipolar"; see here for proof of concept (and working well too).

    Grts,
    Erik

    [​IMG]
     
    Last edited: Dec 27, 2019
    vasilis likes this.

Share This Page