Using external reference voltage with a PWM DAC - Page 1
Forum section: electronics / beginners

author: mduchalski
author_rank: Newbie
timestamp: September 12, 2018, 09:14:34 pm
content: Hello,I'm trying to use filtered PWM signal as a analog output in my power supply project. I want to use an external 4.096V reference voltage (MCP1501), so I've been using a simple single transistor-based inverter with a RC filter on the output. This approach, however, does not seem to produce good results. I played around with it using Atmega328p Timer1 PWM modes - Fast PWM at 15.6kHz and Phase-Corrected PWM at 7.8kHz, 10-bit resolution. In both cases I'm getting maximum recorded error of 15-20 LSB. I've included more detailed measurements below. Unfortunately I don't have a scope to take a look at the signals, and simulation wasn't all that helpful, showing performance far inferior to what I actually got (order of magnitude bigger errors). I initially thought that C-E voltage drop when transistor is driven into saturation will put the average a little higher, but simulation suggests that the "high" collector voltages may be significantly off - ~200mV lower than the expected 4.096V (@50% duty cycle 7.8kHz). My questions are - what is most likely to be the primary source of these errors and is it possible to achieve better performance of a PWM DAC with an external voltage reference, if so how?

author: JS
author_rank: Frequent Contributor
timestamp: September 12, 2018, 09:23:18 pm
content: Use a CMOS buffer, any CMOS aimple logic will help. Inverter, buffer, schmid trigger... Try our and see which is better, I recon all of them will be much better than your approach.Power them from the voltage reference, and they will stat low right at ground ans high right at the reference. Test that, just to be sure, how much error you are having from your circuit? Meaning 0 output and FS output errors. In your circuit it will widely change with load, in the CMOS not so much but still, the higher impedance the load has the better.JS

author: mduchalski
author_rank: Newbie
timestamp: September 12, 2018, 09:42:57 pm
content: Thanks for the quick reply and suggestions. I have some 4000-series logic laying around, so I will definitely test that. The main reason I tried to do it with a discrete transistor was to avoid the need for another IC on the board. I was hoping that there is some trick you can use here I'm not aware of/obvious mistake I'm making. But if such an elementary circuit is not able to deliver decent performance and I will need to put an additional IC on there anyway, I might as well make it some cheap dedicated DAC. Thanks again.

author: JS
author_rank: Frequent Contributor
timestamp: September 12, 2018, 10:04:25 pm
content: You could do it with discrete fets, but a bjt is not the device for the job. And you need push pull config or it will still have high error.The obvious error is BJT has a saturation voltage of quite a few mV instead of a low Rds on, so with low Rds on you will get quite close to the rails while you won't be able to get close to the rails with a BJT. Then, when the BJT is off you hace a high resistance, so the load will have a huge impact on the high voltage you get. Not getting right to the rails is the problem here, with a CMOS buffet you will get much closer to the rails. The other problem is the slew rate of rising and falling edges being different, making the switching time less precise. If you have the same ahape going up and down and your edges are much faster than the PWM signal you will have much greater accuaracy.JS

author: David Hess
author_rank: Super Contributor
timestamp: September 13, 2018, 12:04:30 pm
content: Quote from: mduchalski on September 12, 2018, 09:42:57 pmThere is a not so obvious trick; reverse the collector and emitter connections to run the bipolar transistor backwards for lower saturation voltage. The base drive needs to be increased to make up for the lower gain. Also use a low valued speed up capacitor in parallel with the base series resistor to improve switching times and especially reduce storage time.But the real way now is to use a CMOS inverter or buffer powered by the reference voltage or even better, an analog switch. In the past switching might have been done with currents and diodes.

author: Buriedcode
author_rank: Super Contributor
timestamp: September 13, 2018, 03:40:04 pm
content: PWM DACS have great linearity - because clocks are generally very consistent, but tend not to have the best absolute accuracy due to the problem you've encountered - precise high/low levels.As suggested, using buffers powered by your reference and a high impedance filter will help, but I would still add calibration to account for any remaining offset if you're after absolute accuracy. Offset is much easier to calibrate (simply adding or subtracting values, or use a trimmer if in hardware) than linearity.

author: mduchalski
author_rank: Newbie
timestamp: September 13, 2018, 06:23:56 pm
content: Thanks for your responses. I tried the suggested BJT trick (and also increased filter input impedance) , and while performance is better and I'll definitely keep this approach in mind for the future, it's still not quite what I would like. I'll try experimenting with different component values but since it seems that as you suggested using a CMOS buffer is the best option here, I think I'm going to go for a dedicated DAC IC in this case to avoid the need for calibration and get better performance in general.Thank you all for your help.

author: JS
author_rank: Frequent Contributor
timestamp: September 13, 2018, 07:46:00 pm
content: The thing with jelly beam CMOS is that they are cheaper and more available than the ADC you will look for... And in the end linearity for PWM is very good as already stated. Also, with one part you could buffer several channels.JS

author: Buriedcode
author_rank: Super Contributor
timestamp: September 13, 2018, 10:29:29 pm
content: It's all a question of application. PWM DACs are great for some things, and not for others. For apps where you have explicit feedback and you don't know how much of an adjustment you'll need, then PWM can be very good. If you're trimming a voltage - that doesn't vary that much, but must be stable, then a DAC with absolute accuracy is better. A dedicated DAC chip will *generally* be better, if your application is say, trimming voltages, and will requires less filtering.PWM DACs can be excellent for audio (again, because its so linear, and absolute accuracy isn't needed) just look at class D amps!

author: mduchalski
author_rank: Newbie
timestamp: September 13, 2018, 10:57:40 pm
content: My application is digital control of a power supply - setting voltage and current, so it is exactly "trimming the voltage". That's why I was leaning towards a dedicated chip in my last reply. But in the meantime I found some CMOS logic chips and tested them. I must say I'm very satisfied with the performance - I tested CD4011BE and 74HC00 NAND gates used as inverters. The latter one worked much better with errors within a few milivolts over the entire range, max. recorded -6mV/1.5LSB (approximately, my multimeter is only +/-1% accurate in that range), as opposed to max. -16mV/-4LSB with the 4000-series one. This makes me think I'm going to stick with PWM after all. Thanks!