Buck converter using Attiny84 (PWM frequency change)

I found PWM library :-) i can change pwm freq. without interrupting time related functions :)

With this library pwm freq. could be up to 2 MHz, so i can easily achieve 100 or more kHz :)

So I was playing with PWM library today and i wrote a simple program for controlling duty cycle of my converter, nothing fancy or complicated, just a simple PWM generator.

I used pin 9 which is on 16 bit timer1 of 328P, and i used pwmWriteHR function so i can use higher resolution because im going to switch output at 75 kHz instead of 32 kHz

Here is the code:

#include<PWM.h>

const int output = 9;
const int pot = A0;
const int okled = 13;

int duty = 0;
int32_t frequency = 75000;

void setup(){
  InitTimersSafe();
  bool uspjeh = SetPinFrequencySafe(output, frequency);
  if(uspjeh){
    pinMode(okled, OUTPUT);
    pinMode(output, OUTPUT);
    digitalWrite(okled, HIGH);
  }
}

void loop(){
  duty = analogRead(pot);
  duty = duty / 4;
  pwmWriteHR(output, duty);
  delay(5);
}