I am creating a simple boost converter that step up voltage in the range 5V-30V. The switch is a MOSFET controlled by PWM output of an Arduino (with additional necessary components.) I want to implement a feedback mechanism to control or regulate the output voltage. I need to understand how a voltage divider read the output voltage as an analog input to Arduino and how to write the correct Arduino code for this feedback controlling.
Boost converters use inductive charge pumps for high efficiency. A current is allowed to cumulate to an inductor from the low voltage source with a switch. The switch is kept ON a short time (typically for 10 to 20us) to prevent the current to grow too high. Induction law states that the current grows at rate voltage/inductance. That's amperes per second if voltage is in volts and inductance is in henries.
The switch is turned OFF abruptly. The current through the inductor fights its way with as high voltage as needed. That's the inductive or "flyback" pulse. In boost converters there's a diode which allows the current charge the output capacitor. Its voltage increases a little, typically only few millivolts, maximally less than 100 mV.
The switch controller observes the output voltage and starts a new switch ON-switch OFF cycle as soon as the output voltage has dropped under a specified regulation limit. It drops due the output load current as the math law of the capacitor states. The output voltage dropping rate (V/s) depends on load current and the capacitance. For that reason the output voltage swings up and down intentionally, but the swing is kept acceptable (well below 100 millivolts) with proper math design.
That design before all programming is your first job. Then you can check how quickly you must be able to run the controlling software loop. By having big enough inductor and output capacitor you can make the switch ON-switch OFF cycle as long as needed for acceptable software timing accuracy.
Switchmode converter design has been the subject of numerous cases in this site. Here's one: Flyback Converter Capacitor Value selection with given ripple voltage limit
Controller IC manufacturers have published detailed application notes with valid math for their ICs. Of course they must properly cover also the trademark independent design principles.
NOT ASKED: I recommend you to use a controller IC. Let the computer output the wanted voltage or adjust parts in the controller cicuit for that purpose. I guess you must make the software controlled ON-OFF cycle very long to get accurate enough output voltage. Big inductor costs money and its mechanical vibration can create very annoying whistle if the switching frequency is in the audio band.
Disclaimer: I'm not a competent programmer