Link here

User's Guide
Control the speed and direction of DC motors with a current controlled H-bridge driver

Speed control

  • Connecting one or two optical shaft encoders.
  • Describe control loop.
  • Adjusting the speed sensitivity.
  • Adjusting the loop gain.
 

Connectors

H1 Wildcard Bus

H1 Wildcard Bus
Signal Pins Signal
GND – 1 2 – +5V
/IRQ – 3 4 – V+RAW
PG1 – 5 6 – PG0
MOSI – 7 8 – MISO
/RESET – 9 10 – SCK
/MOD.CS – 11 12 – 16 MHz
E Clock – 13 14 – R/W
/OE – 15 16 – /WE
AD7 – 17 18 – AD6
AD5 – 19 20 – AD4
AD3 – 21 22 – AD2
AD1 – 23 24 – AD0
Note: You do not need to make any connections to the Wildcard Bus.
 

H2: The external control connector

H2: External Control (RPi) Connector
Signal Pins Signal
Setpoint – 1 2 – +5 V
NC – 3 4 – NC
NC – 5 6 – NC
Motor_Enable – 7 8 – NC
NC – 9 10 – NC
IN_2 – 11 12 – IN_1
I0 – 13 14 – GND
I1 – 15 16 – I2
+3.3V – 17 18 – I3
NC – 19 20 – GND
NC – 21 22 – I4
NC – 23 24 – /FAULT
 

H3: General purpose motor connector

Generally, you connect your motor and its power supply to the screw terminal plug/socket (H4 and H5), but for low current applications you can also use H3, a 10-pin ribbon cable connector. In any case, connections to your motor's optical encoder (if any) are made to H3.

H3: Motor Header
Signal Pins Signal
Encoder_1 – 1 2 – Encoder_2
Speed – 3 4 – VM (+8.2 – 30 V)
GND – 5 6 – OUT_1
OUT_1 – 7 8 – OUT_2
OUT_2 – 9 10 – NC
 

H4 and H5: Motor and power connections

For connecting to the motor and its power supply, two screw terminal plug/socket combinations are used; H5 is a 2-position socket for field power and H4 is a 2-position socket for the motor/load connection. Plugs and sockets come with the board, but for testing with different motors you may want to purchase more plugs. The dimensions and part numbers of the plugs and sockets are:

H4: Motor Drive
Signal Pins Signal
OUT_1 (+ for CW) – 1 2 – OUT_2 (– for CW)
H5: Field Voltage
Signal Pins Signal
+VM (+8.2 – 30 V) – 1 2 – –VM(GND)
 

H6: JTAG programming header

H6 is used during production to program the board's internal CPLD. You should not make any connection to it.

H6: JTAG (CPLD Programming) Header
Signal Pins Signal
GND – 1 2 – +3.5 V
TDI – 3 4 – TMS
TCK – 5 6 – TDO
 

Plugging in the Motor Control Wildcard

With the power off, plug the Wildcard Bus socket on the Motor Control Wildcard onto either the Wildcard Port 0 or Wildcard Port 1 24-pin header on your Mosaic controller. The corner mounting holes on the Wildcard should line up with the standoffs on the controller. The Wildcard ports are labeled on the silkscreen of the controller. Note that the Motor Control Wildcard headers are configured to allow direct stacking onto a controller, even if other Wildcards are also installed. Do not use ribbon cables to connect the Motor Control Wildcard to the controller. Using a ribbon cable on the Motor Control Wildcard’s 10-pin field header, however, is fine.

Caution - Connectors are not keyed!
The Wildcard Buses do not have keyed connectors. While the power is off and unconnected, be sure to insert the Wildcard so that all pins are connected, and the standoffs align with the mounting holes in the corners of the Wildcard. The controller and/or the Motor Control Wildcard may be permanently damaged if the connection is made incorrectly.
 

Setting the Wildcard address

Once you have connected the Motor Control Wildcard to a controller, you must set its address using jumper shunts across J1 and J2. These addressing jumpers select a 2-bit digital code that sets a unique address on the Wildcard port of the controller. Each Wildcard port accommodates up to 4 Wildcards. Wildcard Port 0 provides access to Wildcard addresses 0-3 while Wildcard Port 1 provides access to Wildcard addresses 4-7. Two Wildcards on the same port cannot have the same address (jumper settings). The following table shows the possible jumper settings and the corresponding addresses.

Address Jumper Settings
Wildcard Port Wildcard Address Installed Jumper Shunts
0 0 None
0 1 J1
0 2 J2
0 3 J1 and J2
1 4 None
1 5 J1
1 6 J2
1 7 J1 and J2
Note: Address 0 is not available on the QScreen or Handheld. Use addresses 1 through 7 instead.
 

Under the hood: How H-Bridge motor control works

Show a diagram of the H-bridge current path Show a diagram of the PWM current waveform for inductive loads Say why resistive loads won't work Show controlling a heater using a series inductor.

 

Controlling the output state

An ENABLE signal turns ON/OFF the controller chip. When it is disabled, an attached motor can coast, that is, turn freely. When the controller is enabled, and attached motor may be turned ON or OFF, and when OFF it is braked.

The IN1 and IN2 inputs control the state of the two sides of the H-bridge output, OUT1 and OUT2, and consequently turn a connected device ON/OFF and control the direction of the current through it. Either IN1 or IN2 can also be used for PWM control of the load.

The load is turned ON/OFF as shown in the following table.

Input pins Output state Motor
response
ENABLE IN1 IN2 OUT1 OUT2
1 0 0 L L Motor braked, both sides low
1 0 1 L H CCW rotation
1 1 0 H L CW rotation
1 1 1 H H Motor braked, both sides high
0 X X X X Outputs are tri-stated allowing the motor to coast
 

Controlling the output current

The maximum current through the load is automatically limited to a value you set by an internal controller that uses PWM chopping at a fixed-frequency. You can set the maximum value by setting a 5-bit code on pins I0-I4. You can set the value from 0 to 100% of the board's maximum. The board's maximum is controlled by a fixed resistor, and is by default set to 3 A.

When you enable the H-bridge and set its output, current rises through an attached load (usually a motor winding) at a rate that depends on the field voltage and the winding inductance. Once the current hits the maximum you set, the bridge is disabled and the current allowed to decay until the beginning of the next PWM cycle. The current is chopped at a frequency of 50 kHz.

When controlling DC motors, setting a maximum current prevents excessive start-up or stall current.

The 5-bit code used to control the maximum current is not strictly linear; instead, it provides a sinusoidal response curve. The current limit as a portion of the full scale, is given by SINC/128), where C is the 5-bit count. The following table provides the counts and the set-point current as a percentage of full scale.

Count
Current
    Count
Current
Hex Decimal Hex Decimal
00 0 0% 10 16 71%
01 1 5% 11 17 74%
02 2 10% 12 18 77%
03 3 15% 13 19 80%
04 4 20% 14 20 83%
05 5 24% 15 21 86%
06 6 29% 16 22 88%
07 7 34% 17 23 90%
08 8 38% 18 24 92%
09 9 43% 19 25 94%
0A 10 47% 1A 26 96%
0B 11 51% 1B 27 97%
0C 12 56% 1C 28 98%
0D 13 60% 1D 29 99%
0E 14 63% 1E 30 100%
0F 15 67% 1F 31 100%
 

Setting the decay mode

Controlling motor speed

Describe PWM control vs closed loop speed control, and when each is needed.

 

Controlling speed with a PWM command

Motor speed is proportional to the motor's torque, which you can control by controlling the current, and inversely proportional to the load placed on the motor, which is generally not within your control. Consequently, to compensate for varying load feedback control is generally used in which the motor speed is monitored and changes compensated for.

You can control the motor's torque or current by setting its PWM duty cycle. During the PWM ON time, the current increases linearly, and during the PWM OFF time the current continues to flow through the bridge while decaying, with a decay rate you program. The current waveform is triangular, with an average current proportional to the PWM duty cycle.

Often, and particularly for geared down motors, the load on the motor is nearly constant, and its speed is simply proportional to the PWM duty cycle you command. To truly regulate the motor speed in the face of changing load on the motor you can take advantage of the board's PI controller by setting jumper J3 and assuring that the PI controller's gain is properly adjusted as described here FIXME (include link).

You set the PWM duty cycle of the motor by sending … to … FIXME

Motor duty cycle vs the duty cycle count
Fig. 1  Motor duty cycle vs the duty cycle count. The motor is fully OFF at a count of 0 and fully ON at a count of 31.
 

Closed loop speed control

Describe motor behavior in the face of changing load.

For this reason, in most applications closed loop control isn't needed.

 

Protection circuitry

Automatic output current limiting

The average motor current is determined by the the field voltage you supply, the motor characteristics, and the PWM duty cycle you command. But in addition to that, for safety considerations, internal current regulation is used to limit the start-up and stall current of the motor.

During the PWM cycle, when the H-bridge is turned ON, current rises through the motor winding at a rate that depends on the field voltage and the winding inductance. When the bridge is turned OFF the current decays until the beginning of the next PWM cycle. With current regulation, whenever the commanded PWM duty cycle is greater than 20%, during the ON time of the PWM waveform the current is automatically monitored, and if a set-point current is attained, the bridge is immediately turned OFF. Consequently, the actual duty cycle may be automatically reduced from the duty cycle you commanded to keep the motor current below the desired set-point.

Motor current is not automatically during the first 20% of each PWM cycle
Current monitoring isn't perfect as it doesn't start until 3.75 μs into the ON time, corresponding to about 20% of the total period. So the PWM duty cycle may be automatically reduced to as little as 20% by current limiting, but not lower. Further, if you set a duty cycle of less than 20%, the current limiting circuitry is ineffective.

This current limiting greatly improves the reliability of motor control. For example, if you command the motor to be fully ON (at 100% duty cycle) but a heavy load or stall condition causes too much current, the current limiting circuitry will automatically turn down the duty cycle for you to keep the current under control, down to as little as 20% duty cycle. Further, when you initially turn a motor fully ON from a stopped condition, the duty cycle will initially be limited to as low as 20%, then increase as the motor speeds up, soon attaining the full ON status you commanded, all the while limiting the motor current to the set-point current.

The set-point current is determined by a fixed resistor, which sets its maximum value, and also by the PWM duty cycle you command. That is, the PWM duty cycle value you send to the board serves double duty; it sets the output duty cycle, and it sets the threshold current for automatic current limiting (which may automatically reduce the duty cycle to below that value you commanded). The default value for the maximum current is set by the current sensing resistor to 3.3 A (but you may change it, see below).

The set-point current does not vary strictly linearly with the commanded duty cycle; instead, it provides a sinusoidal response curve. The current limit as a portion of the full scale, is given by SINC/128), where C is the 5-bit count. The following table provides the counts, the PWM duty cycle, and the set-point current as a percentage of full scale.

Commanded PWM duty cycle and current limit value for each input count
Input count Commanded
Duty cycle
Current limit Input count Commanded
Duty cycle
Current limit
Hex Dec %FS Default (A) Hex Dec %FS Default (A)
00 0 0% 0% 0 10 16 51.7% 71% 2.34
01 1 1.7% 5% not limited 11 17 55.0% 74% 2.44
02 2 5.0% 10% not limited 12 18 58.3% 77% 2.54
03 3 8.3% 15% not limited 13 19 61.7% 80% 2.64
04 4 11.7% 20% not limited 14 20 65.0% 83% 2.74
05 5 15.0% 24% not limited 15 21 68.3% 86% 2.84
06 6 18.3% 29% not limited 16 22 71.7% 88% 2.90
07 7 21.7% 34% 1.12 17 23 75.0% 90% 2.97
08 8 25.0% 38% 1.25 18 24 78.3% 92% 3.04
09 9 28.3% 43% 1.42 19 25 81.7% 94% 3.10
0A 10 31.7% 47% 1.55 1A 26 85.0% 96% 3.17
0B 11 35.0% 51% 1.68 1B 27 88.3% 97% 3.20
0C 12 38.3% 56% 1.85 1C 28 91.7% 98% 3.23
0D 13 41.7% 60% 1.98 1D 29 95.0% 99% 3.27
0E 14 45.0% 63% 2.08 1E 30 98.3% 100% 3.30
0F 15 48.3% 67% 2.21 1F 31 100% 100% 3.30
Note: The input count is shown in both hexadecimal and decimal. The duty cycle increases linearly with the input count, from zero to 100%. The current limit value is not linear, but rather sinusoidally related to the input count.

Whether you connect the board to a Mosaic Controller, another microcontroller, or use it stand-alone, the current limiting function remains active.

To prevent overcurrent conditions you should always use an inductive load. All motors will have sufficient inductance, so if you are driving a motor you needn't worry about adding a series inductor. But if you are driving a purely resistive load, for example, if you are using the driver to power a thermoelectric cooler, then you should add a series inductance. The minimum inductance required is approximately 22 uH. You should use a standard value greater than 22 uH, allowing some margin as the inductance of real inductors drops off with current a bit. A 33 uH or 47 uH inductor of sufficient current rating works well. Suitable inductors include:

33 uH 6A leaded torroidal inductor Bourns 2100HT-330-H-RC available from (Digikey part number M8919-ND http://www.digikey.com/product-detail/en/2100HT-330-H-RC/M8919-ND/775458), or,

47 uH 8.5A leaded torroidal inductor Murata 1447385C available from (Digikey part number 811-1334-ND http://www.digikey.com/product-detail/en/1447385C/811-1334-ND/1924822)

 

Changing the full scale current limit value

The 100% value of the current is set by a resistor on the board. By default a 0.20 Ω resistor sets the maximum to ±3.3 A. You'll notice the resistor, designated R5, has a large package1).

You may require a full scale of less than ±3.3 A. For example, you may want more precise current control with a full scale current of only 0.5 A. In that case, you may change resistor R5. The following table provides the resistor value needed for different full scale currents:

Current Sense Resistor Values
Resistance @ Power Maximum Current Maximum duty cycle
3.30 Ω @ 0.25 W 0.2 A 100%
1.32 Ω @ 0.5 W 0.5 A 100%
0.66 Ω @ 1 W 1.0 A 100%
0.33 Ω @ 2 W 2.0 A 100%
0.22 Ω @ 2 W2) 3.0 A 100%
0.20 Ω @ 2 W 3.3 A 100%
0.19 Ω @ 2.5 W 3.5 A  88%
0.16 Ω @ 2.5 W 4.1 A  65%
0.13 Ω @ 3.5 W 5.0 A  40%
Rs =  (Vref / 5) / Imax =  0.66 /Imax
Caution -- Stay within maximum power limitations
You can use the board to drive up to ±3.3 A or lesser currents continuously. You can change the current sensing resistor to provide greater full scale currents, but if you do you must decrease the duty cycle of the board to keep the average power dissipated on the board to that using ±3.3 A full scale, as shown in the table. For example, you can change the full scale current to 5 A by replacing the current sense resistor with a 0.13 Ω, 3.5 W resistor. In that case, you can not use the board with 100% duty cycle, but must use external PWM control of the board to keep its overall duty cycle to less than 40%. Do not exceed currents of 5 A.

You can also disable the automatic current limitation completely by replacing the current sense resistor with a short, either by removing the resistor and replacing it with a zero ohm resistor, or shorting across it with a soldered wire. If you do that, you'll need to be careful that your load doesn't draw more than 5 A transiently, or more than 3.3 Arms continuously. If you exceed those limits, the H-bridge motor driver chip will be damaged.

 

Overcurrent protection

Aside from the current regulation/limiting discussed above, the board's circuitry protects against motor currents in excess of 6 A by removing the gate drive of its output FETs. If the output current persists longer than a small over-current-protection-time, all FETs in the H-bridge are disabled and the SUCCESS signal is negated. The board remains disabled until you either re-enable it in software, or remove and reapply its field power. Overcurrent shutdown may result from a short of a motor output lead to ground, to the supply, or to the other motor lead. The overcurrent value is set at 6 A and is independent of the current sense resistor value.

 

Thermal shutdown

If the board's motor driver IC's die temperature exceeds safe limits (150°C), the H-bridge will be disabled and the SUCCESS signal will be negated. Once the die temperature falls to a safe level operation is automatically resumed. The visible sign of this action is that the motor will turn OFF, then turn ON again, then after heating up again turn OFF again. Such thermal oscillation is an indication of either excessive motor current or too high an ambient temperature. The remedy is to drive the motor at a lesser speed.

The following temperature measurements were taken on the board when powered at 14.2 V with a resistive load drawing an average (97 % duty cycle) of 2.85 A. The load dissipated 33 W while the board itself dissipated 7.3 W. The board was operated in free air at an ambient temperature of 29.5 °C (85 °F).

Top surface of driver chip 92°C
Top surface of 0.2 Ω current sense resistor 120°C
Board adjacent to driver chip 85°C
Board adjacent to current sense resistor 107°C
Top surface of CPLD 59°C
 

Reading the FAULT signal

FIXME – Use either "FAULT" or "SUCCES", but not both. Decide which the board reports to the microcontroller. Keep in mind that it can not be read in stand-alone operation. Search this document for both terms and correct as needed.

The motor driver IC responds to possible faults by shutting down and issuing a FAULT signal. It will shutdown on over-current, short circuit, under-voltage, and over-temperature conditions. Your software can poll the FAULT signal to detect a potential shutdown, or to verify normal operation. The FAULT signal is asserted on the following conditions;

  • Overcurrent or short

    If the bridge current exceeds 6 A for too long the H-bridge will be disabled and the FAULT signal asserted. The H-bridge remains disabled until either you disable and re-enable the chip, or remove and reapply the field voltage. Overcurrent will occur in response to a short to ground, supply, or across the motor winding.

  • Over-temperature

    If the chip's internal die temperature exceeds 150 °C the H-bridge will be disabled and the FAULT signal asserted. Once the temperature has fallen to a safe level operation automatically resumes.

  • Undervoltage lockout

    The field voltage must be greater than 8.2 V for reliable operation. If it falls below that the H-bridge is disabled and the FAULT signal asserted. Operation resumes when the field voltage rises above 8.2 V.

If you use an inadequate field power supply, that is, one whose output voltage falls below 8.2 V when the motor is powered, then the motor controller might endlessly switch ON/OFF as the power drops when the motor is ON and rises again as the motor is OFF. So, for reliable operation your power supply must be able to supply the motor's turn-ON current without dropping below 8.2 V.

 

Interfacing to a typical motor

Let's demonstrate control of a typical motor. For our "typical" motor we'll look at a 12 V 25 W motor. There are many compact (66 mm in diameter, or appx. 2.55"x2.5") motors like this used in diverse applications, for example to move a load along a linear rail, as printer carriage drives, or to actuate a medical peristaltic pump.

Unloaded it spins at 2700 rpm and with a nominal load it turns at 1800 rpm and draws 2.1 A (25 W). It's internal resistance is 1.8 Ω; consequently, it's start-up current is 6.7 A. It's mechanical response time is about 25 msec.

We'll consider an application where the motor is connected through a 5:1 gearbox to a peristaltic pump head, which turns at a rate of 10-400 rpm to pump 50-250 ml/min.

The speed of the motor can be monitored through two optical sensors that are placed on an 18-tooth wheel on the motor shaft. The two sensors are placed so they produce quadrature pulses 90° apart in phase.

Motor speed
(rpm)
Encoder
pulse rate (Hz)
Pump speed
(rpm)
Pump flow3)
(ml/min)
Condition
2700 810 540 338 Unloaded motor
1800 540 360 225 Nominal with load at 2.1 A
180 54 36 11.3 Turned down to 10%
90 27 18 5.6 Turned down to 5%



See also →


This namespace contains:
 
Notes:
It's in an SMD 2512 package, PN RLP73K3AR20JTE.
For example, PN RLP73K3AR22JTE or Digikey A109899CT-ND.
Assuming that the tubing is sized so that 400 rpm produces a flow of 250 ml/min.
This page is about: Control PWM Current, Speed and Direction of DC Motors – Using an H-Bridge motor control board to control speed & direction of DC motors. An onboard PID controller controls speed from a digital command.
 
 
Navigation