Relationship between PWM frequency and an DAC's Resolution

EDIT: I initially asked this about ADCs instead of DACs, but that was a mistake, so I have changed the question accordingly.

Hey everyone!

TL;DR Does a DAC with resolution X mean it can work at a PWM frequency up to X? Or, in other words, is an DAC's precision of PWM voltage output limited by the frequency it is working at?

From my understanding, in the context of having a micro-controller interface with some output device, if you don't have an analog output pin to produce the needed analog voltage, you would use an digital-to-analog convert (DAC) pin, which outputs that same voltage using PWM. PWM has the pin turn on and off (each on or off = a pulse) at a given frequency (PWM frequency). The percentage of pulses that were on is the duty cycle, which in turn determines the voltage output (the on's and off's at certain proportions to each other average out to give some voltage). So if the max. voltage was 5V and the frequency was 50Hz, and you set 40 of the pulses to on, then that's an 80% duty cycle and a 4V output. Correct any of this if I'm wrong.

Now, say the pin that was carrying out this PWM had a resolution that was higher than the frequency. Say the ideal frequency to work with the output device was 50Hz and the analog-to-digital converter's pin's resolution was 64 (6-bit). From my understanding, 64-bit resolution means this ADC can split an analog signal into 64 discrete units. But if it is working at 50Hz, that's just 50 pulses, so only 50 possible discrete values because number of pulses relates to voltage output. Is there any meaning then to having a resolution higher than 50 here (of course 50 isn't an integer power of 2 but that's beside the point)? If not, then is it the case that In micro-controllers, the pulse value of the resolution is mapped using the frequency?

This came up with me because I am currently working with servos that function at 50-60Hz and the resolution of my ADC pins on my micro-controller is 4096, and I'm wondering do I really have that 0.001220703125V precision if the frequency is that?

Would very much appreciate any answer to this.

If you feed a PWM output directly to an analog input, the adc will either read zero or fullscale, depending on when you sample.

If you're generating the PWM signal, you know it's average voltage as the ratio of on/pulsewidth time multiplied by the supply volts.

What's the problem?

Allan

To figure out how a PWM controller works and how you can convert a PWM pulse into a voltage, you might see this tutorial:

https://provideyourown.com/2011/analogwrite-convert-pwm-to-voltage/

Once converted to a voltage via an RC filter, you might want to convert back this voltage to a number thru the ADC controller, providing this voltage is compliant with your ADC. E.g. a DUE has a 12-bit resolution ADC controller which means that a 0V – 3.3V range can be split into 2exp12 steps = 4096 steps.

allanhurst:
If you feed a PWM output directly to an analog input, the adc will either read zero or fullscale, depending on when you sample.

If you're generating the PWM signal, you know it's average voltage as the ratio of on/pulsewidth time multiplied by the supply volts.

What's the problem?

Allan

I'm asking about the relationship between PWM frequency of a given output device vs the resolution of whatever is supplying the PWM.

There is no such relationship..

The resolution of the PWM is entirely down to its number of bits.

Allan

comfortcube:
Hey everyone!

TL;DR Does an ADC with resolution X mean it can work at a PWM frequency up to X? Or, in other words, is an ADC's precision of PWM voltage output limited by the frequency it is working at?

Pulse width modulation is a scheme with a square (rectangular) waveform (having a chosen nominal frequency to begin with, having waveform voltage levels 0 and V for example). And EACH CYCLE of the rectangular waveform begins with a pulse with amplitude V (for example), and the width of this pulse is proportional to an input value, such as an input voltage. The width of the pulse can be as small as 0, and as high as the period of the PWM signal.

The PWM frequency (which is the frequency of the PWM signal) can be assumed to be precise and accurate.

The input value resolution has nothing to do with PWM frequency.

The error (uncertainty) associated with the ADC due to quantisation error, would contribute to the uncertainty in the width of the pulse...... because we want the pulse width to be proportional to the input value. This means...... uncertainty in input value will contribute to uncertainty in pulse width.

The PWM frequency is just fixed. So, for every T seconds (or microseconds for the PWM period)---- like clockwork ---- somebody says 'GO!'.... and then it's your job to keep the pulse at a level of 'V' Volts for 'x' seconds before dropping it back to 0 Volt. Frequency never changes. The only issue is...... we need to set the pulse width accurately. And that accuracy is up to the ADC. This is all assuming that the pulse width control begins with an analog voltage, which in turn is quantised (via an ADC) to give a digital codeword, which is then used as input to a processor-based PWM generator.

Obviously, PWM frequency will have uncertainty associated with it as well. But that's not related to the PWM technique.... and not related to the controlling and setting of pulse widths.

comfortcube:
Now, say the pin that was carrying out this PWM had a resolution that was higher than the frequency. Say the ideal frequency to work with the output device was 50Hz and the analog-to-digital converter's pin's resolution was 64 (6-bit). From my understanding, 64-bit resolution means this ADC can split an analog signal into 64 discrete units. But if it is working at 50Hz, that's just 50 pulses, so only 50 possible discrete values because number of pulses relates to voltage output. Is there any meaning then to having a resolution higher than 50 here (of course 50 isn't an integer power of 2 but that's beside the point)? If not, then is it the case that In micro-controllers, the pulse value of the resolution is mapped using the frequency?

If you have an input signal that is changing with time....... then the PWM frequency should be chosen to be much higher than the bandwidth of the input signal. And, the ADC sampling frequency should be much higher than the PWM frequency.

And.... regarding the 6 bit resolution. It means that it can split a voltage range into 2^6 = 64 different levels. If the PWM frequency is 50 Hz... then the PWM period is 1/50 = 0.02 seconds. So an input voltage range having 64 levels becomes translated to 64 levels (of pulse duration) across a 0.02 second range. Eg... 0V to 1V (input value) mapped to 0 seconds to 0.02 seconds (pulse width value).

I think you have DAC spelled incorrectly.

And ADC reads an external analog voltage - it's the Arduino analogRead().

It is not related to the generation of PWM, which is normally done using the output compare functionality of the timers (though it can be generated fully in software if you must)

comfortcube:
I'm asking about the relationship between PWM frequency of a given output device vs the resolution of whatever is supplying the PWM.

This sentence isn't clear ..... "relationship between PWM frequency of a given output device". If you say pwm frequency of a given output device, then that implies that this output device IS a PWM generator.

Also.... "vs the resolution of whatever is supplying the PWM.".... here... whatever is supplying the PWM appears to be the 'given output device'. So this is a head-to-tail loop thing. You probably need to convey your thoughts more clearly to avoid ambiguity. A drawing of your system could help make things really clear as well.

Also, PWM is generated (produced) by a PWM generator. The PWM signal is 'transmitted', and that PWM signal (waveform) is then 'received' at the receiving side.

There is no relationship between ADCs and PWM. At all. End of story. The fact that you even think this reveals that you have some deep misunderstanding of something, I can't quite tell what.

There is no inherent relationship between PWM frequency and duty cycle resolution, except that many dgital PWM sources will allow you to reduce resolution in order to increase frequency. This is only an artifact of the way counters are used generate a PWM signal from a digital circuit, and not an inherent relationship. It is also nothing like the incoherent mess that you've posted.

As brought up by MorganS, you seem to be confusing ADCs with DACs, although your entire post is so nonsensical that it's hard to tell what you're actually thinking.

The percentage of pulses that were on is the duty cycle

No, the duty cycle is the percentage of time that the pulse is HIGH. It doesn't matter if the base frequency is 1 mHz or 1 MHz.

So if the max. voltage was 5V and the frequency was 50Hz, and you set 40 of the pulses to on, then that's an 80% duty cycle and a 4V output. Correct any of this if I'm wrong.

You are very wrong. The fundamental frequency of a waveform and its duty cycle are completely unrelated.

At this point, I don't know what else to tell you except that your "understanding" of this topic is horribly confused, so try finding some other things to read that might explain it better.

allanhurst:
There is no such relationship..

The resolution of the PWM is entirely down to its number of bits.

Allan

My God. My sincerest apologies. I meant DACs, not ADCs. Newbie mistake. And my question is answered now.

MorganS:
I think you have DAC spelled incorrectly.

Thank you for pointing that out. I completely messed that up. Apologies to everyone who already replied confused at my question. And my question is answered now.

I'm curious to know what the answer is, because I think most people here didn't even know what the question was.

Jiggy-Ninja:
I'm curious to know what the answer is, because I think most people here didn't even know what the question was.

I think so. The opening question was...

"Does a DAC with resolution X mean it can work at a PWM frequency up to X?"

If the resolution is 1/64 .... then the question would become "Does a DAC with resolution 1/64 mean it can work at a PWM frequency up to 1/64?"

So even if the DAC did relate to pwm frequency.... the question would still have issues.

O.P. could help clarify things maybe.

Jiggy-Ninja:
I'm curious to know what the answer is, because I think most people here didn't even know what the question was.

Southpark:
I think so. The opening question was...

"Does a DAC with resolution X mean it can work at a PWM frequency up to X?"

If the resolution is 1/64 .... then the question would become "Does a DAC with resolution 1/64 mean it can work at a PWM frequency up to 1/64?"

So even if the DAC did relate to pwm frequency.... the question would still have issues.

O.P. could help clarify things maybe.

So what I intended in my original question was whether the ideal frequency of a device receiving a PWM signal (so usually motors or LEDs) limited the ability to use the maximum resolution of a DAC if the resolution was higher than the frequency. The reason I came to this question to start with was because I was reading documentation on working with a servo controller using a Raspberry Pi (the PCA9685 https://cdn-learn.adafruit.com/downloads/pdf/adafruit-16-channel-servo-driver-with-raspberry-pi.pdf ) and towards the end, it shows the methods of the class. One is to set_pwm_frequency, and in the description it says that is to set the number of pulses per second generated. The other is set_pwm(), and when the description said a number from 0 to 4096 (referring to the resolution) and "ticks", I thought "ticks" and "pulses" were the same thing, so if there were only X "pulses" as per the frequency, and the resolution could go higher than that, is it limited? And on top of that, I thought PWM worked by having X pulses HIGH and Y pulses LOW in a given time interval. But, Southpark's answer cleared it up - it's the individual pulses that are modulated, which means frequency doesn't matter.

Apologies for this confusion. I went about asking the wrong way, and me mixing ADC and DAC up certainly did not help.

And on top of that, I thought PWM worked by having X pulses HIGH and Y pulses LOW in a given time interval.

From a certain point of view, this is not completely wrong.

TL;DR, digital circuits generate PWM signals by dividing down a much higher frequency clock signal using a counter. The signal is set when the counter is below the requested value, and cleared when it is higher.

It has to do with the way digital circuits (as opposed to analog circuits) create a PWM signal. Central to the method is a counter register. A counter is a digital circuit that increases (or decreases) its value by 1 whenever an transition occurs on it's input. A timer is simply counter that is supplied a clock signal with known, fixed frequency. For a 16 MHz Arduino, that frequency is 250 kHz (16 MHz / 64). This is set up as part of the initialization code that you don't see that is run before setup(). A Raspberry Pi's PWM peripheral will be set up differently, but the basic theory will also apply.

The timers in an AVR Arduino are set up by default for 8-bit mode. That means it takes 256 (28) clock edges for the counter value to fully roll over from 0 to 0 again. The Raspberry Pi's is apparently 12-bit, and takes 4096 (212) clock edges to roll over.

The counter is paired with a digital comparator circuit that compares two digital numbers and determines which one is larger or smaller. One of the values used is the counter value, and the other is the requested duty cycle value. The output from this circuit is what is used as the PWM signal. While the counter value is lower than the duty cycle value, the PWM output will be HIGH. When the counter goes past the duty cycle value, the PWM output goes LOW.

The input clock signal is what is referred to by "ticks". Generally speaking, the resolution of the PWM signal is the number of input ticks needed to do a full roll over of the counter value. The resolution and frequency can be chosen independently of each other though, as long as you are capable of generating an input clock with the necessary frequency (output frequency * resolution).

So wrapping this up, the set_pwm_frequency method in the R-Pi documentation is setting the input frequency used by the PWM timer (which would be output frequency * 4096), and set_pwm is setting the duty cycle value used by the digital comparator (probably supposed to be 0-4095).

If you're trying to interpret a PWM signal, it's resolution is what will determine the maximum amount of resolution you can extract from it and meaningfully use with a DAC. The frequency will have an effect though, since slower frequencies will make it take longer for changes in the PWM value to be registered.

comfortcube:
So what I intended in my original question was whether the ideal frequency of a device receiving a PWM signal (so usually motors or LEDs) limited the ability to use the maximum resolution of a DAC if the resolution was higher than the frequency.

Definitely happy to help comfortcube. Thanks for clarifying things. But, just mentioning something extra here... just in case. It's possible that some terminology may be mixed here. Eg...... the statement 'resolution higher than frequency' is out of context. In terms of measurement..... resolution is the smallest increment (value).....gradation....or something like that. Frequency is a rate (of occurrence)...... in this case, the rate of one full cycle of a repetitive (periodic) waveform per second. 1 cycle per second is the same as 1 Hertz. The period of a waveform T (in units of seconds) is related to frequency f (in Hertz, or Hz) ..... by this equation... f = 1/T.