Geoff Bunza geoffb

There are many modelers who for various reasons, use DC throttles to control the locos and trains on their layouts. What if you could combine the simplicity of a DC throttle with the sophistication of JMRI control, signaling, sensors, and even WiFi throttles? Yup! WiFi throttles for DC train control! …and what if you could  put such layout control together for less than the cost of an old dual throttle power pack? Interested? Let’s see how it can be done!

_does_DC.jpg 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 3
FrenchSR

Re DC+ and 4 cabs.

Is it possible to use 2 arduino power shields stack on top of each other to create the 4 outputs?

Reply 0
Geoff Bunza geoffb

@FenchSR re: A second power shield

Bonjour FrenchSR (name? nom?)

Quote:

Is it possible to use 2 arduino power shields stack on top of each other to create the 4 outputs?

Theoretically-- yes, but you would not be able to simply insert it into the sockets of the Arduino UNO or Mega2650 together with the first motor shield. In a manner similar to connecting the FET H-Bridge in the article on the first page, the second motor shield would need its power, ground, PWM and Dir connection made independently to the Arduino as the simple pin plug-in's would overlap with the first motor shield. After making separate connections, the second motor shield would then act as CAB3 and CAB4. Ground wires should connected together.

However, exactly like the FET H-Bridge example, there would be no monitoring for short circuits or excessive current drain. So be careful. You could easily install circuit breakers or fuses in series to protect the throttle. The original motor shield has a rated current of 2 Amps max, but its thermal cutoff will likely trigger if you use much more than 1.3-1.6 Amps continuously without external cooling.

'Hope this helps.  Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
FrenchSR

2nd power shield

Thanks Geoff. So if one carefully bent the Dxxxxxxx pins used by Cab #1 and #2 out of the way on the second power shield then that's okay. Vin must not go to arduino but all ground pins should be made. Brake links must also be broken.

Regards Richard.

Reply 0
Geoff Bunza geoffb

@FrenchSR rein Use

Hi Robert,

It is slightly worse than that-- any pin or jumpered pin used by the first motor shield or the Arduino would have to be avoided including the current sense pins, the brake (as you pointed out), etc. It might be easier to consider what few pins would be safe to leave attached... like the GND pins!

Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
CardboardNoWheels
Geoff,

Thanks a ton for your work on this and for continually sharing your expertise. I am very excited about this project, as it allows me to add sound to DC locos via JMRI's VSDecoder feature.

As a previous reply mentioned, I too have the problem with motors humming due to the low frequency PWM. I noticed that person also uses an Arduino Mega, like I do. Can anyone confirm this issue does not occur with the Uno? That would be a quick/cheap fix.

Otherwise, has anyone had any luck with increasing the PWM frequency in the few years this project has been out there?

Thanks!
Modeling CNW and EJ&E in N-Scale
Reply 0
Geoff Bunza geoffb
Hi CardboardNoWheels (name?),

You are most welcome.

The default PWM frequency for all pins is 490 Hz, except pin 4 and 13 whose default frequency is 980Hz.
You could first try changing the cab1 PWM pin to 4 or 13 to see if the higher frequency made a difference.
DCCpp_Uno.h has all the definitons for all the DC cab PWM and dir pins.
For the respective pins on a MEGA2560 ONLY Try adding ONE of the following to your setup for EACH respective pin set:
CODE TO CHANGE ARDUINO MEGA PWM FREQUENCY:
Code for Available PWM frequency for D4 & D13:

TCCR0B = TCCR0B & B11111000 | B00000001; // for PWM frequency of 62500 Hz
TCCR0B = TCCR0B & B11111000 | B00000010; // for PWM frequency of 7812.50 Hz
TCCR0B = TCCR0B & B11111000 | B00000011; // for PWM frequency of 976.56 Hz (The DEFAULT)
TCCR0B = TCCR0B & B11111000 | B00000100; // for PWM frequency of 244.14 Hz
TCCR0B = TCCR0B & B11111000 | B00000101; // for PWM frequency of 61.04 Hz
TCCR5B = TCCR5B & B11111000 | B00000101; // for PWM frequency of 30.64 Hz


Code for Available PWM frequency for D11 & D12:
TCCR1B = TCCR1B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz
TCCR1B = TCCR1B & B11111000 | B00000010; // for PWM frequency of 3921.16 Hz
TCCR1B = TCCR1B & B11111000 | B00000011; // for PWM frequency of 490.20 Hz
TCCR1B = TCCR1B & B11111000 | B00000100; // for for PWM frequency of 122.55 Hz
TCCR1B = TCCR1B & B11111000 | B00000101; // for PWM frequency of 30.64 Hz

Code for Available PWM frequency for D9 & D10:

TCCR2B = TCCR2B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz
TCCR2B = TCCR2B & B11111000 | B00000010; // for PWM frequency of 3921.16 Hz
TCCR2B = TCCR2B & B11111000 | B00000011; // for PWM frequency of 980.39 Hz
TCCR2B = TCCR2B & B11111000 | B00000100; // for PWM frequency of 490.20 Hz
TCCR2B = TCCR2B & B11111000 | B00000101; // for PWM frequency of 245.10 Hz
TCCR2B = TCCR2B & B11111000 | B00000110; // for PWM frequency of 122.55 Hz
TCCR2B = TCCR2B & B11111000 | B00000111; // for PWM frequency of 30.64 Hz

Code for Available PWM frequency for D2, D3 & D5:

TCCR3B = TCCR3B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz
TCCR3B = TCCR3B & B11111000 | B00000010; // for PWM frequency of 3921.16 Hz
TCCR3B = TCCR3B & B11111000 | B00000011; // for PWM frequency of 490.20 Hz
TCCR3B = TCCR3B & B11111000 | B00000100; // for PWM frequency of 122.55 Hz
TCCR3B = TCCR3B & B11111000 | B00000101; // for PWM frequency of 30.64 Hz

Code for Available PWM frequency for D6, D7 & D8:

TCCR4B = TCCR4B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz
TCCR4B = TCCR4B & B11111000 | B00000010; // for PWM frequency of 3921.16 Hz
TCCR4B = TCCR4B & B11111000 | B00000011; // for PWM frequency of 490.20 Hz
TCCR4B = TCCR4B & B11111000 | B00000100; // for PWM frequency of 122.55 Hz
TCCR4B = TCCR4B & B11111000 | B00000101; // for PWM frequency of 30.64 Hz

Code for Available PWM frequency for D44, D45 & D46:

TCCR5B = TCCR5B & B11111000 | B00000001; // for PWM frequency of 31372.55 Hz
TCCR5B = TCCR5B & B11111000 | B00000010; // for PWM frequency of 3921.16 Hz
TCCR5B = TCCR5B & B11111000 | B00000011; // for PWM frequency of 490.20 Hz
TCCR5B = TCCR5B & B11111000 | B00000100; // for PWM frequency of 122.55 Hz

'Hope this helps. Have fun!  🙂
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
CardboardNoWheels
Geoff,

That worked like a champ! I added these 2 lines after setup, and resolved the whine.
TCCR3B = TCCR3B & B11111000 | B00000001;
TCCR1B = TCCR1B & B11111000 | B00000001;
This sets both throttle pins to 31khz. I tried 3.9khz first, but that only makes a higher-pitched whine than the default 490hz.

The throttle response suffers, as in the loco doesn't move until the throttle hits 50%, for I loco that I normally don't exceed 40% on a DC transformer. It's worth it to have the sound though.

Thanks
-Ben
Modeling CNW and EJ&E in N-Scale
Reply 1
Geoff Bunza geoffb
Hi Ben,

I'm glad that worked out for you.
More info:  If some modeler uses an Arduino Uno, those parameters will likely not work correctly--- they are geared for a Mega2560, which uses a different processor.

Have fun!  🙂
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
FrenchSR
Geoff, thinking slightly out of the box, could your DC+ work with an RF Nano and say a TA8050P H-Bridge. Normally a Nano doesn't have enough memory to use Wifi but the RF Nano has it built in. I'm thinking about this in a deadrail S gauge layout using resurrected American Flyer DC locos (Battery powered with 18650 or 21700 ), Engine Driver with JMRI.
Regards Richard.
Reply 0
Geoff Bunza geoffb
Hi Richard,

Well... yes and no... The RF Nano uses the NRF24L01+ receiver/transmitter which I think was meant for a direct protocol in the ISM band (2.4GHz) transmission to another NRF24L01+and not equipped with a Wifi stack internally That's important because the JMRI Wifi server and Engine Driver assumes normal Wifi protocols to connect. You might consider an ESP-32 variant instead.

With regard to the TA8050P H-Bridge, it is a 1.5A older part, and while it has some thermal protection, I seem to remember that it may have a unprotected "shoot through" problem that can cause it to heat up. I could not verify this on the web, but remember that I dropped using it early on in favor of the SN754410. I would recommend  taking a look at a small but effective SMD part rated at 2.3 A: the Rohm BD62130AEFJ which looks quite promising for future work.

With all that said, if you built a NRF24L01+ to NRF24L01+ receiver/transmitter pair, you could conceivably run a loco direct link to control a DC loco via the radio link, but not through JMRI nor with Engine Driver. It would be closer to the operation described here: 
Battery Powered Models in HO Scale MRH, Nov 2014
http://mrhpub.com/2014-11-nov/land/files/assets/basic-html/index.html#83

'Hope this helps. Have fun!  🙂
Best regards,
Geoff


Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
FrenchSR
Geoff, thank you very much for the in depth answer. I have the TA8050s but not the RF Nanos so won't order those and will continue down the route of existing technology even if over the top for my purposes. Keep up the great work you've been doing. Have read all your SMAs and the threads generated. Really is food for thought.
Regards Richard.
Reply 1
CardboardNoWheels
I dug back into this project, mainly so I can sit on the couch and control my trains with a tablet instead of sitting at the layout with my hands on transformers. I cranked up PWM to the max (31khz), which is in the range n-scale DCC decoders use. I also scaled the throttle, since the high PWM makes the throttle non-linear, and only 60-75% is usable. The result is far better control than my MRC transformers and incredible low-speed crawl from all my locos.
 
I was lazy with my throttle scaling code: halfing input and adding 50%, making the actual throttle range 50-100% and then adjusting the Engine Driver app preferences to limit throttle input to a max of 70%. Depending on your application, you can adjust scaling equation and possibly reduce PWM frequency for more torque on larger scales which are less susceptible to whining motors.
 
I can update my comments in the code (for clarity) and share the two files I updated, as long as Geoff is cool with that.
 
-Ben
Modeling CNW and EJ&E in N-Scale
Reply 2
Geoff Bunza geoffb
Hi Ben,
 
So glad you enjoyed this project! 
Always happy to see other modelers improve on my efforts. Please do share your results. If the files are large, zip them up and attach them to your comments… and thanks !
 
Have fun!  🙂
Best Regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Reply