Creating a pwm signal with various duty cycles

Hello everyone ;
im new in programing , in my project i want to generate a pwm signal using a fixed frequency and various duty cycles stored in an array ; the code below works perfectly for what i need but i want it to be more precise using timer interrupt and get rid of the function delay() what is the easiest way to do that ? im using arduino mega (atmega2560)
const int pinV1 = 6;
contst int V1 = {168,168,168,167,171,174,178,189 ,102};
void setup ()
{

Serial.begin (9600);
pinMode(pinV1, OUTPUT);
}
void loop ()
{
int arrLen = sizeof(V1) / sizeof(LEAD1[0]);
for (int t=0; t<arrLen; t++){
analogWrite(pinV1, V1[t]);
delay(2);
}
}

The above is not a reasonable question :roll_eyes:


See:

Thanks for your answer , i will read this Arduino reference

Each time you change the duty cycle, you glitch and momentary change the frequency.

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