precise high res pwm - Page 1
Forum section: electronics / general

author: acbern
author_rank: Frequent Contributor
timestamp: April 12, 2014, 02:25:02 pm
content: does anybody have a suggestion how to simply generate a 20 to 24 bit pwm. cpld/fpga, ok, but quite an effort (for me at least, have nil experience with it).rather thinking of programming a microcontroller pwm output, but those I found have 16 bits max.this is for generating a very precise voltage. so the accuracy of the pwm is important (should basically be defined by the osc. used).(and no, a calibrator is not the solution, I need a part; also, the analogs arround I will take care, so really the issue is the digital part).frequency of some ten to 100 hz would be ok (given max frequency of input)there is a solution shown in edn, using different control signals and analog switches, but has other drawbacks.looking realy for a microcontroller based solution.adrian

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: April 12, 2014, 02:39:16 pm
content: You can increase effective resolution of a MCU PWM using dithering - e.g. change the LSbit every nth PWM cycle.You will struggle to get high res with plain PWM though due to the difficulty of ripple filtering to get a sensible settling time.If you need 20-24 bits you probably should be using a proper DAC, or at least looking at the techiques that proper DACs use, which will certainly not look much like PWM.Some 32 bit MCUs will support 32 bit PWM by the nature of the counters they use to do it - certainly some of the NXP ARMs will.However look at the figures - say you have 20 bits with a PWM clock of 50MHz, this will give you a 47Hz PWM cycle. What sort of filter time constant are you going to need to filter out that ripple down to the LS bit? well under 1Hz I'd expect.

author: dannyf
author_rank: Super Contributor
timestamp: April 12, 2014, 02:40:12 pm
content: QuoteAre you trying to generate 20/24 bit pwm or are you trying to generate very precise voltage? It is perfectly fine to generate very precise voltage using <20 bit pwm.But if you insiste on 24-bit pwm, mcus are practically out of the question for the frequency you need.

author: acbern
author_rank: Frequent Contributor
timestamp: April 12, 2014, 02:51:14 pm
content: thanks guys so far.few comments: the filtering is a resolved issue. I do not want to dig into this given this is a digital blog. also, i do not need fast settling.pwm at this accuracy level is in principle the best soultion, the most accurate calibrators out there use this. the digital part is an issue, am still trying to avoid cplds. really stable dacs at this resolution do not exist. the most accurate i know of is from ad, it has other potential drift issues and is 20 bit 'only'.

author: madires
author_rank: Super Contributor
timestamp: April 12, 2014, 02:54:45 pm
content: Some AVR32 got 20 bit PWM.

author: AndyC_772
author_rank: Super Contributor
timestamp: April 12, 2014, 03:56:31 pm
content: In what way would a digital output from a MCU, toggling up and down somewhere around the mains frequency, actually qualify as 'more stable' than a dedicated DAC device designed for the purpose?What characteristics are you expecting of the digital device's output in each of its two states? When it's a logic '1' it'll be equal to the local supply voltage (whatever that's doing), minus some temperature and load dependent figure, plus some interference from the inside of the chip. Logic '0' doesn't have the same PSU dependency, but it's still not exactly 0V, ever.How are you powering this digital device of yours? If you're relying on your logic '1' output level to be constant, then if the supply voltage is meant to be 3.3V, but it drifts up to 3.300003V, that's one LSB of error at 20 bits. Where is your PSU getting its voltage reference from, and what is the drift in its control loop?Let's suppose you can generate a PWM signal at 100 Hz, which you can do to 20 bit precision with an FPGA running at 100 MHz or thereabouts. Let's also suppose that you have an "ideal" digital buffer on the output which delivers absolutely precise, repeatable logic levels, with no noise or drift whatsoever. What then? You need a filter which drifts by less than one LSB in 10 msec in order to keep the output stable.Full scale at 20 bits is about a million LSBs. If your filter takes >10ms to change its output by 1 LSB, then a full scale change of output will take a million x 10ms, which is nearly 3 hours.

author: sync
author_rank: Frequent Contributor
timestamp: April 12, 2014, 04:04:46 pm
content: I was experimenting with PWM + dithering using an ATmega and a 74HC14 as driver. One of my best results I got with 10 bit PWM + 14 bit dithering (see attachment). At the low and high end there were substantial nonlinearities. I used several calibration points (100uV, 5mv, 1V and 4V) to compensate it at the low end. Also I had spikes like between 3.6 - 3.7V of the graph. At these the precision wasn't good. There was a hysteresis depend to the direction of the voltage change. The settling times were a few 10s.In the end I gave up on this PWM idea.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: April 12, 2014, 04:13:51 pm
content: If you need more bits than a given counter register, you can do sigma-delta on it. S-D isn't just a one-bit thing, the general case applies for any number of bits. Instead of a comparator, you need an ADC. Which will of course limit your accuracy -- you can't expect an ENOB of 20 with an ADC that hardly does 11 bits in DNL or INL.Quote from: AndyC_772 on April 12, 2014, 03:56:31 pmFortunately, a LTI (linear time-invariant) filter does not exhibit slew rate limiting. A single pole cutoff at 100Hz will let through almost all the ripple, but has a 20 bit settling time of around 14ms, for a full scale transition.Of course, a 100Hz single pole lets through about 70% ripple. You'd want to use a lower cutoff many-pole filter. The same general idea applies though.Note also, if your spec is settling within +/- 1 bit inclusive, a transition of <1 bit will settle almost instantaneously.Tim

author: acbern
author_rank: Frequent Contributor
timestamp: April 12, 2014, 04:45:31 pm
content: the atmel at32 was a good hint, thanks madires. works up to 100+ mhz pwm clock, that also gives a reasonable output frequency.of course, one needs very dc-stable and steep filters, but its doable this way as it looks.settling is also solvable, to those who are concerned (at least within the timeline I need, couple seconds).and of course, the voltage being pwm'ed needs to be very stable, the output cannot be more stable than it, for obvious reasons, so one would use a voltage with <1ppm stability to do that given the 20 bit equate about 1ppm. using the digital voltage does not make any sens of course as andyc_772 points out.

author: dannyf
author_rank: Super Contributor
timestamp: April 12, 2014, 04:59:53 pm
content: QuoteFor obvious reasons, a super stable supply voltage isn't always required: it is implementation specific.

author: Jeroen3
author_rank: Super Contributor
timestamp: April 12, 2014, 06:33:32 pm
content: Find an ADC that accurate and create a closed loop pwm voltage regulator using PID.Or am I missing some important detail why 32 bit timers wont work here?*ST parts have 32 and 16 bit timers, NXP parts mostly have 32 bit timers only, also most other modern parts can concatenate timers.

author: acbern
author_rank: Frequent Contributor
timestamp: April 12, 2014, 11:49:30 pm
content: thanks, but thats timers, and not pwm. or do you have somthing specfic in mind capable of doing beyond 20 bits pwm?and an adc introduces other isses (linearity, offset and full scale drift, aging...), getting all this under control is much more expensive than the pwm solution. plus you still need a precise/high res. pwm.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: April 13, 2014, 12:13:15 am
content: Quote from: acbern on April 12, 2014, 11:49:30 pmPWM is sometimes just a particular timer configuration. You can potentially use timer compare hardware to do PWM if not directly supported by timer hardware.

author: dannyf
author_rank: Super Contributor
timestamp: April 13, 2014, 12:15:17 am
content: QuoteThey (and OC) are the same thing.QuoteToo many to list. But if you do the math, to generate 32-bit pwm at even 1Hz means the mcu has to run so fast that you are unlikely to have this type of devices unto 2050, at the earliest.QuoteYou may want to read AN86 from Linear.

author: David Hess
author_rank: Super Contributor
timestamp: April 13, 2014, 07:39:20 am
content: Quote from: Jeroen3 on April 12, 2014, 06:33:32 pmThis is how I have seen it done in the past although two DACs were used as the source. 20 bit linear integrated ADCs are inexpensive and easy to use. I have considered a similar design using charge balancing instead of DACs or PWM.

author: acbern
author_rank: Frequent Contributor
timestamp: April 13, 2014, 08:32:09 am
content: using only 22 bits of a 32 bit counter would be sufficient. 32 bits as you state obviously takes too long. while 20 bits would be ok, 22 would be desirable for my application. the key really is to find a micro-c. that has hardware capabilities in the counter stage to generate an output resuting in a pwm. Just setting a counter and counting down will not do it. the tricky part is the hw logic arround the counter stages. I am not the microcontroller speciialist (thats why I am asking you guys), but have not found a suitable controller yet. The only fit was the AT32 above as recommended by madires.And thanks, I know AN86 (also other interesting stuff included), but I always found this approach way too complicated and costly compared to a PWM solution (dont forget the digital stage which also requires a microcontroller). The goal here really is simple and low cost and precise. two dacs and an adc and a micro-c is much more costly than an at32, a chopper and a filter stage.

author: AndyC_772
author_rank: Super Contributor
timestamp: April 13, 2014, 08:46:29 am
content: Assuming you really do have your digital buffering, power supply and analogue filtering sorted, could you achieve what you want with two separate PWM outputs to give you 'coarse' and 'fine' adjustment?Set up your output buffer / amplifier network such that one output has a gain of, 1:1, and the other is added with a gain of, say, 1/4096. Set the output voltage to be approximately the right value with the first PWM output, then trim it up or down very slightly by adjusting the duty cycle of the other.Major advantage: in a perfect world, two 12 bit PWM outputs with suitably weighted outputs gives you 24 bits' worth of precision. Counter frequency can be dramatically reduced, and your filter design may actually have a chance of working.Disadvantages: all sorts of things to do with component matching, drift and so on.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: April 13, 2014, 09:11:15 am
content: QuotePick two.You get what you pay for.

author: acbern
author_rank: Frequent Contributor
timestamp: April 13, 2014, 09:22:55 am
content: yes, in principle a good idea, but as you point out, the problem is with the matching of the two (at least at 16 bit each). in addition, the stability of the whole thing will only be as good as the msb stability, which is now also analog. as I am moving the mixing into the analog world, all the usual drift and aging issues would show up. overall, even if it worked out (I have not done a error propagation calculation), I think the 20 bit pwm solution is still more simple.what I was thinking about is using 2x 20bit pwm (the at32 has 4), one to achieve 1ppm resolution, the other to do sub-ppm (of coarse even 8 bit would be sufficient for that). if properly done, the drift impact is neglectable there.

author: AndyC_772
author_rank: Super Contributor
timestamp: April 13, 2014, 09:30:13 am
content: Is the matching that big a deal? If both of your digital output buffers are powered from the same supply then they'll drift together, and if they both connect to the same analogue filter then that shouldn't introduce any mismatch either.What you need are two resistors at the input to the filter, which maintain an accurate (and known) resistance ratio. Mount two high quality resistors of the same type next to each other and in good thermal contact, and I don't see why it shouldn't work.

author: acbern
author_rank: Frequent Contributor
timestamp: April 13, 2014, 10:26:17 am
content: so very quick sanity check:for 16 bit, an lsb equates about 150uv at 10v. if I wanted the drift from mixing to be less than 1uv, equal 0.1ppm at 10V (per year and over 20K temp range) that would equate about 0,7% of drift related to the 150uv, or 7000ppm. aging of good resistors is maybe 25ppm each pa, 50 ppm for both. affordable resistors are 5ppm/k, thats another 200ppm combined. so seems to work with 2x 16 bit pwm.one thing to observe is mixing ratio. relation is 1:64k, so e.g. 100 ohms versus 6.4 meg. so leakage (moisture, solder flux residues) must be observed in the design. respectively, one could limit the voltage swing of the ls pwm dac and decrease the 6.4meg resistor value accordingly, this would be the better approach.on a side note, using normal dacs for both will not do it as the zero/full scale drift of the msb is prohibitive.

author: dannyf
author_rank: Super Contributor
timestamp: April 13, 2014, 11:15:35 am
content: QuoteIt would be trivial in a feedback loop; In open loop controls, it can be significant.

author: Smokey
author_rank: Super Contributor
timestamp: April 14, 2014, 02:46:53 am
content: Check out TI DSPs. This is just one app note. A lot of the TMS chips have the high resolution PWM.http://www.ti.com/lit/ug/spruge8e/spruge8e.pdf

author: Andreas
author_rank: Super Contributor
timestamp: April 15, 2014, 07:04:01 pm
content: Quote from: acbern on April 12, 2014, 02:25:02 pmYou can either try a PIC24FV32KA302 (two 16 Bit timers can be concatenated to build a up to 32 bit counter or PWM)or simply use 2 16 Bit PWMs mixed together via resistors.Essential is that you use switches with high symmetry and low charge injection. (a HC-MOS gate is far away from that).Up to now I have best results with MAX4053A devices.A good starting point would be this cirquithttp://edn.com/design/other/4326640/DC-accurate-32-bit-DAC-achieves-32-bit-resolutionI got 16 bits linearity from start and could trim this to around 2-3 ppm by adjusting R7.The advantage of this cirquit is very fast settling time (with proper adjustment).The disadvantage is noise (compared to a DAC solution) from switching.With best regardsAndreas

author: Andreas
author_rank: Super Contributor
timestamp: April 15, 2014, 07:26:30 pm
content: Quote from: acbern on April 13, 2014, 09:22:55 amThis will only be so long until you really tried it.A difference in rise/fall time of 10 ns at 100 Hz will be already 1 ppm non linearity.A charge injection of 10 uC will charge up your 1uF filter capacitor by 10 uV.Different output resistance in high and low state will do their job.Not to speak from digital effects like "ground bouncing".And all effects are temperature dependant.Don't think that a digital design is more easy when its going to ppm level.With best regardsAndreas

author: Q-Kernel
author_rank: Contributor
timestamp: April 15, 2014, 09:10:38 pm
content: The dsPIC33FJ32GS610 series have very powerful PWM's with a 1 nSec frequency resolution. See features below:• Two Master Time Base modules• Up to Nine PWM Generators with up to 18 Outputs• Two PWM Outputs per PWM Generator• Individual Time Base and Duty Cycle for each PWM Output• Duty Cycle, Dead Time, Phase Shift and Frequency Resolution of 1.04 ns• Independent Fault and Current-Limit Inputs for Eight PWM Outputs• Redundant Output• True Independent Output• Center-Aligned PWM mode• Output Override Control• Chop mode (also known as Gated mode)• Special Event Trigger• Prescaler for Input Clock• Dual Trigger from PWM to Analog-to-Digital Converter (ADC) per PWM Period• PWMxL and PWMxH Output Pin Swapping• Independent PWM Frequency, Duty Cycle and Phase Shift Changes• Current Compensation• Enhanced Leading-Edge Blanking (LEB) Functionality• PWM Capture FunctionalityThey are mostly used for DC/DC and AC/DC Inverters, PFC and lighting. Very cheap too

author: westfw
author_rank: Super Contributor
timestamp: April 16, 2014, 04:47:56 am
content: QuoteTime to look at some of the new 32bit processor chips. The TI Tiva (ARM CM4) chip used on the $12 "Tiva Launchpad" board has 32 and 64 bit general purpose timers (with OC-based PWM capability), even though its fancy "PWM controller" seems to be based on a 16bit counter.

author: Andreas
author_rank: Super Contributor
timestamp: April 16, 2014, 06:36:11 am
content: Hello,when reading 1ns resolution or 32 Bit processor I think always "PLL".The question is: do you really want to use a PLL with jitter and phase noise nearly in the percent range for a precision PWM?For a SMPS this may be a nice feature since you get a spread spectrum of your EMI noise.But for a calibrator where you have carefully select your PWM output frequency according to the NPLC setting of your DVM to get maximum normal mode suppression?With best regardsAndreas

author: acbern
author_rank: Frequent Contributor
timestamp: April 19, 2014, 09:12:28 pm
content: sure, 10ns are 1ppm, but at 16bit for the first stage and 100hz output the counter input frequency is in the range of 6mhz, or 160ns, so getting jitter to well below 10ns should not be a problem. and analog switches I would not use, would just use a slow filter, no need for fast settling.similar to how datron does it in their 4808. and the btw used 13 and 13 bit pwms.that being said, it is cerainly not simple, agreed.

author: Andreas
author_rank: Super Contributor
timestamp: April 20, 2014, 07:12:10 am
content: Hello,no analog switch to scale down a precise reference voltage with your PWM?The interesting question is: why do they use 13 + 13 bits PWM at Datron.(They also could use 16 + 10 Bits)With best regardsAndreas

author: acbern
author_rank: Frequent Contributor
timestamp: April 20, 2014, 07:46:07 am
content: actually i wanted to use the tc1426 as the switch due to its low on-resistance. this would then directly go into the filter. the max 4052 has a very low charge injection, 10pc only. maybe the max4052 would be a good candidate too, not sure it is the better choice, what do you think?as far as datron is concerned, one of their complications certainly was that they had to generate the digital pwm stage by conventional 74-logic. quite an effort back then, but I can only guess. i would tend to keep the lsb impact low (hence 16 bits of msb) in order to be able to forget the influence of resistor mixer drift (temp and long term). 13 bits means about 1,25 mv for the lsb.linearity is not so important for me btw, I just want to set a voltage, what the exact digital value is of secondary importance. impornant for me is long term and temperature drift.

author: Rerouter
author_rank: Super Contributor
timestamp: April 20, 2014, 08:55:45 am
content: so what your actually after is a high resolution low drift system (precision implies you want each step to be as close to actual as possible)

author: acbern
author_rank: Frequent Contributor
timestamp: April 20, 2014, 12:22:43 pm
content: if thats your interpretation of precision then thats right. i would not necessarily concurr, because repeatability and resolution should be below 1ppm. if the inl is 5ppm I do not care. if the dnl is 2 ppm I do, because then there are missing voltage steps.

author: Andreas
author_rank: Super Contributor
timestamp: April 20, 2014, 01:04:28 pm
content: Hello,I do not think that a high current mosfet driver is a good choice for precision PWM.But I did not try this.5 ppm INL is also not easy to achieve. On the first try I got 65uV / 5V = 13 ppm INL with the MAX4053A.With some trimming the INL could be enhanced to 3-4 ppm.DNL should not be a issue with PWM.Long term + temperature drift will depend mainly on the reference voltage which is used.With best regardsAndreas

author: tszaboo
author_rank: Super Contributor
timestamp: April 20, 2014, 06:52:30 pm
content: Quote from: mikeselectricstuff on April 12, 2014, 02:39:16 pmSorry Mike, but that is not true. If you dither something, you will get a small ripple on the output, just as you said it. If you make a filter to filter out that ripple, mathematically, you end up with a system which is equivalent with a higher resolution, slower pwm. So there is no real advantage, only if you are hardware (register size) limited somehow.The only real way to increase a pwm resolution is throw more hardware at it. This means plls, multiple clock-shifted registers AND gated, and so on. There is no easy way.