NEW to Arduino: need to output a voltage ramp function over a specified time

I am looking for some guidance on how I can output a ramp function of voltage over a specified period of time. I understand I could likely do this using a loop and altering the PWM each iteration, but I was not sure if there was a better option. Any help would be appreciated!

-Andy

Probably better use a DAC for that. PWM doesn’t produce a voltage, it produces a block wave.

I understand I could likely do this using a loop and altering the PWM each iteration, but I was not sure if there was a better option.

Basically you have to change the analog write value over time, so a for loop is one way. Depending on what else you want the Arduino to do at the same time it might not be the best or most efficient. Look at the blink without delay example in the IDE or see my
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html
Or Robin2's several things at once

Your PWM signal needs filtering externally to convert it into a steady DC voltage. See PWM

Do you need constant time of the ramp or variable? If the time is constant you can use current source and capacitor to get it easily.

PWM output into a lowpass RC filter will do.
For example, here's analogWrite (pinX, stepSize);
into a low pass filter made of 4.7uF cap and 10K resistor,
with stepSize changing from 0,25,50,75,100,125,150,175,200,225, 250, 0.

[


@ashagen, do not cross-post. Threads merged.

I forgot to mention that I planned on changing the PWM through each iteration using a low pass filter. Is this the best way to go about it or is there an easier way? Could I increment analogWrite() with each iteration, while keeping the voltage increase relatively constant/smooth?

Yes, Make the changes as big/small as you want and as often as you want,