Boost converter MOSFET switch code ??

Hello,

I'm trying to build a boost converter using MOSFET as a switch. The circuit is built correctly I believe, but I'm new to Arduino coding. Can someone help me with the code to make the Arduino produce 40Khz frequency and 61% Duty Cycle. The circuit should boost 5V to 12V. What code should I use?

Please see attached.

Thanks for the help in advance!! :slight_smile:

Sorry. Here's the attached!

Below is an example of setting timer 1 on an ATmega328p (eg Arduino Uno) to deliver a PWM on pin OC1A (pin 9 ). Alter the value of ICR1 and OCR1A to deliver the desired frequency and duty cycle.

// OC1A = 9
 // OC1B = 10

 //set timer1 toggle at xHz
 TCCR1A = 0;// set entire TCCR1A register to 0
 TCCR1B = 0;// same for TCCR1B
 TCNT1  = 0;//initialize counter value to 0

 ICR1 = 400 ;   // set frequency.  400 = approx 40 KHz with 16 MHz clock ( See data sheet for formula)
 OCR1A = 240 ;  // set duty cycle as proportion of ICR1.  240/400 = approx 60% 

 TCCR1A |= ( 1 << COM1A1 ) | (1 << WGM11) ;

 // wg mode 14
 TCCR1B |= (1 << WGM12) | (1 << WGM13);
 // prescaler  1
 TCCR1B |= (1 << CS10) ;