DC-DC Buck converter duty cycle Arduino code

We are designing a DC-DC buck converter that is working to provide a stepped-down voltage with a high output frequency. I need a really simple Arduino code that will generate 10Khz or more when I connect it to the oscilloscope + correct square sine wave output. By manually manipulating the duty cycles PWM by changing the values on the Arduino code itself. For example, the input voltage is 30v and it has a 100% duty cycle. I want Arduino code with a fixed generated 10Khz or more frequency that will allow me to make the PWM signal (duty cycle) 50%, 66%, and 33% every single time by just changing some of the code values.
Hope I didn't misunderstand our target and THANK YOU in advance.

You're asking someone to write the code for you. Have you tried to do it yourself and now you're stuck, or are you offering to pay someone to do the work?

Look into using the timer1 library.

Make changes as needed.


//This sketch generates pulses within the frequency range of 1 MHz to 1 Hz using Timer1 PWM on pin 9:

#include <TimerOne.h>

#define pwmRegister OCR1A const int outPin = 9;

long period = 10000; long pulseWidth = 1000;

// the logical pin, can be set to OCR1B // the physical pin

// the period in microseconds // width of a pulse in microseconds

int prescale[] = {0,1,8,64,256,1024}; // the range of prescale values

void setup() { Serial.begin(9600); pinMode(outPin, OUTPUT); Timer1.initialize(period); setPulseWidth(pulseWidth); }

void loop() { }

// initialize timer1, 1000 microseconds

bool setPulseWidth(long microseconds) { bool ret = false;

int prescaleValue = prescale[Timer1.clockSelectBits];

// calculate time per counter tick in nanoseconds long precision = (F_CPU / 128000) * prescaleValue ; period = precision * ICR1 / 1000; // period in microseconds if( microseconds < period) {

int duty = map(microseconds, 0,period, 0,1024); if( duty < 1)

duty = 1;

if(microseconds > 0 && duty < RESOLUTION) {

Timer1.pwm(outPin, duty);

ret = true; }

} return ret;

}

Post an annotated schematic, not a frizzy picture of what your circuit is as of now. Be sure to post links to each of the hardware devices unless they have a generic number such as 2N4400.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.