Improve PWM outputs with S/H?

A simple timer can set a pin HIGH for N clock cycles out of 1024, then LOW for

1024 - N clock cycles. That output pin, with some RC filtering, generates about the same range and precision of voltages as a 10-bit DAC. But, cheaper.

It also has ripple, because the filtered output ramps UP while the pin is high, and DOWN while low, dithering around the intended value, in addition to slowly (exponentially) decaying to a new average output value when a change is made.

The RC time constant ought not to be made too long, or a change won't propogate quickly, but cannot be made too short, or the ripple will grow to be more than an LSB of the output.

If one were, however, to use an analog switch in a sample/hold amplifier, taking a sample at N/2 cycles and/or at N + (1024-N)/2, the hold value would both ramp as quickly as the RC time (give or take half the PWM cycle period), AND would be devoid of the triangle-wave-like ripple.

So, the idea is to change from one PWM output, to a PWM output and a two-pulse strobe auxiliary output. Then an external S/H amp can buffer the PWM aerage value, while rejecting the PWM ripple (because the strobe selects the centerpoints of rise and fall phases).

Does a cheap (?quad) S/H chip exist to support this? Have any of the usual controller chips ever had an output option like this?

Reply to
whit3rd
Loading thread data ...

W for

es

eaper.

It can make sense to switch the output more frequently. Sigma-delta modulat ion exploits this.

A primitive version of this compares the desired output (a fixed 10-bit bin ary number) with a counter hooked up backwards, so the least significant bi t of the counter (which is toggling more or less non-stop) is compared with the most significant bit of the fixed number.

I thought this up around 1976, and got to use it around 1993. It's publishe d here

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)

in section 2.6.

high, and DOWN while low, dithering around the intended value, in addition to slowly (exponentially) decaying to a new average output value when a ch ange is made.

So use a multipole filter, set up for maximally rapid settling.

e

Perhaps.

Never heard of one. Sigma-delta D/A converters are commercially available a nd have been for many years. No doubt somebody here will tell you what's cu rrently favoured. Ten bits isn't exactly difficult.

--
Bill Sloman, Sydney
Reply to
bill.sloman

I don't know. How about some algorithm that doesn't just add or subtract bits from the end, but takes them out of the middle... in some judisious manner such that the short term average is about equal to the long term average.

George H.

Reply to
George Herold

The price for a S/H chip and amplifier would be a lot higher than a microcontroller with the needed DAC

Cheers

Klaus

Reply to
Klaus Kragelund

Also, for a PWM output the VDD ripple ruins the accuracy, so a 10bit DAC on a 3V supply would need to have a supply with quite accurate voltage void of supply load regulation effects

Cheers

Klaus

Reply to
Klaus Kragelund

Sigma-delta, in other words.

Reply to
Clifford Heath

cycle

i think you will find that adding poles (i.e. more RC sections) to your filter will be easier and more fruitful.

m
Reply to
makolber

Maybe, I don't really know about sigma-delta (S-D) DAC's. (Reading in AoE... ) Well I was picturing something different, but maybe the output pulse stream is the same. If the output was (say) 3/4 full scale what would the S-D output stream look like. I'm seeing 3 high, 1 low, 3 high, 1 low...etc.

George H.

Reply to
George Herold

Or if a full sigma-delta is not worth the bother, just reverse the bits in the counter value (assuming it counts from 0 to (2^N)-1 ) before comparing with the duty cycle value, as Bill suggested. Bit-reversing in software is messy, so if I'm not short of memory then I pre-compute them and use a lookup table.

When I am doing software PWM like that, usually it is to dither between two adjacent duty cycle values in a hardware PWM unit, because I ran out of resolution.

Reply to
Chris Jones

critto:

formatting link

Bye Jack

Reply to
jack4747

Many microcontrollers have bit-reverse instructions. If you are lucky, your compiler (possibly with particular headers) has a convenient function for it. If not, then a line of inline assembly will do the job.

Reply to
David Brown

That's not clear. One kind of S/H chip is just a Miller capacitor (built into all compensated op amps) and a way to strobe the bias current that drives it. It's not a hard circuit to build (about the same as a programmable-bias op amp) and many PWM outputs need a buffer amplifier anyhow.

Analog function in the S/H, digital function in the microcontroller, seems like a good inexpensive pairing. An ADC on the controller adds precision resistors, and an external ADC is likewise usually a mixed digital/analog function (or takes LOTS of wires out of the controller to connect it).

Reply to
whit3rd

ering,

row

e

mp can buffer

obe

f the

bit reversing mean you have to run at the full clock rate not the period li ke with a timer.

a sigma-delta is just a couple of adds it's hardly any worse than having to lookups and compares

Reply to
Lasse Langwadt Christensen

Interesting: a Bresenham algorithm could make an output-only control, with fine clock timingl, that would beat the simple PWM algorithm (that only allows two transitions repeated in each fixed timeframe). That would be a hard-ish logic problem, but supportable in the right logic hardware (or could be faked up in software, given enough CPU cycles).

It simplifies the output filtering, because it isn't a 1024-clocks ripple frequency bandwidth any more. I'm dubious that it'll be the low-cost option on an Arduino any time soon, though.

Reply to
whit3rd

bresenham and delta-sigma are quite similar

Reply to
Lasse Langwadt Christensen

ltering,

ly

't

grow

lue

M
a

amp can buffer

trobe

of the

r

n
m

like with a timer.

If you only reverse the higher order bits, as I did in 1996, you can run at a lower fraction of the full clock rate, and get most of the advantage.

to lookups and compares.

Probably true.

--
Bill Sloman, Sydney
Reply to
bill.sloman

Den torsdag den 14. september 2017 kl. 01.49.08 UTC+2 skrev snipped-for-privacy@ieee.o rg:

e:

filtering,

e

owly

e.

on't

ll grow

value

PWM

d a

/H amp can buffer

strobe

ny of the

or

ts

in

hem

d like with a timer.

at a lower fraction of the full clock rate, and get most of the advantage.

what I mean is that if you use regular PWM on a CPU you'd just setup a time r and don't have to do anything until you decide to change the duty cycle

if you want to reverse bits you there is not hardware to do the work, you have to do a compare for every clock cycle

Reply to
Lasse Langwadt Christensen

.org:

s:

ote:

4,

C filtering,

the

slowly

ade.

won't

will grow

d value

e PWM

and a

S/H amp can buffer

he strobe

any of the

dd or

bits

ng in

them

iod like with a timer.

n at a lower fraction of the full clock rate, and get most of the advantage .

mer

And what I meant was that if you only reverse a few of the high order bits, you can still set up a timer.

In my 1996 paper, we did the bit comparison in a small programmable logic d evice - ICT7024 - and limited the maximum switch rate to about 280kHz (thou gh the underlying clock rate was 17.82MHz). If we'd wanted to do it in a CP U we'd have set the timer to interrupt every 3.6usec, not at 17.82MHz.

We limited the maximum switching rate because we wanted to hold down the sw itching losses in the MOSFET drivers to about the same level as the resisti ve losses - we didn't have the space to heat-sink the MOSFETs to any great extent.

--
Bill Sloman, Sydney
Reply to
bill.sloman

I did a four-channel 8-bit Bresenham PWM in an MC68HC11 in 1999. It would be trivial in an AVR. Here's the assembly code from the PWM timer interrupt handler for a two-channel version that controlled the drive and steering motors of a robot car. Basically you just add the 8-bit drive level to an 8-bit accumulator and output the carry bit as PWM, it's completely trivial. I recall this method was called "SmoothPWM" at the time, but I can't find a record of it now.

  • Motor Interrupt: CarMotorRun: ldab CarDirection ; Motor Enable/Dir value into reg B

ldaa CarSpeed ; Get main motor speed adda CarSpeedPwm ; Calculate new pulse into carry flag staa CarSpeedPwm ; and save the remainder bcs DoMainPulse ; If we don't want a pulse... andb #$F3 ; clear main motor bits DoMainPulse:

ldaa CarSteer ; Get steering motor power adda CarSteerPwm ; Calculate new pulse into carry flag staa CarSteerPwm ; and save the remainder bcs DoSteerPulse ; We need a pulse, so leave it in A andb #$FC DoSteerPulse:

  • Real output: stab PORTC
  • Diagnostic putchar - show the byte for PortC
  • tstb
  • beq CarDone
  • jsr putchar

CarDone: rts

Reply to
Clifford Heath

Thing is, the gain is illusory. Yes, when the signal is static, you get rid of the ripple -- for DC signals, it's a win. But as soon as the signal changes, you get a whopping huge step, or staircase, as the filter follows the change, and the S&H chops it up.

It's just sampling theory all over again: the S&H is a first-order hold. We can apply this theory to see that, we haven't filtered anything, we've just sampled it, putting F_ripple at Fs, where the ripple gets aliased to DC.

Indeed, if we vary the phase between PWM and sample clocks, the output DC offset varies, as it's intercepting a different point along the ripple waveform. How do you know what phase is correct? Are you going to calibrate it?

Any ripple that appears within the sampler's bandwidth (i.e., Fs/2 give or take) is passed unchanged, or indeed may be worsened because it's squared up in the process -- you get THD, that still needs to be filtered if you want a smoothly changing signal.

So you still need the ripple filter. You've aliased F_ripple to DC, and aliased everything else to the harmonics of Fs.

You can solve some of this in digital -- in which case the solution approaches a S-D converter of some order. Or solving it in analog, it's just a higher order filter with the usual bandwidth and settling time tradeoffs.

No free lunch. ;-)

Note that higher order S-D converters have a multi-pole filtering effect. They call it noise shaping. The effect is to reduce converter noise in the passband, pushing it up closer to Fclk. You get wider bandwidth for a given SNR.

Tim

-- Seven Transistor Labs, LLC Electrical Engineering Consultation and Contract Design Website:

formatting link

Reply to
Tim Williams

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.