Jump to content
 

DC Loco Control With an Arduino


BG John
 Share

Recommended Posts

I wonder what fool decided to call the function "analogWrite()" when he could have saved himself some typing if he had called it pwmWrite()   :)

 

...R

 

Probably someone in Marketing :)

 

(Apologies in advance if anyone reading does work in a marketing department.)

Link to post
Share on other sites

All my layouts are small, so trains will either be arriving or departing slowly, or shunting. Nothing will be run very fast, or for very long without at least a brief stop.

 

The two L298N boards with heatsinks have just arrived, so I've got most of the bits I need to put a system together for testing. Final assembly can't be done until the postman brings more bits.

 

Overload and short circuit protection was mentioned earlier. Someone on another forum is using these with L298N boards. Has anyone got any comments on whether they're suitable? I couldn't find any alternative products online, so does anyone knows of anything better?

 

Unless you are using Portescap or similar coreless motors, I don't think PWM would be a problem for that layout.

 

I took a squint at the L298N datasheet and it does seem a bit sketchy with regard to overload protection. Those circuit breakers might help in some situations, but someone reported that they are a bit slow to react, so they might not provide enough protection.

 

Another option is to sense the L298N current. The chip has provision to do that with an external resistor. I suppose you could detect overcurrent in your code, but you'd need to interrogate the current often enough to get a fast response. You could also use an external circuit to do the same thing.

 

As I type this I see that Ray just beat me to it. I was about to suggest the old positive temperature coefficient thermistor method (actually a filament light-bulb for a car). I usually use a turn signal bulb - about 21 watts. (Thinks: Better buy some before they disappear thanks to LED lamps.) The bulb also works as a useful "idiot light".

 

BTW, are you planning on controlling more than one train simultaneously and will sections on your layout use a common return?

 

Abdy

Link to post
Share on other sites

  • RMweb Gold

I've used the L298 quite a bit and, with regards to 00, it is most suitable.

 

For (nominal) 12v dc PWM operation it is quite happy to run one or two locos without a heatsink.

The L298 does NOT have any short circuit protection but it does have built in thermal overload protection.

So, if you do short the track rails together then running the L298 will heat up and then shutdown.

 

I entered an L298 design, admittedly using a PIC, in the 2012 Innovation challenge which had several of the design concepts being discussed here.

 

 

Kev.

Link to post
Share on other sites

Many years ago I experimented with driving trains from my BBC Micro. I worked on the principle that most DC controlers work by having a potentiometer accross the 12v supply simply tapping off the required control voltage. All I did was replace the potentiometer with a combination of a digital to analogue converter which takes the 8 bit digital output and in 256 steps gives an output of 0 to 5 volts feeding into a 741 op amp to give 0 to 12 volts.

 

The potentiometer of any type of controller should be able to be replaced in this way.

 

Stuart

Link to post
Share on other sites

I have not experimented with coreless motors - I had a very tiny one and I broke it before I could do any electrical damage to it. But I have never had any problems with PWM on regular DC motors. And AFAIK all the DCC chips drive the motors with PWM. They don't have the capacity to dissipate the heat that would arise with any sort of resistive system. In practice the coils in the motor average out the PWM.

 

...R

Link to post
Share on other sites

I have not experimented with coreless motors - I had a very tiny one and I broke it before I could do any electrical damage to it. But I have never had any problems with PWM on regular DC motors. And AFAIK all the DCC chips drive the motors with PWM. They don't have the capacity to dissipate the heat that would arise with any sort of resistive system. In practice the coils in the motor average out the PWM.

 

...R

 

Yes, I'm sure DCC decoders can't operate as series regulators - the dissipation would be a big problem. They could still operate like switched-mode power supplies and supply the motor with fairly smooth DC, but I suspect they don't. IIRC they use PWM and sense the motor's back-EMF during the "off" part of the cycle. Someone on RMWeb will be able to provide lots of information on this.

 

I'm not sure why coreless motors have a problem on PWM. I assume it's because the windings have no access to a heatsink so they get hot enough to burn the insulation on the winding wire, but that may well be baloney.

Link to post
Share on other sites

It depends on the motor and controller. An iron cored motor can have relatively slow pulses, since the inertia of the core keeps it spinning between pulses, and the inductance, (if sensing back emf) is sufficient. Coreless motors can easily overheat on full load, (no iron heat sink, as you mention) and for slow pulse rates, due to the much smaller inertia, the armature can tend to stop and start, causing wear on the brushes if a lightly built precision motor.

Link to post
Share on other sites

When I built the "Stop the train game", I initially used the default PWM frequency (around 700Hz) for my N gauge prototype. This worked fine for the little trains but the audible whine became quite unpleasant when I upscaled the design to run a 32mm gauge loco. There is a library available to adjust the frequency of the PWM, so I experimented with different frequencies. In the end I settled on a low pulse frequency of around 50Hz. This seems to work well with both scales of locomotive.  

Link to post
Share on other sites

Coreless motors don't have a problem with PWM. But you'd have to respect the physics involved and differences with normal motors. As alluded correctly before, inertia keeps a standard motor turning during the time the power is off. The super-light rotor of the coreless motor simply doesn't have that inertia and actually stops at the frequency used for normal motors. It's this constant stopping and starting that heats the coils inside the motor because as with all motors, the highest current is at the moment power is applied but the rotor is still idle. However, if you increase the frequency, and thus shorten the off period to below the threshold the rotor needs to keep spinning, the motor doesn't stop. That's why decoder manufacturers introduced an 85kHZ PWM frequency for these coreless motors, and they simply just work. (normal PWM frequency for a standard motor is just a few kHz)

 

A small flywheel on a coreless motor should fix the problem then :)

 

I can see how running 85kHz over the short distance between a DCC decoder and a motor would work, but will there be a problem if it's sent down the rails from a controller?

Link to post
Share on other sites

Lots of interesting and useful comments. It looks as though I'll be able to try an assortment of controllers on my various layouts. Some need everything controlled by Arduinos, so I can use wireless remote control. On others I need to operate the fiddle yard by hand, so won't be able to move around much, and I'll use an Arduino and a stand alone controller. I've got two Gaugemasters and two different cheap Chinese PWM controllers, so along with the Arduino based PWM controllers, I might be able to make some useful comparisons.

 

Incidentally, I was reading the spec. for the Arduino Due today, and it seems to have a couple of real DC outputs, but at very low power so it will need some electronics added for loco control.

Link to post
Share on other sites

I want to do more than control a loco. I have ambitions of a fully automated layout! But not yet, as I have plenty to get my head round first, with PWM loco control, point and signal servos, fiddle yard track alignment sensors, infrared remote control, and then radio control!

  • Like 1
Link to post
Share on other sites

  • RMweb Gold

I want to do more than control a loco. I have ambitions of a fully automated layout! But not yet, as I have plenty to get my head round first, with PWM loco control, point and signal servos, fiddle yard track alignment sensors, infrared remote control, and then radio control!

 

That's what I am doing but using PICs instead.

 

Enjoy the journey - I am.

 

 

Kev.

Link to post
Share on other sites

I want to do more than control a loco. I have ambitions of a fully automated layout! But not yet, as I have plenty to get my head round first, with PWM loco control, point and signal servos, fiddle yard track alignment sensors, infrared remote control, and then radio control!

My suggestion is to stick with simple PWM until you have evidence that it is not suitable for some aspect of your project. That way you can use your brain power for figuring out stuff that is useful for your project.

 

...R

Link to post
Share on other sites

My suggestion is to stick with simple PWM until you have evidence that it is not suitable for some aspect of your project. That way you can use your brain power for figuring out stuff that is useful for your project.

 

...R

I agree. I'll just be using what I've already got though, two Gaugemasters, two cheap Chinese PWM controllers, and two L298N boards for the Arduino controlled layouts. It's easy to get carried away and want to use Arduinos for everything, but where I need to operate a layout from a fixed position, I may as well use standalone controllers. I've currently got five layouts to get working, and three of them need to be operated within reach of the fiddle yard. The other two will have remote control, so Arduino based controllers are needed.

 

Then I can start experimenting with BPRC for the forthcoming O gauge layout!

Link to post
Share on other sites

  • 10 months later...

I have tried using arduino and the L298 boards to control mitsumi motors (didn't want to try it out on an expensive loco). It worked well but there was an audible hum from the motor. Decreasing the pwm frequency I got excellent slow running control but still had the hum, Increasing the pwm frequency I got worse motor control but reduced hum. Has anyone managed to get good control with no hum?

Link to post
Share on other sites

I think the existence of noise depends on the specific type of motor being used. The responsiveness of the motor to different PWM frequencies will also depend on the type of motor.

 

 

The existence of any noise depends almost entirely on the PWM frequency. The volume of the noise at that frequency is more attributable to the type and quality of the motor. If your chosen frequency is on or near the mechanical resonance frequency of the motor you will certainly know all about it. :shout:

Link to post
Share on other sites

The existence of any noise depends almost entirely on the PWM frequency.

Different motors will exhibit different effects for the same PWM frequency. The motors I have been using don't make any noticeable noise with the standard Arduino PWM frequency of about 490Hz.

 

If you are saying that there would be no noise with steady DC power rather than PWM then of course that is correct - but I had not been trying to make that point.

 

...R

Edited by Robin2
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...