Introduction When the switch is closed, the motor sees 12 Volts, and when it is open it sees 0 Volts. If the switch is open for the same amount of time as it is closed, the motor will see an average of 6 Volts, and will run more slowly accordingly. As the amount of time that the voltage is on increases compared with the amount of time that it is off, the average speed of the motor increases. This on-off switching is performed by power MOSFETs. A MOSFET is a device that can turn very large currents on and off under the control of a low signal level voltage. The time that it takes a motor to speed up and slow down under switching conditions is dependant on the inertia of the rotor , and how much friction and load torque there is. The graph below shows the speed of a motor that is being turned on and off fairly slowly: We can see that the average speed is around 150, although it varies quite a bit. If the supply voltage is switched fast enough, it won’t have time to change speed much, and the speed will be quite steady. This is the principle of switch mode speed control. Thus the speed is set by PWM. Inductors Before we go on to discuss the circuits, we must first learn something about the action of inductive loads, and inductors. Inductors do not allow the current flowing through them to change instantly (in the same way capacitors do not allow the voltage across them to change instantly). The voltage dropped across an inductor carrying a current i is given by the equation Where di/dt is the rate of change of the current. If the current is suddenly changed by opening a switch, or turning a transistor off, the inductor will generate a very high voltage across it. For example, turning off 100 Amps in 1 microsecond through a 100 microHenry inductor generates 10kV! PWM frequency The frequency of the resulting PWM signal is dependant on the frequency of the ramp waveform. Frequencies between 20Hz and 18kHz may produce audible screaming from the speed controller and motors. Each switching on and off of the speed controller MOSFETs results in a little power loss. Therefore the greater the time spent switching compared with the static on and off times, the greater will be the resulting ‘switching loss’ in the MOSFETs. The higher the switching frequency, the more stable is the current waveform in the motors. This waveform will be a spiky switching waveform at low frequencies, but at high frequencies the inductance of the motor will smooth this out to an average DC current level proportional to the PWM demand. This spikiness will cause greater power loss in the resistances of the wires, MOSFETs, and motor windings than a steady DC current waveform. It can be seen from the following two graphs. One shows the worst case on-off current waveform, the other the best case steady DC current waveform Both waveforms have the same average current. However, when we work out the power dissipation in the stray resistances in our motor and speed controller, for the DC case: and for the switching case, the average power is So in the switching waveform, twice as much power is lost in the stray resistances. In practice the current waveform will not be square wave like this, but it always remains true that there will be more power loss in a non-DC waveform. Choosing a frequency based on motor characteristics Then we can work out mathematically the minimum frequency to attain this goal. This section is a bit mathematical so you may wish to miss it out and just use the final equation. The following shows the equivalent circuit of the motor, and the current waveform as the PWM signal switches on and off. This shows the worst case, at 50:50 PWM ratio, and the current rise is shown for a stationary or stalled motor, which is also worst case. T is the switching period, which is the reciprocal of the switching frequency. Just taking the falling edge of the current waveform, this is given by the equation ? is the time constant of the circuit, which is L / R. So the current at time t = T/2 (i1) must be no less than P% lower than at t = 0 (i0). This means there is a limiting condition: So Generating PWM signals The PWM signals can be generated in a number of ways. It is possible that your radio receiver already picks up a PWM waveform from the handset transmitter. If there is a microcontroller on the robot, this may be able to generate the waveform, although if you have more than a couple of motors, this may be too much of a load on the microcontroller’s resources. Several methods are described below. Analogue electronics The PWM signal is generated by comparing a triangular wave signal with a DC signal. The DC signal can range between the minimum and maximum voltages of the triangle wave. When the triangle waveform voltage is greater than the DC level, the output of the op-amp swings high, and when it is lower, the output swings low. From the graph it can be seen that if the DC level went higher, the pulses would get even thinner. This uses a counter and weighted resistor ladder to generate the triangle wave (in fact it will generate a saw tooth, but you’ll still get a PWM signal at the end of it). The actual resistor values which are unavailable (40k, 80k) can be made up with 20k resistors, or close approximations can be used. The 74HC14 is a Schmitt input inverter, which is connected to act as a simple oscillator. The frequency of oscillation is roughly f = 1/(2.PI.R.C) but it doesn’t matter a great deal within a few tens of percent. This square wave generated feeds the 74HC163 binary 4-bit counter. All the preset and clear inputs of this are disabled, so the outputs, QA to QD just roll around the binary sequence 0000 to 1111 and rollover to 0000 again. These outputs, which swing from 0v to +5v are fed into a binary weighted summer amplifier, the leftmost LM324 opamp section with the 80k, 40k, 20k and 10k resistors. The output voltage of this amplifier depends on the counter count value and is shown in the table below as Amp1 output. The opamp following this just multiplies the voltage by -½ , to make the voltage positive, and bring it back within logic voltage levels, see the Amp2 output column in the table. Counter value Binary value Amp1 output (Volts) Amp2 output (Volts) 0 0000 0 0 1 0001 -0.625 0.3125 2 0010 -1.25 0.625 3 0011 -1.875 0.9375 4 0100 -2.5 1.25 5 0101 -3.125 1.5625 6 0110 -3.75 1.875 7 0111 -4.375 2.1875 8 1000 -5 2.5 9 1001 -5.625 2.8125 10 1010 -6.25 3.125 11 1011 -6.875 3.4375 12 1100 -7.5 3.75 13 1101 -8.125 4.0625 14 1110 -8.75 4.375 15 1111 -9.375 4.6875 The final, rightmost, opamp compares the voltage with the demand voltage input, which ranges from 0v to 4.6875v, where 0v represents 0% PWM ratio and 4.6875v represents 100% PWM ratio. This demand voltage may range from –12v to +12v but only the 0 to 4.6875 range will adjust the PWM ratio. PWM generator chips There are ICs available which convert a DC level into a PWM output. Many of these are designed for use in switch mode power supplies. Manufacturer IC Normal use SGS Thomson SG1524, SG1525… SMPS Maxim MAX038 Signal generation Alternatively, a MOSFET driver which includes a PWM generator can be used. I know of only one which is not yet released! The SGS Thomson TD340. Digital method The digital method involves incrementing a counter, and comparing the counter value with a pre-loaded register value. It is basically a digital version of the analogue method above: The register must be loaded with the required PWM level by a microcontroller. It may be replaced by a simple ADC if the level must be controlled by an analogue signal (as it would from a radio control servo). This method is only really practical if a microcontroller is being used in your robot, which can preload the register easily. Onboard microcontroller If it has this can greatly simplify the process of generating signals. The Hitachi H8S series has up to 16 PWM outputs available, but many other types have two or three. Interfacing to the high power electronics There are two sides to the electronics: the low-power side, and the high-power side. The low power electronics includes any onboard microcontroller, the radio control receiver, and PWM generators. The high-power side includes the MOSFET drivers, the MOSFETs themselves, and any solenoid or pump drivers that you may have. Basically anything that is switching large currents. Interfacing to the radio control receiver You may be able to tap into the PWM signal which comes out of the radio receiver before it goes into the servo, and use this to drive the input to the MOSFET driver. However, this gives you no choice of switching frequency. Alternatively, the potentiometer can generate a voltage to feed into the PWM generator. A more advanced method if you have a microcontroller on board the robot is to take the PWM signal from the radio receiver and connect it to a timer input of the micro. The microcontroller should be able to decode this waveform, and generate a proportional analogue output value (if it has ADCs, or if an external ADC is fitted). Another even more advanced method is to send serial communications data through the radio channel. The radio control handset will need to have a microcontroller in. The microcontroller should read the pots and switches on the handset, and send suitable commands out of its UART. This connects to the radio transmitter. At the receiver, the demodulated output is sent to the robot’s microcontroller’s UART, and the data is decoded. Current limiting Current limiting is absolutely essential. If the motor is stalled, it can take huge currents which would destroy the MOSFETs very quickly. The form of current limiting presented here is to measure the current that the motor is taking, and if it is above a preset threshold, turn the MOSFETs in the bridge off. If you have a microcontroller on board which generates the PWM ratio, it would be an advantage if the software could detect the over- current status, and reduce the PWM ratio by, say, 10%. This circuit shows just the upper MOSFETs of the bridge being driven for simplicity. The lower MOSFETs are not turned off during a current limit. There is only one sense resistor required for each motor, and that should be connected immediately from the battery positive terminal. The voltage dropped across the sense resistor is amplified by U1A, which is connected in a differential amplifier circuit. The gain of this is 480k / 1k which is 480. This is a very large gain because the voltage dropped across the sense resistor will be very small. The output of the differential amplifier is then heavily low pass filtered by RxCx. This is because there will be a lot of noise coming from the motor, and we do not want to limit the current if we don’t need to. D13 is present to make sure that no negative spikes can affect the following circuitry. U2B compares the filtered signal with a preset value (represented here by V5), and if the current is too high (i.e. the signal is greater than V5), U2B will turn Q1 and Q2 on which clamps the PWM signals from the PWM generator. This will force the MOSFET driver to turn the MOSFET off. Q1 must be repeated four times, one for each of the MOSFET driver channels, but all four transistors can be driven from U2B. D11, R14 and C4 make sure that the MOSFET doesn’t turn back on straight away, but takes a few milliseconds. This stops the MOSFET being rapidly turned on and off. A simulation of the current limiting part of this circuit is shown in the diagram below. The V5 threshold voltage was chosen to set a current limit of 30 Amps. The square wave is the PWM voltage (MOSFET gate voltage), and the sloppy waveform is the drain (motor) current. The spiky bit at the top of the slopey waveform is when the current limiting is switching in and out. Some circuits you may see sample the current going through the main power MOSFET by placing a much lower power MOSFET in parallel with it. This works OK, but the problem is the actual limiting current is dependant on the value of Rds(on) of the MOSFET. If Rds(on) was only half the value we were expecting it to be, then twice as much current would flow before the limiting circuit took effect. Also the Rds(on) value depends very much on the current that is passing through the MOSFET, and on the temperature. Any variation in Rds(on) will change the limiting current. The Rds(on) figure is quoted as a maximum value on the datasheet, but it is not a design-safe parameter. This means that it is not within defined limits which are published on the datasheet. For example, CMOS digital logic guarantees that the output voltage, Vo, will be between Vcc-0.5v and Vcc, and that figure can be used to design circuits which rely on that figure. However, with Rds(on), we only know that it will be between 0 and the quoted value. We cannot rely on a minimum value of it, yet it is the minimum value which controls the current limit. Therefore, using a separate shunt resistor is a much safer method. Feedback Speed Control To stop a robot swerving in an arc when you want it to go forwards, you need to have feedback control of the motor speeds. This means that the actual speed of each wheel is measured, and compared with all the other wheels. Obviously to go in a straight line, the motor speeds must be equal. However, this does not necessarily mean that the speed demand for each motor should be the same. The motors will have different amounts of friction, and so a ‘stiffer’ motor will require a higher speed demand to go as fast as a more free-running motor. A block diagram of an analogue feedback speed controller is shown below The speed demand is a DC voltage, which is fed to the PWM generator for motor A. This drives motor A at a speed dependant on the demand voltage. The speed of motor A is sampled using an optical encoder. This has a frequency output, which is proportional to the speed of the motor. If we assume that motor B is already running at some speed, then the optical encoder on its shaft will be producing a frequency also. The phase comparator compares the two frequencies, effectively comparing the speeds of the two motors. Its output is a signal which gets larger as the two input frequencies get further apart. If the two frequencies are the same, it has a zero output. The integrator adds the output of the phase comparator to whatever its output was before. For example, if the integrator output was previously 3 volts, and its input is 0 volts, then its output will be 3 volts. If its input changed to –1 volts, then its output would change to 2 volts. Let’s assume that motor B is running slower than motor A. Then the output of the phase comparator will be positive, and the output of the integrator will start to rise. The speed of motor B will then increase. If it increased to a speed greater than that of motor A, then the output of the phase comparator would become negative, and the output of the integrator would start to fall, thereby reducing the speed of motor B. In this manner, the speed of motor B is kept the same as the speed of motor A, and the robot will go in a straight line (as long as its wheels are the same size!). This method can be expanded to use any number of wheels. One motor will always be the directly driven one (in this case motor A), and the others will have their speed locked to this one. Note that if the directly driven motor is faster, or more free-running, than the others, then when it is driven at its fastest speed (the PWM signal is always ON), then the other motors will never be able to keep up, and the robot will still swerve. It is best, therefore, to directly drive the slowest motor.