Improve PWM outputs with S/H?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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?

Re: Improve PWM outputs with S/H?
On Wednesday, September 13, 2017 at 8:21:43 PM UTC+10, whit3rd wrote:
Quoted text here. Click to load it
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.
  
Quoted text here. Click to load it
 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.
Quoted text here. Click to load it

So use a multipole filter, set up for maximally rapid settling.
  
Quoted text here. Click to load it
e

Perhaps.
  
Quoted text here. Click to load it

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



Re: Improve PWM outputs with S/H?
On Wednesday, September 13, 2017 at 5:06:32 AM UTC-7, snipped-for-privacy@ieee.org wrote:
Quoted text here. Click to load it

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.

Re: Improve PWM outputs with S/H?
Den onsdag den 13. september 2017 kl. 23.22.52 UTC+2 skrev whit3rd:
Quoted text here. Click to load it

bresenham and delta-sigma are quite similar  

Re: Improve PWM outputs with S/H?
On 14/09/17 07:22, whit3rd wrote:
Quoted text here. Click to load it

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

Re: Improve PWM outputs with S/H?
On Wednesday, September 13, 2017 at 6:21:43 AM UTC-4, whit3rd wrote:
Quoted text here. Click to load it

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.  

Re: Improve PWM outputs with S/H?
On 13/09/17 22:33, George Herold wrote:
Quoted text here. Click to load it

Sigma-delta, in other words.


Re: Improve PWM outputs with S/H?
cycle
Quoted text here. Click to load it

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

m
  

Re: Improve PWM outputs with S/H?
On Wednesday, September 13, 2017 at 9:08:04 AM UTC-4, Clifford Heath wrote:
Quoted text here. Click to load it

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.    


Re: Improve PWM outputs with S/H?
On 13/09/2017 23:07, Clifford Heath wrote:
Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

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.


Re: Improve PWM outputs with S/H?

critto:

Quoted text here. Click to load it
  
Quoted text here. Click to load it
  
Quoted text here. Click to load it

http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious

Bye Jack

Re: Improve PWM outputs with S/H?
On 13/09/17 16:50, snipped-for-privacy@gmail.com wrote:

Quoted text here. Click to load it

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.



Re: Improve PWM outputs with S/H?
Den onsdag den 13. september 2017 kl. 16.40.46 UTC+2 skrev Chris Jones:
Quoted text here. Click to load it

ering,  
Quoted text here. Click to load it
  
Quoted text here. Click to load it

Quoted text here. Click to load it
row
e
  
Quoted text here. Click to load it

mp can buffer
Quoted text here. Click to load it
obe

f the
Quoted text here. Click to load it

Quoted text here. Click to load it
  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
  
Quoted text here. Click to load it

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

  



Re: Improve PWM outputs with S/H?
On Thursday, September 14, 2017 at 7:22:52 AM UTC+10, Lasse Langwadt Christ
ensen wrote:
Quoted text here. Click to load it
  
Quoted text here. Click to load it

ltering,  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
ly  
Quoted text here. Click to load it

Quoted text here. Click to load it
't
 grow
Quoted text here. Click to load it
lue
M  
Quoted text here. Click to load it
a

 amp can buffer
Quoted text here. Click to load it
trobe

 of the
Quoted text here. Click to load it

r
Quoted text here. Click to load it
  
Quoted text here. Click to load it
n  
Quoted text here. Click to load it
m  
Quoted text here. Click to load it
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.
  
Quoted text here. Click to load it
to lookups and compares.

Probably true.

--  
Bill Sloman, Sydney


Re: Improve PWM outputs with S/H?
Den torsdag den 14. september 2017 kl. 01.49.08 UTC+2 skrev snipped-for-privacy@ieee.o
rg:
Quoted text here. Click to load it
stensen wrote:
Quoted text here. Click to load it
e:
Quoted text here. Click to load it
  
Quoted text here. Click to load it

filtering,  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
e  
Quoted text here. Click to load it
owly  
Quoted text here. Click to load it

e.
Quoted text here. Click to load it
on't
ll grow
value
PWM  
Quoted text here. Click to load it
d a

/H amp can buffer
Quoted text here. Click to load it
 strobe
Quoted text here. Click to load it

ny of the
Quoted text here. Click to load it

 or
Quoted text here. Click to load it
ts  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
 in  
Quoted text here. Click to load it
hem  
Quoted text here. Click to load it
d like with a timer.
Quoted text here. Click to load it
at a lower fraction of the full clock rate, and get most of the advantage.
Quoted text here. Click to load it

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



Re: Improve PWM outputs with S/H?
On Thursday, September 14, 2017 at 10:01:21 AM UTC+10, Lasse Langwadt Chris
tensen wrote:
Quoted text here. Click to load it
.org:
Quoted text here. Click to load it
ristensen wrote:
Quoted text here. Click to load it
s:
Quoted text here. Click to load it
ote:
Quoted text here. Click to load it
4,  
Quoted text here. Click to load it

C filtering,  
Quoted text here. Click to load it
    
Quoted text here. Click to load it
the  
Quoted text here. Click to load it
slowly  
Quoted text here. Click to load it

ade.
Quoted text here. Click to load it
 won't
Quoted text here. Click to load it
will grow
  
Quoted text here. Click to load it
d value
e PWM  
Quoted text here. Click to load it
and a

 S/H amp can buffer
Quoted text here. Click to load it
he strobe

 any of the
Quoted text here. Click to load it

dd or
Quoted text here. Click to load it
bits  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
ng in  
Quoted text here. Click to load it
 them  
Quoted text here. Click to load it
iod like with a timer.
Quoted text here. Click to load it
n at a lower fraction of the full clock rate, and get most of the advantage
.
Quoted text here. Click to load it
mer  
Quoted text here. Click to load it
  
Quoted text here. Click to load it

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

Re: Improve PWM outputs with S/H?
Den torsdag den 14. september 2017 kl. 03.45.05 UTC+2 skrev snipped-for-privacy@ieee.o
rg:
Quoted text here. Click to load it
istensen wrote:
Quoted text here. Click to load it
ee.org:
Quoted text here. Click to load it
Christensen wrote:
Quoted text here. Click to load it
nes:
Quoted text here. Click to load it
wrote:
Quoted text here. Click to load it
024,  
Quoted text here. Click to load it

 RC filtering,  
Quoted text here. Click to load it
C.    
Quoted text here. Click to load it
e the  
Quoted text here. Click to load it
o slowly  
Quoted text here. Click to load it

 made.
Quoted text here. Click to load it
ge won't
e will grow
Quoted text here. Click to load it
d  
Quoted text here. Click to load it
old value
the PWM  
Quoted text here. Click to load it
.
t and a

al S/H amp can buffer
Quoted text here. Click to load it
 the strobe
Quoted text here. Click to load it

ve any of the
Quoted text here. Click to load it

 add or
Quoted text here. Click to load it
.
e bits  
Quoted text here. Click to load it
re  
Quoted text here. Click to load it
sing in  
Quoted text here. Click to load it
te them  
Quoted text here. Click to load it
eriod like with a timer.
Quoted text here. Click to load it
run at a lower fraction of the full clock rate, and get most of the advanta
ge.
Quoted text here. Click to load it
timer  
Quoted text here. Click to load it
ou  
Quoted text here. Click to load it
s, you can still set up a timer.
Quoted text here. Click to load it

if you have to  interrupt that cpu you might as well do something a bit sma
rter than reversing bits


Re: Improve PWM outputs with S/H?
Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

use a fast PWM.

say an 8 bit timer/counter in the AVR clocked at full clock speed set the most  
significant bits of the value in the PWM register in an interrupt service routine  
use whatever method to reverse low bits to decide when to dither the PWM value to  
+1 - you only have to make this computation every 256 cycles, so so
long as you can do in in fewer than 200 instructions (I estimate under 20 needed)  
there should be room to run code oustside of the ISR too.  

--  
This email has not been checked by half-arsed antivirus software  

Re: Improve PWM outputs with S/H?
On Wednesday, September 13, 2017 at 12:21:43 PM UTC+2, whit3rd wrote:
Quoted text here. Click to load it

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

Cheers

Klaus

Re: Improve PWM outputs with S/H?
On Wednesday, September 13, 2017 at 3:05:36 PM UTC+2, Klaus Kragelund wrote:
Quoted text here. Click to load it

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

Site Timeline