Arduino running model locos

I would like to control a model rail layout - N-scale - using an Arduino. The models I have advise not to use DCC as it can cause the motors to overheat, so I’m assuming the motors can’t take a PWM supply. My thought is to use a digital-to-analogue converter (DAC) driven from the digital I/O pins of the Arduino, plus a driver circuit using a power transistor. Does this sound feasible? The motor probably draw less than 100 mA. Can anyone recommend a suitable DAC?
Thanks

Hi Ronald
What is “DCC”?? Maybe DC Current. Maybe not as if you can’t use DC current what are you supposed to use. Confusing.

Don’t see why not.
Cheers Bob

Sorry DCC is Digital Command Control. It’s where the track is supplied with a constant AC voltage and a chip in the loco receives commands via a signal transmitted via the rails to change the pulse duty-cycle of rectified DC fed to the motor. The motors run on DC with the speed controlled by the duty-cycle of the pulses. e.g. the motor receives 12 V for 50 milliseconds then nothing for another 50 ms. If the on/off ratio is changed to say, 20 ms on and 80 ms off it will run slower - somewhat like the way solid-state light dimmers work.

Hi Ronald

PWM. Albeit pretty slow but that is the principle. What is wrong with that??
Cheers Bob

“I found PWM controllers make motors run hot especially at low speed so I simply won’t use them. The motors get hot and slow down, eventually failing completely.”

from PWM and Hornby Locos - Electrics (non-DCC) - RMweb

Hi Ronald.
Interesting link. Especially about slow PWM. It is quite feasible that different controllers will have PWM at different frequencies. That scenario you quoted is REALLY slow, only 10Hz. If that is real that could be a reason for heating if the statements in that link are true. Personally I have not tried to run any motor with a PWM as low as that.

Running with a PWM too fast could have a similar result. Once again I have not tried to run a motor with a too fast PWM for any length of time as as you increase frequency the motor will slow down and eventually stop.

I once short time ago had occasion to check this with a larger motor and found it started to slow at anything above about 500Hz. Some commercially available prebuilt controllers quote 15kHz, I doubt there are too many motors that would handle this frequency. But some do provide a frequency adjustment.

As a point of interest the Arduino UNO R3 PWM operates at about 490Hz. Most small motors I have tried seem happy at that.
Cheers Bob

Thanks Bob. My cycle times were just to show how PWM works. I have tried driving model rail vehicles via the L293 (or whatever) H board - the motors rattled, I think. I could always try it out for a short while to see if the motors do get warm or rattle.

The L298N chip, which is available with a variety of different modules, can be configured either as an H bridge or as a driver with direction control. If you were using PWM then you were using it as a driver with direction control. In that case the PWM signals were generated from another source - perhaps a MCU such as an Arduino or perhaps from a stand-alone PWM generator. How well that worked, and whether or not the motor rattled, depends on the device used to generate the PWM, and how that device was configured. For instance the UNO has two kinds of hardware PWM generation, as well as software generation which could be any rate at all!

A DAC is just another type of PWM, but it would likely operate at a higher pulse rate and have more filtering than is typical for MCUs or DCC. The actual pulse rate will depend on how the DAC is controlled.

But getting good low speed and startup performance with a generic DAC is going to be difficult. The advantage of DCC is that you can set the speed curve to suit the loco, ensuring that the lowest speed setting will actually move it. Some DCCs come with the option of a configurable start pulse to get the loco moving before settling into the lowest usable speed.

I would think that investigating why your motor seemed not well suited to the DCC you were using (or to DCC in general) and what could be done differently to get DCC working would be a better option than starting over with a different controller and a DAC. Are you sure that the overheating warning was about running a DCC controller in your loco, or was it about running the loco (as a non-DCC loco) on a DCC layout?

Hi Ronald

What sort of signal is the DCC. It sounds like some sort of command and the actual PWM is generated on board the Loco to drive and control the motor speed and direction in response to sent command.

I am sorry but I am not up on how a model train system works but there must be some sort of standard and compatibility across the board to allow for a mix of manufacturers. I might have a look later as these systems sound interesting. But as for now ???

My thoughts are that if the motor control is actually generated on board the loco the signal from the controller would not be the actual driving PWM but some other form of command. If the power on the rails is constant AC is the controlling signal added to that or separate somehow.

I would have thought that if the driving PWM is generated on board this would have been optimised to work together for best operation.

What I am getting at here is that it could be a mistake to attempt to send driving PWM signals directly to the Loco if the actual driving PWM is generated on board but you should use a dedicated loco driver device. It is not on to control one lot of PWM wit another PWM signal. Usually ends up some sort of disaster.

Perhaps I am confusing the issue here and it is developing to a case of “knowing enough to be dangerous”. So I will shut up until I can find out enough about how all this is achieved by doing a bit of my own research. When I get time. Funnily enough even tough I have been retired for years that is still in short supply (time).
Cheers Bob

DCC control involves a DC supply to the rails combined with a controller that transmits a digital control signal by switching the supply to the rails at high frequency. The control signal is separately encoded for each loco. The DCC unit in the loco interprets the control signal to control the loco motor using the power from the rails. The DCC unit uses PWM to generate the driver voltage for the motor.

The usual practice is to add a DCC controller to the loco and convert the layout to DCC control. OP is considering the alternative of not using DCC but instead driving the layout (or a portion of it) at a variable voltage, using a MCU and PWM to provide the variable voltage to the layout to control the loco’s speed. This is common practice with layouts (or portions) that usually operate only one loco at a time (and the way it used to be done before DCC became the standard).

Hi Jeff.
Thanks for that info. So with DCC control the driving PWM must be generated on board the Loco else all Locos would respond to a driving PWM applied to the rails. And the Loco would have to be modified (probably in a simple way) to accept direct driving PWM. Would that be correct?
Cheers Bob

Additional thinking.
Probably the mod would be to just remove or bypass the DCC controller from the Loco.
For direct PWM drive the PWM would have to be at a frequency best for the Loco motor. Probably the same as the DCC controller generates. Could be where he trouble lies when using direct PWM. Incompatible frequency used.

Thanks Jeff. That’s exactly what I want to do. I have physically sectioned the track if I need to run multiple trams on the same track.

1 Like

Most recent DCC-equipped locos automatically switch to DC mode when there is no DCC control available. How the DC is generated (eg rectifier/rheostat or PWM) is not relevant. Speed depends on the voltage.

The loco OP is concerned about does not have DCC and it is apparently not recommended to upgrade it.

1 Like

All good now. I have the model running on a PWM output from an Arduino microcontroller. Seems happy :slightly_smiling_face:

2 Likes

Greetings everyone, this has been a really interesting thread. Thank you.

I am using an Arduino to drive a small L298N module at a PWM frequency of 7812.5Hz. So far, so good and I have had no loco motor heating issues that I know of. All my locos are DC (not DCC). Some are getting on a bit (30 years or so) and some are relatively new. I have a mixture of Hornby, Bachmann, Mainline and even an old Airfix tank loco. All seem to run OK. One in particular, and oldish Hornby King William IV, loco drive, sings a little bit due to the PWM but otherwise runs as smooth as silk.

Having read this thread, I will definitely keep an eye on the motor temperatures.

My biggest problem (forgive me if this is off topic) is how to smoothly pass control of a loco from one L298N controller to another. i.e. from one track circuit to another. It usually works, but I have blown a few track feed fuses and bricked a controller in the process. It’s a bit hit and miss and seems to depend on how the loco picks up current so I have stopped doing it and will need work out a better way.

Cheers

1 Like

Hi Gregg
Welcome.
One thing you DO NOT want is both PWM controllers connected at the same time. If one were HIGH at that instant and the other LOW you have a short circuit with possible undesirable results.

I think this will be a mechanical thing. It depends on how the power is picked up by the locos. If there is only a small physical gap there is a possibility of the locos contacting both systems at the same time it might be simply a question of enlarging the gap and depend on inertia to allow the locos to traverse this gap and pick up the other power source.

Cheers Bob
EDIT:
The paragraph re series diodes deleted. Would not work.

IMPORTANT. While traversing any transition point both systems should be set to run in the same direction. Locos could get confused if not couldn’t they.

To add to what @Robert93820 has said about enlarging the gap, experimenting with various sizes of capacitors in parallel with the motor should also keep the motors powered for a short time to help while it is clearing the gap.

Hi Dan
Any Cap would have to be connected across the motor in the Loco. As this signal is reversible this cap would have to be non polarised, also as this is probably a PWM signal at this point any cap of a useful size would probably upset the integrity of the PWM waveform.
Cheers Bob

Hi everyone, thanks for your replies and ideas. I think I will just come up a system of isolation and ‘handover’ switches that passes control of the cross-over section of the track from one controller to the other, so only one conrtroller is active at any one time. It means you can’t change track circuits without stopping the train, but so be it.

However, at the moment I am running the two controllers using two Arduinos (for various other reasons). Maybe if I just run them from one Arduino, using PWM pins 5 and 6, then the clocking of the PWM will be largely in synch, provided I have the direction (the H-bridge polarities) set the same way for both track circuits? I will try this on the weekend and report back. If I blow a few fuses or brick another motor controller, it will all be in the interests of engineering!

Cheers
Gregg