Motor Control

== Speed Control ==
Okay, so we've explained how the multifunction decoder creates a DC for its needs, but if we applied this directly to the motor, it would go in one direction really fast. To account for this, the output of the diode matrix does not connect directly to the motor. 
=== Motor Control ===
Between the onboard DC power source (the matrix) and the motor is a series of transistors. Transistors function as a valve, where a small current can control a large one. With a special arrangement of power transistors (meant to control large amounts of power) called an H-Bridge, the decoder can make the train go in either direction. 
As shown, the H-Bridge circuit has four Field Effect Transistors (FETs) arranged in two pairs, with the motor connected in the middle. They can be switched rapidly on and off, making control of a motor or other device possible. The micorcontroller's software will generate signals which switch the pairs on and off, which determines the speed and direction of the vehicle. The method of driving the H-Bridge is known as Pulse Width Modulation. 
By controlling the pair switched, as well as the on/off period, speed and direction can be controlled. Another benefit of PWM is the ability to read the Back EMF generated within the motor for better control of speed and torque. The mass of the rotor creates enough inertia that the motor keeps spinning. By careful manipulation of the PWM signal, very slow speeds are also possible. By switching at a high frequency, any noise from the motor can be moved into the region above human hearing. See High-Frequency Decoders for more details.
With full power to the motor, and ultimately to the wheels, this helps the locomotive run so much better on DCC than with DC. Unlike Analog controllers, the multifunction decoder has complete control of the motor, as well as the capability to monitor and modify the drive signals as needed for exception levels of control.
=== The H-Bridge ===
The H-Bridge shown driving the motor is the same implementation used in a booster, just replace the motor with the Rail A and B connections. In this application, the operation is slightly different as both pairs will be employed.
When driven by a digital signal from the command station, for the first half of the period one pair is on, then during the second half, the other. A logic inverter is used to control one pair, so while one is on, the other is off. Current flows from one FET to Rail A through the load, returning via Rail B to the power supply through the second FET. When the DCC signal changes state, the other pair are switched on, allowing current to flow from Rail B through the load and back the power supply via Rail A. This creates the familiar waveform seen on an oscilloscope, even though there are no negative voltages presentThe output is floating, meaning there is no fixed reference point, which creates the familiar waveform seen on a 'scope.. The direction of current flow through the load creates that illusion. 
== Driving DC Motors with Microcontrollers ==
* 00:00 - Introduction
* 01:17 - DC Motor Driver Basics
* 08:05 - L298N Dual H-Bridge
* 16:13 - TB6612FNG Dual H-Bridge
* 25:24 - DRV8871 Single H-Bridge
* 31:08 - MX1508 Dual H-Bridge
* 38:54 - DBH-12 Dual H-Bridge
* 46:27 - IBT-2 Single H-Bridge
* 51:17 - MD25HV Single H-Bridge & Controller
* 1:02:27 - Conclusion
Category:DCC
Category:Electrical
Category:Electronics