How does this code work for this boost converter?

Hey,
I jumped back and forth a few times between the electronic part of the forum and the programming part of the forum… finally decided to post it here.

This is an instructable by greatScott! on making attiny based boost converter. I want to modify this to integrate in my project where it produces constant 12V from a lithium-battery pack. but i dont quite understand the code, and he doesnt explain it at all. Can someone help me understand the step by step process of the code so i can modify it to my needs?
one more thing, It would be best if i can use this code in an attiny13A while the code is intended for an attiny85/45. ( i already have a tone function running on my attiny13A, if that somehow affects if i can run it on my attiny13 or not )
this is the code:

#define F_CPU 8000000
int pwm = 1;
int potinput = A2;
int feedbackinput = A3;
int potinputval;
int feedbackinputval;
int pwmval;

void setup() {
  TCCR0A = 2 << COM0A0 | 2 << COM0B0 | 3 << WGM00;
  TCCR0B = 0 << WGM02 | 1 << CS00;
  TCCR1 = 0 << PWM1A | 0 << COM1A0 | 1 << CS10;
  GTCCR = 1 << PWM1B | 2 << COM1B0;
  pinMode(pwm, OUTPUT);
  pinMode(potinput, INPUT);
  pinMode(feedbackinput, INPUT);
  digitalWrite(pwm, LOW);
  pwmval = 0;
}

void loop() {
  potinputval = analogRead(potinput);
  potinputval = map(potinputval, 1023, 0, 255, 0);
  feedbackinputval = analogRead(feedbackinput);
  feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
  while (potinputval > feedbackinputval) {
    if (pwmval == 230) {
      potinputval = analogRead(potinput);
      potinputval = map(potinputval, 1023, 0, 255, 0);
      feedbackinputval = analogRead(feedbackinput);
      feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
    }
    else {
      pwmval = pwmval + 1;
      analogWrite(pwm, pwmval);
      potinputval = analogRead(potinput);
      potinputval = map(potinputval, 1023, 0, 255, 0);
      feedbackinputval = analogRead(feedbackinput);
      feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
    }
  }
  while (potinputval < feedbackinputval) {
    if (pwmval == 0) {
      potinputval = analogRead(potinput);
      potinputval = map(potinputval, 1023, 0, 255, 0);
      feedbackinputval = analogRead(feedbackinput);
      feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
    }
    else {
      pwmval = pwmval - 1;
      analogWrite(pwm, pwmval);
      potinputval = analogRead(potinput);
      potinputval = map(potinputval, 1023, 0, 255, 0);
      feedbackinputval = analogRead(feedbackinput);
      feedbackinputval = map(feedbackinputval, 1023, 0, 255, 0);
    }
  }
}

and the circuit

Thanks,
TamjidK

One more thing, as i stated, i dont need a variable output, so i will most likely ditch the pot and set voltage in code.

I wouldn't bother, but would just use one of these from Pololu.com
Pololu 12V Step-Up Voltage Regulator U3V12F12

This goes out with free shipping

Maybe you can talk 'em into add the regulator with it.

I actually spent quite a lot into this project, and would love not to buy more stuff.. And currency conversion added with the cost of shipping a few thousand miles ( about a 100 bucks) for this is... well not good in my case.

I already have few free pins in the attiny13, and i basically need 2 pins, 1 to drive the mosfet and the other to sense voltage, so no fancy features needed.

That code looks like it was written by someone who has never heard of functions.

TheMemberFormerlyKnownAsAWOL:
That code looks like it was written by someone who has never heard of functions.

"he" has a pretty famous youtube channel..

but you people are the experts..

kaseftamjid:
“he” has a pretty famous youtube channel…

Thoughts and prayers

I heard that Donald Trump had a pretty popular TV show, something to do with the phrase "you're fired".

Your schematic in the OP is cut short on the right, so you have lost the sense circuit.
You will have difficulty running the tone() function (or anything else simultaneously) on the same MCU as that code because it appears to use both timers of the ATTiny85, and has blocking loops.

In principle, the code works by regulating the duty cycle of the signal that switches the mosfet gate, depending on the required voltage and the measured output voltage at the sense circuit. Since the author hasn't explained the timer configuration he has used, you have to look up the mnemonics in the data sheet.

If you look at the comments on the instructable, it appears others have tried to put this on an attiny13 and it does not fit.