It is an interesting question – how many effective bits do you have for a PWM output? And how do you work it out?

I sometimes run a webinar about this and I go through the number of bits that you effectively get out of the PWM. It turns out that it is the maximum count less the minimum count and then you take the logarithm to the base two of that number to get the number of bits. For those of you who don’t remember logarithms to the base two you take the natural logarithm (ln on your calculator) and then divide by ln(2). As an example for a maximum count of 128 and a minimum of 0 then ln(128)/ln(2) gives 4.8520/0.6931 =7 which is perfect as 128 is 2^7.

If the maximum count is 12435 and the minimum is zero then the number of bits is 13.602 bits. Yes you have a fractional number of effective bits.

Is 13.602 bits enough? Probably not or probably yes. It does depend on the application. Typically its not quite enough.

How do you get to this. If you have a 8.0418 kHz switching frequency and a 10ns clock (100MHz) then you get 13.602 bits.

If you have an 80.418 kHz switching frequency and the same 10ns (100MHz) clock then you have a count of 1243 which is 10.279 bits. That is ln(1243)/ln(2) = 10.279 bits.

So that’s how you calculate the number of bits you have in your PWM.

And you may be asking why are you writing blogs about this. Well I repeatedly get asked this question and others like it so I thought I’d write them into blog posts. I am trying to write one every two weeks