Attainable PWM accuracy?

Oct 11, 2019 84 Replies

You could certainly analog sum two PWMs, maybe before the filter. They could run at a much higher frequency than a single PWM of the same resolution.

Sorry, that's too hard to think about.

a

rom

it

ely

l

MCU

tput

to

, so

ht

M, anyway?

ease

but

ion

k

but then you get the issue of how well analog matched the two outputs are

by inverting I meant reversing the bit order

i.e. 50% output becomes hi-lo-hi-lo-hi-lo-hi-lo instead of hi-hi-hi-hi-lo-lo-lo-lo

t

o

anyway?

se

t

This sort of stuff is easy in an FPGA, even a tiny, low power FPGA. You ca n also run the clock rate way above 7 MHz which makes filtering much easier .

Rick C. -- Get 2,000 miles of free Supercharging -- Tesla referral code - https://ts.la/richard11209

ing a

s from

ut it

tively

t'll

m a

45 MCU

output

ing to

so, so

ought

PWM, anyway?

ill ease

re, but

ension

hink

.
n
e

ts

nah, swapping bits just means the counter counts in a different order

but amount of numbers larger/smaller than the set point is still the same

i.e. it doesn't matter if you count to 1 to 256 in a random order, half of the numbers are bigger than 128

doing a

oes from

but it

tatively

It'll

rom a

C845 MCU

an output

ering to

or so, so

thought

a PWM, anyway?

will ease

ware, but

xtension

think

at.

can

ey

are

bits

I'm confused. The signal being output isn't the counter bits. It's a ther mometer code. Scrambling the bits would definitely improve the filtering.. . for some values, but not all. For example, one bit high and the rest low ... it doesn't matter where you put that bit, it passes through the filter the same way.

Someone was trying to explain to me how Sigma-Delta coding works and I kept getting hung up on the idea that outputing one bit high would always be th e same bit. With a Sigma-Delta code that bit moves around and so not alway s has the same impact on the filter. At least that was the picture the guy painted. The point is the signal has more high frequency content while th e same average value.

So what are you talking about with the counter bits being moved?

Rick C. -+ Get 2,000 miles of free Supercharging -+ Tesla referral code - https://ts.la/richard11209

As has been pointed out, sigma-delta DACs get 20-bit accuracy (and can do b etter) out of pulse width modulation. The process of scrambling the pulse o utputs to push the noise into the high frequency end of the spectrum is com plicated.

As Lasse Langwadt Christensen has pointed out, there are easier way of scra mbling the bits. I spelled out one in my 1996 paper

Sloman A.W., Buggs P., Molloy J., and Stewart D. ?A microcontroller

-based driver to stabilise the temperature of an optical stage to 1mK in th e range 4C to 38C, using a Peltier heat pump and a thermistor sensor? ? Measurement Science and Technology, 7 1653-64 (1996).

I limited the maximum switching rate to about 200kHz - to minimise switchin g losses in the power MOSFETs which were switching currents that could get up to three amps.

If you can live with a minimum pulse width of 133nsec, your worst cases are the single on or off pulses at 114Hz, and the next worst is the same singl e pulse at 228Hz.

Bill Sloman, Sydney

n:

en

m doing a

goes from

e, but it

entatively

? It'll

from a

LPC845 MCU

e an output

ltering to

t or so, so

er

ot

.

t thought

ke a PWM, anyway?

ch will ease

ftware, but

extension

't think

that.

re

P can

They

s are

e bits

ermometer code. Scrambling the bits would definitely improve the filtering ... for some values, but not all. For example, one bit high and the rest l ow... it doesn't matter where you put that bit, it passes through the filte r the same way.

pt getting hung up on the idea that outputing one bit high would always be the same bit. With a Sigma-Delta code that bit moves around and so not alw ays has the same impact on the filter. At least that was the picture the g uy painted. The point is the signal has more high frequency content while the same average value.

out counter[1:n];

So does that become a sort of poor man's delta-sigma? Same duty cycle but better spectrum?

John Larkin Highland Technology, Inc lunatic fringe electronics

iptechnology.com:

:
n

doing a

goes from

, but it

ntatively

? It'll

from a

PC845 MCU

an output

tering to

or so, so

r t

thought

e a PWM, anyway?

h will ease

tware, but

extension

t think

hat.

e

can

hey

are

bits

yes

here's an example from google:

formatting link

Very nice, but you have to watch switching losses. Unless I'm mistaken, this switches many times more frequently than with the bits not reversed.

CH

in:

en

doing a

oes from

but it

tatively

It'll

rom a

C845 MCU

an output

ering to

or so, so

thought

a PWM, anyway?

will ease

ware, but

extension

t think

hat.

e

can

They

ts are

e bits

lf

thermometer code. Scrambling the bits would definitely improve the filter ing... for some values, but not all. For example, one bit high and the res t low... it doesn't matter where you put that bit, it passes through the fi lter the same way.

kept getting hung up on the idea that outputing one bit high would always be the same bit. With a Sigma-Delta code that bit moves around and so not always has the same impact on the filter. At least that was the picture th e guy painted. The point is the signal has more high frequency content whi le the same average value.

yes it is a compromise

You could leave some low-order bits un-reversed, which would give you a bit each way.

n

kin:

nsen

n:

I'm doing a

ne goes from

ble, but it

tentatively

ng from a

e LPC845 MCU

be an output

filtering to

olt or so, so

rner

Not

ts.

n't thought

make a PWM, anyway?

hich will ease

software, but

s.

ma extension

on't think

e that.

more

uP can

. They

me

uts are

the bits

lf

thermometer code. Scrambling the bits would definitely improve the filteri ng... for some values, but not all. For example, one bit high and the rest low... it doesn't matter where you put that bit, it passes through the fil ter the same way.

kept getting hung up on the idea that outputing one bit high would always b e the same bit. With a Sigma-Delta code that bit moves around and so not a lways has the same impact on the filter. At least that was the picture the guy painted. The point is the signal has more high frequency content whil e the same average value.

Not sure that explains anything. But some of the other posts made me reali ze what you are talking about. As long as the modulus of the PWM counter i s 2^N then the counter runs through all possible codes. So any combination of bits can be used to generate the thermometer code and it will produce t he same number of 1 bits, but with a different pattern of higher frequency content.

The counter length is not always 2^N since that with the clock frequency de termines the sample rate and that is often set by controlling the modulus o f the counter.

Rick C. +- Get 2,000 miles of free Supercharging +- Tesla referral code - https://ts.la/richard11209

If there's memory, SPI+DMA does the bitbanging by itself.

mikko

This is why I don't like MCUs for most projects. It's so hard to get a sin gle tasking processor to do real time stuff. It's just so much easier to d o it in an FPGA where you just do what you need and don't have to worry abo ut twisting the durn thing into the shape required.

It would be so nice if they just included a thousand or so LUTs in with eve ry MCU. Then you could design the hardware you need rather than trying to fit the design into the limited hardware available.

Rick C. ++ Get 2,000 miles of free Supercharging ++ Tesla referral code - https://ts.la/richard11209

Here's an earlier incarnation of Woodward's idea:

piglet

h:

en

rkin:

nsen

n:

,

ed.

Published that back in 1996.

Sloman A.W., Buggs P., Molloy J., and Stewart D. ?A microcontroller

-based driver to stabilise the temperature of an optical stage to 1mK in th e range 4C to 38C, using a Peltier heat pump and a thermistor sensor? ? Measurement Science and Technology, 7 1653-64 (1996)

I thought it up in around 1975 but didn't get around to using it for anothe r twenty years.

Bill Sloman, Sydney

I don't like using busses on schematics, but some people do.

One of my guys named a uP address bus A[15:0] and connected the program eprom A[0:15}. The board didn't work. I wrote the eprom image builder program, so I had to add a switch to shuffle all the instructions around in the eprom programming file.

John Larkin Highland Technology, Inc lunatic fringe electronics

Lots of uP SPIs have FIFOs, or DMA ability, so some sort of PWM spectral manipulation might be done in software without getting too time critical.

We've done DDS sinewave synthesis in software, low audio range around

400 Hz. An periodic IRQ routine did the phase accumulator and sine lookup thing and loaded the uP internal DAC. I guess we could have made the sine wave from a PWM output, but the DAC was there.

The next refinement would be to use PWM in some sort of delta-sigma or bit reversed pattern, but that would take a screaming periodic IRQ rate, and my c programmer begrudges us every CPU cycle. Maybe he generates bitcoins in background or something.

John Larkin Highland Technology, Inc lunatic fringe electronics

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required