6 years, 8 months ago.

A little problem with PWM pins

Hi guys, this is my problem. I have a circuit and the power supply must be from my nucleo F401RE. I know it doesn't have any DAC so i can't use AnalogOut in my code: do i have to use PWM necessarily? How can i use that to supply an exact voltage value? Can you make an example?

Thank you for your time.

1 Answer

6 years, 7 months ago.

"Power Supply" implies you want to provide a non-trivial amount of power. A DAC is usually signal level and you would expect to draw no more than 1 or 2 mA from the micro pin (I haven't checked the pin specs). How much current does this DAC output need to source?

You can generate pretty good DAC output by using a low pass filter on a PWM signal. Run the PWM signal quite fast, say 100kHz range. Run the PWM into an LPF filter to smooth it out and then buffer this with an opamp. Opamp can be used to provide gain as well to step up the voltage if you need to. An opamp can generally source more current than the micro pin as well - how much current, depends on the opamp.

Top answer here shows it pretty well. It uses 2 stage LPF on input, but a single R and C would work just fine. The circuit you are looking for is a "non-inverting opamp", you can find equations for setting the gain.

https://electronics.stackexchange.com/questions/100918/convert-a-pwm-to-analogue-with-double-the-voltage-range

You might be able to get 50 to 100mA out of an opamp (I don't actually know what the limit is). If you need more current you will need a DC-DC power supply. This could be controlled from the nucleo board to adjust the output voltage.