DCC++ Hardware - Motor Shields

KE4NYV Jan 25, 2016

  1. H0Guy

    H0Guy TrainBoard Member

    25
    6
    3
    I like the idea of modifying the DCC++ Current Sensing Code to match the values in milliamperes to specific values for different Motor Shields.
    The code also needs to be corrected for the Pololu Motor Shield which uses the same Current Sensing Value as the Arduino Motor Shield which is incorrect.
    A lot of folks struggling with DCC++ and non-Arduino Motor Shields due to Current Sensing issues.
    I will look over you suggested changes in the next week or so and let you know if I see any problems.
     
  2. FlightRisk

    FlightRisk TrainBoard Member

    454
    158
    6
    Thanks. I'm also looking at the last version of Atanisoft's that has a case statement to handle motor boards. I could modify that to add other boards/current sensors and change it to true current. Ironically, it looks like he is doing just that in his ESP32 only program.

    Maybe we should compare notes because there are a lot of variables. Which code base do we start with and what IDE? We could even have 2 versions if necessary, the PlatformIO one and the Arduino IDE version. That isn't a code difference, just folder/formatting one for the different environments.

    The simplest thingfor people (especially non-Arduino coders) would be a sketch that requires one file to change (config.h) to select the motorboard which automatically handles the correct current and just uploads to a board with the Arduino IDE.
     
    Jacekts likes this.
  3. Jacekts

    Jacekts TrainBoard Member

    20
    7
    2
    I agree, having very little knowledge of programming in comparison to whats needed. If its intended for regular guys to use its got to be straight forward and well noted.

    DCC++ while a cheap setup, fails to hail as a great platform, when i don't go seemingly 4 post without people mentioning so many issues and the spider web of who does what with what software when. I'm not trying to crap on anyone, i understand not one needs to use it if they don't feel inclined. I also understand the massive amount of man hours the project has into it already, i appreciate the dedication and wish i understood code better to help.
     
  4. tnt23

    tnt23 TrainBoard Member

    27
    12
    2
    Got the PCBs, will assemble and test shortly.

    photo_2020-03-01_09-45-56.jpg
     
    Last edited: Mar 1, 2020
    vasilis and FlightRisk like this.
  5. Paul1361

    Paul1361 TrainBoard Member

    41
    6
    2
    Just ordered a 200W 200ohm rheostat to create a variable current load capable of up to 10A at 15V. What would be the diagnostic terminal command to get the raw value of off the ADC for current sense? I currently have both a real Arduino motor shield and a IBT-2 and will be happy to share the data obtained to provide mapping for accurate feedback.
     
  6. Paul1361

    Paul1361 TrainBoard Member

    41
    6
    2
    Testing , gathering data, providing DETAILS of problems encountered is VERY valuable.
     
  7. Paul1361

    Paul1361 TrainBoard Member

    41
    6
    2
    This is another place where I see Atani's hard work being so valuable, with his web based interface, I expect that shield variables can be stored in eaither flash or EEPROM somewhere on the ESP32 and read from there at startup and set via web interface or possible custom command station CV. All that then would be needed is a table of values for the different tested and approved motor shields.
     
  8. FlightRisk

    FlightRisk TrainBoard Member

    454
    158
    6
    <c> for "current". An exponentially smoothed value from 0 to 1023 representing what the motor board is reporting to the Arduino. There is no standard, it is all based on how many millivolts per Amp the boards circuitry is designed for. The code in the next DCC++ EX will give you milliamps as well as raw pin reading. For an Arduino motor board, a pin reading of 300 would be around 890 mA. The <c> command is what JMRI sends to DCC++ to give an update once a second or so to the current meter. It only shows that as a percentage. We are going to change that too. But for now, 300 would be around 29% (300/1024)
     
  9. tnt23

    tnt23 TrainBoard Member

    27
    12
    2
  10. Paul1361

    Paul1361 TrainBoard Member

    41
    6
    2
    Well I decided to look at the MAX471 & 472 chip which are EOL and no longer being made. I am also noticing large discrepancies in the output of different shield current sense. I think I am going to throw some time this evening into looking for a long term and cheap CS solution that would provide a stable reference. What I want is a stable .5V per A output which would provide maximum resolution at up to 10A. I will start a new thread for this once I figure out componet selection.
     
  11. FlightRisk

    FlightRisk TrainBoard Member

    454
    158
    6
    We have been doing a lot of testing and discussing on the DCC-EX discord since we wind up chatting in real-time fairly often. The current sense chips and the H-Bridge chips are a big challenge. And as soon as you find a good solution, they discontinue the product. Things like the MAX741 are still available. I don't know if a Chinese company bought up the stock or have cloned that actual chip, but I'm going with those while testing everything else. Did you do any more with your board @tnt23?
     
  12. Softec

    Softec TrainBoard Member

    27
    9
    4
    I have been testing various current measuring devices for my layout. I started out using Current Transformers (5A:5mA) through a voltage divider directly into the analog port of an Arduino. This is very stable when averaged; relatively fast in execution and good resolution above 20mA amps (approx. 1000ohms at 18v). The down side is that I want to use my current sensor for both overcurrent protection and block detection and the block detection is not low enough to be reliable. I then tried sensors base on the INA169 sensor (similar to the MAX471) which had a little better low end resolution but still not enough to be reliable. This limitation is basically because of the 10bit resolution of the Adruino ADC. I then tried connecting these devices through an external ADC at 12 bit and 16 bit over an I2C bus. These devices were extremely slow and the repeatability was poor. Then I tried an INA219, which is a programmable ADC on an I2C bus with and effective resolution of 15bits. When properly configured it does auto averaging at a reasonable speed. I can now get repeatable readings down to 2mA (approx. 10000ohms at 18v). This device has an upper limit of 3.2A so it now acts as both detection and overcurrent protection. Google “ti ina219” for information. I can post the few lines of code required for configuration if desired.


    Dan
     
    Last edited: Jul 24, 2020
    FlightRisk likes this.
  13. Jimbo20

    Jimbo20 TrainBoard Member

    274
    175
    9
    Do you really mean 2 micro amps?

    Jim
     
  14. Softec

    Softec TrainBoard Member

    27
    9
    4
    Sorry Jim, 20mA for the CT's and 2mA for the INA219. I changed the post. Good catch!
     
  15. Kuba

    Kuba New Member

    7
    2
    1
    Since the MAX471 & 472 chips are EOL, maybe it is worth looking towards something from the current production with similar functionality, such as ZXCT1041?
     
  16. Atani

    Atani TrainBoard Member

    1,331
    1,028
    27
    About the only problem with this chip is the 20V limit. NMRA DCC allows up to 24V to the rails.
     
  17. FlightRisk

    FlightRisk TrainBoard Member

    454
    158
    6
    We have been testing all sorts of options. Short of designing something ourselves from discreet components, there is no perfect option. And as soon as there is something that at least works, it is discontinued. If people who are testing could please submit their results either here or email or our discord it would be great if we could coordinate our efforts.
     
  18. Kuba

    Kuba New Member

    7
    2
    1
    Indeed, thanks for signaling this limitation. Being focused on the TT/H0 scale - where the voltages are lower, I forgot about this limitation.
     
  19. Atani

    Atani TrainBoard Member

    1,331
    1,028
    27
    One solution is something line INA219 or INA229 on the h-bridge motor power supply input. This would give you a very accurate reading on the actual current used on the rails and this will cover the voltage range for all scales. A similar component could be ACS712 but there are known issues with this depending on where in circuit it is placed.

    In most cases though the h-bridge will have built in current sense, usually low side current sense, and that usually is close enough to get an idea of usage but may cause problems with commercial boosters when a short occurs since it may not be seen by the h-bridge. It is highly recommended to use high side current sense for OPS track for this reason and almost all commercial offerings are setup in this manner.

    NMRA DCC specifications are silent on this subject.

    Sent from my ONEPLUS A5010 using Tapatalk
     
  20. FlightRisk

    FlightRisk TrainBoard Member

    454
    158
    6
    Hi Paul. I'm ready to take you up on that :) Would you be able to generate a table of currents? We would have a voltmeter on the input to the motorboard (the voltage will drop as we put more current to the board) and then an ammeter connected in series to the input. Check the read current as a baseline and then read the current for a known resistance from 20mA up to 2Amps (or however many Amps the board delivers)
     

Share This Page