DCC++ Hardware - Motor Shields

KE4NYV Jan 25, 2016

  1. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    one thing I am not sure about in reading the code and in selecting a higher current H-Bridge, forgive my lack of DCC knowledge, but how does DCC++ read back CV settings through the H-Bridge? just wondering.

    ~Travis
     
    Scott Eric Catalano likes this.
  2. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    DCC++ sends a packet to the decoder requesting it to pulse the motor which increases the power consumption for a fraction of a second. This power consumption is read by DCC++ via the current sense pin.
     
    Scott Eric Catalano likes this.
  3. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    ok, thanks. I will shop for a current sensor as well... I have some 30A bidirectional sensors, like http://www.ebay.com/itm/121686377854
    they split Vcc at around 2.5V. lower is reverse flow current, and above is forward flow current. if I alter the analogRead() statement in the CurrentMonitor::check() function (CurrentMonitor.cpp) from analogRead(pin) to (analogRead(pin) - 512) then it should shift the current reading down, though it may lose a tiny bit of resolution from the full 10-bit. that will get me about 0.05859375A per step. I don't think 6 hundredths of an amp is scarifying too much resolution. I plan on running HO. I just have to find an H-Bridge at a decent price. it will have to be separate H-Bridges for each track circuit, as otherwise I couldn't use my current sensors.

    Anyway, I am rambling, so I will do a little browsing for the H-Bridge.

    ~Travis
     
    Scott Eric Catalano likes this.
  4. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    Scott Eric Catalano likes this.
  5. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    I think I remember some posts about that particular device, I will look them up again. it did look simple, with just a simple transistor logic inverter for it to work in, IIRC, locked antiphase configuration. I think it even has onboard current sensing on the IS1 and IS2 pins.

    This was after all the H-Bridge I was leaning toward, anyway. I found a datasheet here http://www.robotpower.com/downloads/BTS7960_v1.1_2004-12-07.pdf

    Thanks for the input :)

    ~Travis
     
    Scott Eric Catalano likes this.
  6. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    Yes, this board does provide current sense. the small modifications necessary for this board can be found on @David Bodnar's website: http://trainelectronics.com/DCC_Arduino/DCC_Booster/index.htm To use the board as your primary motor board you would need a couple of these, one for PROG and one for MAIN.

    The approach I will be taking is using an arduino clone motor board to power my helix and PROG tracks and couple of the 43A boards to power the upper/lower decks of the rest of the layout. I will be using software to trip the "over current" condition around 5A rather than 43A that the board supports. I am in the process of reworking the DCC++ base station code to support multiple motor boards (or power districts if you want to think of it that way). I should have something usable in the next few days. I just got my 15VDC/15A power supply in the mail and am in the process of wiring it up with a voltage/amperage meter for each channel. I should have that wired up later today and be able to test at least the helix and PROG tracks (waiting on the 43A boards to get here still, eta of Sat for delivery)
     
  7. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    Thanks for the link, I have just saved it as a bookmark.

    The multiple motor boards idea sounds interesting. I look forward to experimenting with the results.

    right now, for a power supply for experimenting, I am using a 40A camper converter/charger, and a large battery for smoothing and power fail storage. it actualy powers several projects at the moment, but I think it should be clean enough to experiment with DCC++. I put a scope on it and it surprisingly has very little ripple. I know this is a little weak in the volts for HO, but I think it will work for experimenting alright. I ran my Athearn GP38-2 with it a while back in DC mode (haven't made the conversion on it yet), and I think it went plenty fast. even if it was on old 1970's brass track.

    my only gripe, other than all I have right now is brass track, is that my loco is a different coupler height than my fathers old Tyco (I think) rolling stock. I found an old style plastic coupler, but then I found the height was wrong anyway. but on the plus side, I have a fine running loco. :)

    I figure, once I get the DCC++ going, and have converted my loco over, then I will have to find some better track real cheap. I have been tempted to buy some sections of EZ-track style off eBay, just to have something.

    ~Travis
     
    Scott Eric Catalano likes this.
  8. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    I just bought 2 of the IBT-2 motor driver boards, and I eagerly await for their arrival. :)
    maybe with my next paycheck I can afford a DCC conversion for my GP38-2.
    According to http://www.tcsdcc.com/Customer_Cont...s/HO_Scale/Athearn/GP38-2/Athearn_GP38-2.html
    I need TCS MC2 decoder. as I don't need sound yet, it is plenty for my loco.

    Then, all I will need is some decent track, really really cheap. eBay isn't really forthcoming on this front.
    But anyway, just updating on my progress thus far.

    ~Travis
     
    Atani and Scott Eric Catalano like this.
  9. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    I use the same MD board for the main track output, but use a MD that has the L298 chip for the program track, which works just fine with the standard DCC++ code. I haven't tried the 43A board for the program track for 2 reasons....first, the way it reports current is very different than the boards with the L298 chip, and I didn't want to deal with modifying code to detect the very low current used for acknowledgement from the decoder when responding to reading the CVs......it may work, but it may not. I guess you'll let us know. The second reason is that the program track is supposed to be used to 'test' the initial hookup of the decoder, and SHOULD be current limited, so errors won't be catastrophic. With the power that the 43A board delivers, that's problematic.

    The manual and schematic for the MD board I use is attached, along with the 43A schematics.......both require the inversion of one of the MD signals as per Dave Bodner. I decided to use one 74LS04 chip to do the inversion function, because wiring 2 transistor inverters versus one 14-pin chip was simpler. Everything else was the same as Dave did, and it works just fine.
     

    Attached Files:

  10. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    I forgot one important detail about how I hooked up the program MD board......the board has no onboard resistor to develop a voltage that the Arduino can use to sense current, but has the outputs on the L298 tied to ground (to complete the current path) with removable jumpers. I removed the jumpers and connected the non-ground end to an external 15 ohm resistor. the other end of the resistor is tied back to the ground side where the jumper was removed, completing the current path......the non-ground end of the resistor is then connected to the current sense for the DCC++.
     
  11. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    I have a SeeedStudio L298 shield, but it doesn't seem to like operating on a breadboard for custom wiring. I will look into that one you suggested for my program track.

    any idea what the current output on the IBT-2 boards scale to? are they 0/1023=0A/43A. if so, I can use a different analog reference on the Arduino to change the precision. if for example, I use a 3.3V reference, it would be about 28.38A full scale. or if I go further down, and use a 1.1V internal reference (Arduino MEGA 2560 only), then IIRC, it will drop the full-scale precision down to about 9.46A, if I did my math right. so if we have a 9.46A full scale, then each ADC step is about 0.009A.

    as the second IBT-2 is already ordered, I can always use it for either a booster, or a backup. but while I have time I will try again with my motor board and see if I can figure out how to get it running on a breadboard. I think it has a sneaky circuit somewhere that only works if plugged into the Arduino.

    ~Travis
     
    Scott Eric Catalano likes this.
  12. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    The BTS7960 based boards (the 43A boards) don't use a resistor in the current path to sense the current, but output a proportional voltage based on current draw. The basic design uses a 1K resistor in the design, and the data sheet has the values for using a 1K resistor. Exactly how to 'adjust' DCC++ current sense to calibrate for current is something I haven't been able to figure out.

    Dave Bodner said that the default parameters would cutoff about 5A, and had some other values that he used for 8A+ cutoff. Since there seems to be only one adjustment for overcurrent in the code, obviously that'd also affect to program track.

    Work is being done to allow for multiple driver boards with individual cutoffs when overcurrent, and individual values for the boards, but if all the boards except for the program track were the same, different values most likely wouldn't be needed.....
     
    Scott Eric Catalano and sboyer2 like this.
  13. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    I have wandered around the code for DCC++ for a few days now. not much else to do when I am home from work all last week due to tonsillitis from Strep. I am not 100 percent that I can adjust current sensing correctly, but I will make a copy of DCC++, and when I get my IBT-2 boards, I will play around with it and see what I can produce.

    ~Travis
     
    Scott Eric Catalano likes this.
  14. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    Hope you feel better soon! I just got my IBT-2 boards on Thurs and connectors yesterday (the connectors i had for 8pin were in single row, settled on back to back 4pin since i couldn't find a single set that was only 8 pins).

    My plan for building this into DCC++ is create a couple types of CurrentMonitor classes that have board specific logic in the check method. For the IBT-2 I plan on leveraging code similar to @David Bodnar's code which scales the sense pin using a 10k POT (I will use a POT to get a close enough value for 5A-10A and have a flag of sorts to set the limit). Using this approach we should be able to use the existing logic for Arduino/Pololu boards and different logic for IBT-2 (if necessary).
     
    Scott Eric Catalano likes this.
  15. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    What about using the map() function to scale the current, and then a fixed gain multiplier, and the constrain() function to limit the output? then it would just be a task of figuring out the values for each board, and entering them into the config file. this should make it scalable for most any board.

    ~Travis
     
    Scott Eric Catalano likes this.
  16. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    I have done some code-diving, and I don't see that DCC++ reports the actual current anywhere. it just uses the raw ADC value, (though it is smoothed).
    what about adding a command to the code that reports the actual current via the serial interface? it could be added transparently, so that JMRI still reported as it needed, but for custom interfaces, it would be neat (the geek in me says so) to be able to read the actual current.
    For the IBT-2, it states "VIS = (IL / 8.5 A)V", with a 1K resistor. my interpretation is that if it is outputting say, 3V at the current sense pin, then the current draw is about 25.5A. so, we (or maybe just me) need to convert the ADC value to amps. so the line in CurrentMonitor.cpp:
    current=analogRead(pin)*CURRENT_SAMPLE_SMOOTHING+current*(1.0-CURRENT_SAMPLE_SMOOTHING);

    could be:

    current=(((analogRead(pin)*CURRENT_SAMPLE_SMOOTHING+current*(1.0-CURRENT_SAMPLE_SMOOTHING)) * (5.0/1024)) * 8.5);

    and current now stored the amp draw from (pin). or have I made a math error?

    ~Travis
     
    Scott Eric Catalano likes this.
  17. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    I wasn't sure how/what Dave did with the 10k pot in the circuit, but it'd probably be more reliable to stick to the design of the hardware in use.....the smoothing logic for current sense wasn't designed to work with the way the BTS7960 chips work. If I was up to the c++ programming task, I'd redesign the current sense for use with the BTS7960 chips, and leave the logic for the L298 chips alone.

    I've always thought that the original code was kind of a kludge in the current monitoring area....it would make more sense to take multiple samples and simply average the results, but the code as written may just do that already......I just don't understand what the code actually works. It's far from obvious, at least to me.
     
    Scott Eric Catalano likes this.
  18. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    ok, so the way I interpreted that is there needs to be some code to identify what board chip is in use, and affect only the portions needed for that board, per channel (main vs. prog track). that way, the older Arduino MD and the L298 MD code will remain exactly the same, and is only used if one of those boards are on that channel. but if a BTS7960 based MD is used, then that channel gets the appropriate config value so that it can process current correctly. is that what you are saying?

    as for the smoothing it currently has, I agree that it kind of baffles me as to how it works, exactly. I'm no mathematician, but it looks like it may be a faster approach to smoothing. so maybe the multi-sample and average approach may not be fast enough. I did see a averaging approach that used a circular-buffer that may be fast enough. rather than take 10 samples, then average, it uses a progressive average by first filling a circular buffer (array), and updating the oldest value with the current value, and averaging that.

    as far as still being able to read CV on the programming track, I see in the code the threshold above the smoothed current reading is only 30. so if we alter what board is used for the programming track, we just have to adjust the gain enough to assure that the sensed current bumps above 30. we can over-shoot this and it will still work, as long as the lower threshold falls below 30.

    am I right, or am I just talking out my ***? sometimes things seem so easy in my head.

    ~Travis
     
    Scott Eric Catalano likes this.
  19. crusader27529

    crusader27529 TrainBoard Member

    247
    167
    11
    Except for the part about a difference between the main and program track, you're correct. The code for over-current monitoring shouldn't differentiate between the function, just on the type of MD board and the specified max current value.

    Any averaging of current would need to take only one sample each time the function was called or else the check would take too long.......timing is very inmportant in DCC signal generation. Maybe leaving the smoothing stuff alone and just allowing for different tuning parameters would suffice?

    #define CURRENT_SAMPLE_SMOOTHING 0.01
    #define CURRENT_SAMPLE_MAX 300

    These parameters would need to be tuned for different MD boards and current limits.....Dave Bodner's stuff said that the MAX value had to be increase to 500 or so to get 8A from the BTS7960 based 43A board.

    In any case, I'd be careful changing the operation of the code that could affect timing. Just having multiple parameter sets for different MD boards and current values seems the easiest AND safest way to make it all work.
     
    Scott Eric Catalano likes this.
  20. Travis Farmer

    Travis Farmer TrainBoard Member

    352
    320
    14
    as I am still waiting for my BTS7960 based MD boards, all I am doing now is studying the code and throwing out ideas. when I get them, I will likely use one for my layout, with a L298 based MD for my Prog track, and use the other BTS7960 MD I ordered for a little R&D setup. that way I don't compromise my as-yet-to-build layout. besides, if I screw up a CV setting on the R&D track, I will need to be able to put it onto the known good Prog track to reset the CVs.

    (quoted from a ways up)
    I just noticed, I forgot to ask. on that 15 ohm resistor, what power level did you use? I assume a standard 1/4W resistor is insufficient?

    ~Travis
     
    sboyer2 and Scott Eric Catalano like this.

Share This Page