Analog voltage control via Microcontroller
If your microcontroller does not have a DAC, you can generate high-frequency pwm, run it through a low pass filter and it is effectively an analog voltage. 

Unfortunately if you're trying to get up to a higher rail voltage than your microcontroller pin output, then you could either first pwm a transistor in front of the filter with a pull down from a higher voltage rail, or use an op-amp after your filter.

A pull up to drive a filter on 24V will eat a lot of power, you might be better off using an op-amp amplifier out of a DAC or 0-5V PWM run through a low pass filter... Below is a schematic to give an idea, although you will notice if you simulate it is more like 0-22V due to the 4.7k pullup resistor not driving the filter well.







simulate this circuit &ndash; Schematic created using CircuitLab