Boost Converter Problems
&quot;I want to learn my mistakes and correct them.&quot;
Ok, start with the code. I've not used an AtTiny, but there are some things that stand out and should be considered.

What starts the loop? Does it just free run? Usually it's best to start the loop from a PWM timer interrupt. That way the ADC is read, and PWM value is updated once per PWM cycle. If the loop free runs, it won't be synchronous with the PWM, and it may not even be consistent if other processes are going on.

What is the PWM frequency? Is it 8MHz/256, or ~32KHz? Let's just say it is 32KHz. What is the conversion time of the ADC? can it support 32KHz?

What happens to the PWM control output if variable val is less than 0 or greater than 255? Integrator accumulators have to be bounded.

What happens if AnalogRead() is equal to 512? Is that implicitly handled by the IF statement as a noop? If so, do you really want a dead spot in the integrator?

The integrator can change the PWM control at every sample point, which means it will have way too much gain. Integrators in loops like this need a scale factor which will effectively be less than 1, or a division. That also means that each integrator contribution per sample will end up being some fraction. How do you handle sums of quantities that are each less than 1?

Does the AtTiny have a hardware multiplier? If not, are you going to do multiply/divide by left shift/right shift or software algorithm?


Boost converters can be very hard to control. With a 470uH inductor, operation will be continuous conduction mode (CCM). In CCM there are 2 complex poles and a right half plane zero. Either of these will make the control unstable if not properly compensated. Since you don't seem to be familiar with control theory, perhaps you shouldn't even use an integrator, maybe hysteretic or bump control would be better. These types of control don't control as tightly as a PI, but they are simple and an AtTiny could probably support them. First, set the PWM to a fixed duty cycle like 50% (you'll need to experiment to get a workable duty cycle). Then each cycle check if Vo is greater than a set value. If Vo is greater than the set point then don't put out a pulse the next cycle. If Vo is less than or equal to the set point then do put out a pulse the next cycle. Also, for a bump control a smaller value for L1 will be needed to operate in discontinuous conduction mode (DCM). Bump control will not work with CCM since filter Q will be to high, and the output would ring.
Boost
Since a boost has a direct path from the battery through L1 and D1 to the output, even if Q1 never switches, the output won't be less than ~1.8V (that's Vin - 0.6v). It's hard to imagine what could cause an output of 1.2V with no load. But, pretty much every part you are using has a problem.

What is the resistance of L1, also saturation current and self resonant frequency? With L1 of 470uH and C2 of 1mF, unless L1 resistance is at least 0.5 Ohms, output filter Q will be over 5, very ringy. Also at 0.5 Ohms, L1 will dissipate ~125mW with Io of .25A. For DCM operation a smaller inductor will be needed anyway. The CCM/DCM boundary can be used to find an upper limit for L1 in DCM operation.
L1 &lt; \$\frac{V_o}{16 i_{\text{crit}} f_s}\$ or \$\frac{\text{5V}}{\text{(0.25A)} \text{(16)} \text{(30kHz)}}\$ = 38uH

Q1 is only being driven with ~2mA, but only has \$\beta\$ of ~20. It will never switch the current needed with that kind of drive. It would be best to change to a logic level FET.

D1 needs to be a switching diode and a schottky would be best. Something like a 1N5818 would work.

A 5.6V zener should be added across \$V_o\$ to keep the output from over voltage.


If you are going to design a Boost, you should read &quot;Understanding Boost Power Stages&quot;.