Getting round values from PWM - Page 1
Forum section: electronics / general

author: fenclu
author_rank: Regular Contributor
timestamp: January 24, 2016, 09:01:23 pm
content: HiI'm working with a STM32 micro which has a 16 bit timer. Since it has a narrow range of supply voltage I need to use a 3V voltage reference. I want to obtain nice round values in 1mV steps with a range of 2V. I have two ideas on how to solv this issue1.Since all I really need is a 12 bit PWM I can use the full 16 bits and make the micro count every 22 bits. That would equal to about 1,007mV on the output.2. I could use the PWM as a 12 bit and use a 0.1% voltage divider on the output to divide the max 3V to 2.048 volts. That would give me a nice 500uV/bit or 1mV/2bits.Now, which of these methods is actually a better design practice? Sorry if I made some dumb assumptions, I'm so tired that I'm dizzy

author: dannyf
author_rank: Super Contributor
timestamp: January 24, 2016, 09:40:42 pm
content: QuoteThat means a total of at least 2000 steps. So you need at a minimum a 11 bit pwm.With a 12-bit pwm, you can utilize dithering. Or an output divider to scale it back to 2v tops.

author: Kalvin
author_rank: Super Contributor
timestamp: January 25, 2016, 09:12:17 am
content: Use higher voltage, like 3.2768V and you have now nice round step size for the PWM. Or, use a single logic gate device as a buffer/voltage level translator driven by the PWM and power it from 2.048V, and you will now have nice round step size again.

author: fenclu
author_rank: Regular Contributor
timestamp: January 25, 2016, 09:51:22 am
content: Quote from: Kalvin on January 25, 2016, 09:12:17 amI think that requires a adjustable voltage reference. And aren't they a bit crap? I mean, they rely on being set by two resistors and I think that would introduce additional "nonprecision". Am I thinking correctly?BTW I really don't want to go to trimmer pots etc.

author: bktemp
author_rank: Super Contributor
timestamp: January 25, 2016, 10:00:05 am
content: Can't you set the PWM to 3000 steps? Then each step produces 1mV. If you only use steps 0-2000 you get 0-2V in 1mV steps.

author: fenclu
author_rank: Regular Contributor
timestamp: January 25, 2016, 11:01:43 am
content: But isn't the PWM always referencing to 3V supply? How to set it to exactly 3000 steps?

author: Kalvin
author_rank: Super Contributor
timestamp: January 25, 2016, 11:45:14 am
content: Quote from: fenclu on January 25, 2016, 11:01:43 amActually when you think about what you just said, it should be able to make the PWM-timer to run from 0 to 3000 or 0 to 30000 instead of 0 to 65535. That will solve the issue.

author: dannyf
author_rank: Super Contributor
timestamp: January 25, 2016, 12:07:05 pm
content: Not quite, as 100 percent duty cycle means vcc so picking a shorter period does not help.One way may be to limit the output to 2000mv and a 2000 pwm period.Or go with dac.

author: bktemp
author_rank: Super Contributor
timestamp: January 25, 2016, 12:15:11 pm
content: Quote from: dannyf on January 25, 2016, 12:07:05 pmIf the PWM period is set to 3000 counts, but only the range 0-2000 is being used, the maximum output voltage = 3V * 2000/3000 = 2V.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: January 25, 2016, 03:10:59 pm
content: Why does it matter? You should avoid using gimmicky constants like "1mV/count". Counts are dimensionless: the only time a calibration needs to be applied is when that count is translated to a real value, i.e., an analog gain stage at the physical output, or converting counts to units for reporting to the user.Tim

author: Kalvin
author_rank: Super Contributor
timestamp: January 25, 2016, 03:51:00 pm
content: I am not sure about this (not tested), but here is one idea: If you have two PWM-outputs available, you should be able to find suitable resistors so that the combined PWM-outputs will provide 0V - 2V output and the other PWM-channel has convenient step values. The other PWM-channel can be used for amplitude calibration. Like I said, I haven't tested this.Edit: See this EDN article for the basic idea, but you need to calculate the resistor values so that you get correct output value with convenient PWM-register value and the other PWM-channel can be used for amplitude calibration:http://www.edn.com/design/analog/4441113/A-faster-PWM-based-DAC