Precise analog voltage from PWM

Gxit3bd

Destate9  writes:

So I’ve been trying to make a constant current H-bridge circuit for a project, and I’m running into trouble with PWM. Right now, all I have connected to the Output compare pin of my PIC32MX microcontroller is a 330uF capacitor (Max ESR of 1.4 ohms according to datasheet). I assumed a 50% duty cycle (at VCC = 3.3V) would yield 1.65V, but that is not the case. As you can see in my attached picture, the output voltage (y-axis) vs Duty Cycle (divide the x-axis by 65535) looks a little more like a CDF. I know there must be a way to calculate this function based on the capacitor charging and discharging, but I’ve been scratching my head for a while, and was wondering if anyone else has derived this function.

Via the forum.

Join the Conversation

3 Comments

  1. The output pin is connected directly to a 330 uf cap, so external buffer? That seems like a heavy load for a typical GPIO pin, is there some current-limiting going on?

  2. With the cap connected directly to a GPIO, you are assuming that the pin impedance is exactly the same in source and sink, but this is not true in general—NMOS and PMOS are not perfectly symmetric. In the more common configuration, a series resistor dominates the pin impedance and you can analyze the circuit as a perfect voltage source driving a low-pass filter.

    If you left out the resistor intentionally because you plan on driving a load, this won’t work. Your PWM DAC needs to see a reasonably high impedance, so you might need to buffer it with an op-amp.

Leave a comment

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.