# How can I increase the resolution of a PWM signal?

Say I have a motor and I want it to spin at exactly 2042.8878 revolutions per minute. Say I have a very precise sensor to detect the RPM of the motor to a resolution of 1/1000th of a revolution per minute.

• Can I produce a PWM signal which can match the speed to that degree of precision?

• What variables in the signal parameters would I have to adjust to get the precision if possible?

• Would I have to use additional circuitry between the motor and the driver?

• Would I have to design the signal/circuitry around the specific specifications of the motor?

• Should I just use a stepper motor?

This is assuming I am using a microcontroller to measure the motor's speed and adjust the signal in real-time to maintain a certain speed.

• If your "PWM signal" is the input voltage to the motor and you are trying to control that voltage to regulate the speed, then I think you need to look up closed-loop feedback control before really asking this here. And more appropriate for your question, information like this or this. Nov 25 '15 at 11:59

You won't ever get 'exactly' 2042.8878 RPM, so going with your measurement accuracy I will assume you mean 2042.8878 +/- 0.0005 RPM. This is approximately an error of 1 part in 4 million. So let's assume you can set up a timer which counts up to around 4 million and resets, and use that for the PWM. Assuming a two pole motor, 2042 RPM is 34 electrical rotations per second, and you would want to PWM it at with about ten PWM cycles per electrical rotation, so your PWM timer needs to increment (4 million * 10 * 34 ) times per second, equivalent to 1.4 GHz.

There are microcontrollers with that sort of clock frequency, so it is not downright impossible. You'd also have to do the PID control to calculate what the value should be, and doing that to one part in 4 million will take a time to settle.

Stepper motors typically don't run that fast - torque drops to zero around 1200 RPM, though some specialist steppers can run faster ( see SteveO's comment below ).

Brushless motors would require commutation through six phases, and ideally have a several PWM cycles per phase, so would need around six times the timer frequency and so be out the range of simple PWM.

You can also dither the PWM so of the ten per phase energised you stretch n to give one more digit; this would reduce the clock required by a factor of 10 so may make it practical, but it's not trival to control to that level of accuracy.

• Could you elaborate more on why 10 PWM cycle are needed for an electrical rev?
– 50k4
Nov 25 '15 at 15:37
• Typically you'd want enough so the motor, which is behaving somewhat like a low-pass filter, develops a constant torque through the revolution; ten is probably enough for this. If your PWM is too slow compared to the commutation speed, then you can get situations where in a brushless motor turning off some phases completely and others on full, whereby the motor runs very poorly; in a brushed DC motor there's a bit more laxity but you don't want your PWM to be say on for one revolution then off for the next if you're trying to hold a constant speed. Nov 25 '15 at 16:36
• in a PMSM (Permanant Magnet Syncrouneous Motor) this problem is also less significant then in a BLDC (Brushless Direct Current), right?
– 50k4
Nov 25 '15 at 17:30
• Good answer Pete. One nit: I've found steppers capable of more than 1200 RPM. For example, look at Kollmorgen's P2H series, which can produce about 50% of max torque as high as 3000 RPM. Nov 25 '15 at 20:32
• Thank you for taking the question seriously. Your answer helped me to confirm my current understanding of the problem and will help me to look in the right direction for the information that I still need to learn. Nov 26 '15 at 23:32

The PWM signal should not be the limiting factor in achieving the accuracy you seek. For some applications, PWM signals are chopped > 100 kHz, so, given the correct DSP or microcontroller output to create the PWM, you will have as much control over the power going into the motor as you need.

Most of the motion control system I've built have had PWM amplifiers between the microcontroller and the motor. If you don't have those amplifiers, then yes, you will need to put additional circuitry between your controller and your motor. You can get these off-the-shelf, or you can chop a power FET (often using another FET to get the speed) based off of a variable duty-cycle pulsed signal. It is this chopping signal that you will adjust to drive more, or less, power into your motor. If your system's load varies greatly, you may need to put a control loop around this signal so you can keep it stable. See Brian's references about speed control of motors. Loops similar to those position and speed control loops would be used to dampen the rate of change of your PWM driver.

I think you need to look at your specifications, though. If your sensor has a shaft rotation resolution of 1/1000 rpm, how will you ever control the shaft to a speed of XXXX.YYYY (1/10,000 rpm accuracy)?

For a continuous-rotation application, a stepper might be a better solution. It is brushless for long life, easy to control, and has its own type of feedback. But you need to be sure to get enough pulses per revolution to get the accuracy you're looking for. If you have a 512 pulse/rev stepper, that is only ~ 30k pulses/min. With that you can barely achieve a speed accuracy of 1/10k.

• Thank you for taking the question seriously. Your answer helped me to confirm my current understanding of the problem and will help me to look in the right direction for the information that I still need to learn. Nov 26 '15 at 23:32

Using a hardware PWM system based on a comparison-voltage source, a triangle-wave generator, and a comparator, you can set as many different output levels as your comparison-voltage source can generate. A charge-transfer system like that diagrammed below can be used to develop almost arbitrarily many different levels.

In operation, the voltage on C1 supplies one input to a comparator, via a unity-gain buffer. A triangle wave oscillator supplies the other input, generating a PWM signal.

The voltage on C1 is set by turning on, turning off, or setting to high-impedance one or more of digital inputs D1...D3, then turning on D4 for a controlled interval, to slightly raise or lower the voltage on C1. For example, suppose C1 = 0.1 μF and VC1 = 2 V. Turning on D4 for 1 ms with D1 on will raise VC1 by .21 V; turning on D4 for 4 μs with D3 on will raise VC1 by 8 μV.

If you want to control to about 1 part in 4 million using this method in simplest form, then R3 may need to be larger. But of course slightly more involved alternative schemes can get by with smaller resistors. For example, if R2 is 10 MΩ and R3 is 10.01 MΩ, you could raise VC1 by a few nV by turning on D2 high for a fraction of a microsecond, then returning it to high impedance and turning on D3 low for the same length of time, or could lower VC1 by doing vice versa; or could turn on both briefly high, then one briefly low, etc. Another approach is to have D4 trigger a one-shot that closes S1 for a few nanoseconds, rather than depending on use of a fast microcontroller clock.

If you actually use a system like this, write a program that computes voltage rates of change for all combinations of your digital inputs, at various voltages on C1. Also analyze the system for stability.

Note, D4 is controlling a JFET switch S1 to isolate C1 from leakage that could occur through D1-D3 if S1 were left out. For example, the Atmega328 data sheet shows a max leakage of 1 μA on typical inputs in high impedance state, which is about a million times the leakage of a good JFET. However, typical leakages of Atmega inputs – rather than max leakages – might be much less. One could run experiments to see if S1 is indeed necessary.

• Thank you for taking the question seriously. Your answer helped me to confirm my current understanding of the problem and will help me to look in the right direction for the information that I still need to learn. Nov 26 '15 at 23:33
• @JohnEuell, please feel free to upvote or accept useful answers! Nov 27 '15 at 1:40