-1
\$\begingroup\$

Working on a project to design a PWM generator that has full-scale accuracy of 0.1%. It is generated by reading a variable voltage from the power supply through a voltage divider and producing an equivalent PWM output. I am filtering the output to measure the average voltage. I'm noticing that my output does not swing within 0.1%. I wonder if there are ways to make the PWM more precise and be able to reach the specs of 0.1% of full-scale?

I am not giving out schematics because they are very basic. What I am asking for is suggestions. I level shift my output with a comparator, then I filter it out to get the DC voltage back. I have succeded in getting a 0.1% FS accuracy. However, this was really a trial and error method, measuring the difference between input and output and adjusting my code accordingly. I don't like this; I much prefer a more systematic method. Maybe I am asking to much, there will just be a difference between thoery and practice.

\$\endgroup\$
  • 2
    \$\begingroup\$ Hello, you may want to give your question a bit more structure and details (schematics and measurement setup) to ensure a good answer. \$\endgroup\$ – Sclrx May 25 '18 at 8:52
  • 1
    \$\begingroup\$ What frequency? How stable is the clock signal for the microcontroller? Can you post a circuit diagram of the filter with component values? 0.15 of full scale would normally mean 15% - perhaps you left the units off? \$\endgroup\$ – Andrew Morton May 25 '18 at 8:53
  • \$\begingroup\$ This can't really be answered without schematics. What's the power supply, what makes you think the power supply in itself is so stable that it keeps within 0.1% of expectations? What's the voltage? And what do you feed as reference voltage to your ADC? \$\endgroup\$ – Lundin May 25 '18 at 8:59
  • 1
    \$\begingroup\$ To vague, the accuracy depends on many variables, PWM resolution, the switched voltage, the ON resistance of the switches , the filter used to smooth the output, the clock jitter etc. As I remember some microcontrollers do not use full scale PWM from 0 to 100%. I also hope that PWM resolution is at least 11 bits ( at least a bit more than the desired precision). Show all elements listed above as error sources to be able to help you. \$\endgroup\$ – Dorian May 25 '18 at 10:04
  • 2
    \$\begingroup\$ @Chu - If the PWM signal is used just to communicate a duty cycle (on to off ratio) it is very reasonable to expect that it can be used for a precise application. What does not work for precision is if the PWM waveform with sloppy high and low voltage levels is converted to an average voltage value. \$\endgroup\$ – Michael Karas May 25 '18 at 11:52
5
\$\begingroup\$

Simply using the port pin from a micro to generate a voltage by low-pass filtering won't typically work all that well because it depends not only on the power supply voltage, but the internal voltages at the MCU chip. If the micro is doing other things, or the supply is not very stable or is noisy you have little hope of getting the output to within a few mV.

To get accurate filtered value you need to switch a precise switch that is connected to a stable reference. The precise switch can be just a CMOS buffer or inverter gate (doesn't have to be an analog switch) but it must be connected to the reference voltage and analog ground, not the MCU supply and ground (the two grounds can and should be connected, but at only one point). The gate should be fast enough that rise and fall times are not a significant part of the PWM cycle time.

If you do that you can easily get 0.01% stability, with reasonable PWM times. Accuracy should depend primarily on your reference voltage stability and not on the MCU clock stability, unless it is terribly unstable or varies within a PWM cycle due to horrible layout or bypassing, for example. Using a purpose built analog switch may help a bit with linearity and absolute accuracy.

\$\endgroup\$
  • \$\begingroup\$ ... or, at that point, simply buy and use a DAC. (This answer is still very good and fully deserves my upvote.) \$\endgroup\$ – Marcus Müller May 25 '18 at 23:22
0
\$\begingroup\$

Precision PWM from a microcontroller can be accomplished through doing the following.

  1. Make sure your power supply and reference voltage are stable and not too noisy.
  2. Remove offset error, preferable through chopping it.
  3. Gain error correction.

Analog and digital ground should be connected at one point and used to correct your offset. Use a differential ADC one connected to your input signal and the other to the ground. Have the ADC switch its input and the offset would be removed. Doing these things I achieved 0.1% PWM with an Xmega MCU.

\$\endgroup\$

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.