I am currently experimenting with some motor control circuitry for my garden train. I have spent several time trying to read up on the basics of motor control, and I have also done some prototyping. I have finally settled on a design, but I have a few different questions that I would appreciate if someone experienced could help me answer.

The question consists of two parts: (a) a system overview and (b) a few questions regarding the design. I am aware that this is a composite question, but I couldn't find a meaningful way of splitting them.

System Overview

The idea is to build a simple garden railway control system. The garden at hand is a small one, remotely placed. The only source of power will be the batteries that I bring. The layout is also to be automated over time, but for locomotives will be manually controlled, likely via a radio link.

Figure: http://avendi.se/stackexchange/dpower-system-overview.png

The track will be used as a power bus: a LiPo battery or two car batteries in series will be connected to the rail to provide power to all rolling stock, and in the future, lamps, switches and so on.

Locomotives will be picking up power from the track, but will receive motor commands via radio. In the future, the locomotives will hopefully be fully automated.

Loco Control

Each locomotive will be equipped with a small control circuit. The purpose is to both be able to drive the DC motor, as well as control the drive. The driver is centered around a H-bridge circuit (the L6202), and the control around an microcontroller (the ATmega328).

Figure: http://avendi.se/stackexchange/dpower-loco-control.png

As it is unknown how the locomotive has been placed on the track, a rectifier is first in line to give us a DC power line initially. This power is then fed into two different voltage regulators. One is to support the ATmega328 and whatever radio solution that will be chosen, and the other ons is to support the motor driver.


Now that I have explained the complete system, here are the questions:

  1. The voltage regulator for the microcontroller (LM2937) will need to reduce the voltage from approx 20V DC to 5V DC. I am guessing most of it will be turned into heat. Is there any way to avoid this?

  2. The microcontroller won't draw much current, but the motor will, and I guess there might be noise and transients from starting and stopping the motor. Do I need to protect the microcontroller (or its voltage regulator) from this? If so, how?

  3. How can I protect a LiPo from short-circuits or other problems? I don't want any LiPo fires.

I guess those are the most important questions. I have lots of shorter questions, but I think the big questions. If you spot any other problems or improvements, please let me know.

  • \$\begingroup\$ Why don't you use DCC - this is what it's designed for and gives you tons of features. en.wikipedia.org/wiki/Digital_Command_Control \$\endgroup\$
    – Andy aka
    Jul 24 '13 at 7:25
  • \$\begingroup\$ The thought has struck my mind, and I do realise that I am pretty close to the normal operation of DCC in my design. Right now, I just want to be really basic and understandable. I want to build the electronics myself, and while I could build a DCC decoder, I would have a much harder time building a DCC command station and booster. I could in theory get an off-the-shelf component, but the price is significantly higher that I am willing to pay right now, and I need to find a solution that doesn't require an electrical 220 VAC socket in the garden. Thanks for sharing though! \$\endgroup\$ Jul 24 '13 at 7:40
  • \$\begingroup\$ DCC need not be as complicated as you might think: usuaris.tinet.cat /fmco/dccgen_en.html especially given that you still have "radio reciever" as a black box. You might also want to research "Hornby Zero One", which was an early (late 1970s) British system that was a simple forerunner of DCC. \$\endgroup\$
    – pjc50
    Jul 24 '13 at 8:15
  • \$\begingroup\$ Thanks, that was a very valuable link! I will certainly take a look at it. If it is as simple as it looks, I might convert the locomotive control to a true DCC decoder. :-) \$\endgroup\$ Jul 24 '13 at 8:27
  • \$\begingroup\$ The radio receiver is probably going to be my old Hitec RC radio transmitter and receiver. The microcontroller would just need to decode the servo pulse for one of the channels to determine speed and direction. \$\endgroup\$ Jul 24 '13 at 8:34

I wouldn't worry about losses from the microcontroller's voltage regulator. Yes, most of the energy goes into making heat. But, the current needed by the microcontroller will be so small compared to the motors that it's probably not worth concern. For more detail on how to calculate just how much heat there will be, see My linear voltage regulator is overheating very fast.

I would suggest dropping the voltage regulator for the motors. A PWM-driven motor is already a buck converter, so as long as you aren't exceeding the maximum voltage of the driver, you are probably safe. The voltage rating for motors is usually the maximum continuous voltage they can take, but peak voltage is much higher, limited basically only by the insulation in the windings. As long as your motor controller is doing its job of limiting the current, and thus the power and heat, to the motor, a higher voltage motor drive is fine. Adding a regulator to the system just makes it more inefficient.

The motor will generate noise. Reduce it by including plenty of bypass capacitors, from small ones around each IC, to big ones to supply the motor. Also, arrange your PCB and cables to minimize the area of the loop through which the motor current travels. This will minimize the inductance of that loop, and thus reduce its inductive coupling to everything else in your circuit. Remember that the motor current flows not only through the positive supply but also ground. Keep these currents away from the microcontroller's ground. Your motor is small enough that you should not require any extraordinary measures beyond good layout and standard practice to keep noise at reasonable levels. I have a previous answer on noise with some more detail. Also, a linear regulator usually has better power supply noise rejection than a buck converter: another reason to retain the 5V regulator.

I'm not enough of an expert on batteries to address your concerns beyond basic advice, like include a fuse. This seems like something you could easily break out into a separate question and get some good advice, if after doing some basic research you require more clarification.

  • \$\begingroup\$ Thanks for you answer! A follow-up question: In the case where the loco is idle, and the only thing consuming power on the track is the loco, will the microcontroller voltage regulator hold up? \$\endgroup\$ Jul 24 '13 at 7:32
  • \$\begingroup\$ I don't see why it wouldn't. \$\endgroup\$
    – pjc50
    Jul 24 '13 at 7:59
  • \$\begingroup\$ According to the linked article on voltage regulators, I am in a similar situation. I have a voltage drop of 19V, and a current draw of about 200 mA. The LM2937 is a linear regulator. Should I exchange it for a switched one? \$\endgroup\$ Jul 24 '13 at 8:18
  • \$\begingroup\$ Use a switched regulator if you have the space, certainly. I was assuming the draw would be more like 1ma for the microcontroller, and had forgotten to count the radio reciever. \$\endgroup\$
    – pjc50
    Jul 24 '13 at 9:06
  • \$\begingroup\$ @DavidPettersson 200mA sounds like a lot for a radio receiver and a microcontroller. I'd first try to reduce that, but if that's not possible, a switching regulator starts to make sense. \$\endgroup\$
    – Phil Frost
    Jul 24 '13 at 10:23
  1. Use a buck converter to avoid the power loss when dropping the voltage down. Dimension Engineering has some good modules, and an excellent introduction here.

  2. It depends on your specific regulator, but the easiest thing to do is to put some capacitors on both the motor power supply and the sensitive electronics rails.

  3. A fuse is the easiest method of protection, but requires that you replace it every time the rails are shorted. A DC breaker will protect your batteries and is resettable after a short.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.