Phase correct pwm ( various duty cycles)

hello everyone , I'm new to the timer interrupt thing , I have a very simple question , is it possible to change the duty cycle of the pwm signal during the execution program, in other words I want to plot various duty cycle in the same program , is it possible and if it is how to do that ( change it in the void loop ? ) I'm using Arduino mega by the way.

Sure it is. There could be no 'analogWrite()' without it.

Read: https://www.gammon.com.au/timers

The whole "how to do that" is there.

All timer functions, and especially PWM waveform generation, are revealed and fully discussed in the processor data sheet. Take some time to go over the material.

this is for arduino uno im using mega is it the same things or i need to adapt

umm i tried to do that but i got lost very quickly

There is no shortcut to engineering knowledge. Take the time to learn it, or use the user friendly functions that Arduino IDE provides, like 'analogWrite()'.

The data sheets answer that question, they are similar so the differences exist, but are minor.

i already did that , but i need to plot 9 signal pwm and the program gets very slow with all the delay() function thats why i want to use timer interrupt is the phase correct the best way or there is a simple way ?

What do you mean "plot"?

If you want to understand the material, you have no choice but to study the data sheet until you do. That is a fact of life.

It is easy to program the timers and do experiments on them using the Arduino IDE, and you can attach an LED to a PWM output pin to see the results.

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);
}

something like that but with the timer interrupt

See reply #10.

Always use code tags when posting code.

Why do you want an interrupt?

see reply #8

Reply #8 doesn't even come close to answering that question

Reply #8 makes no sense.

Good luck with your project.

im using the pwm and RC filter to make it like a dac , with various pwm duty cycle i can generate a signal , im trying to simulate an ecg patient simulator so i need 9 signals of each cardiac lead

I suggest spending some quality time with the reference material that has been suggested.

Well i think i will do that , thanks for your quick responses

For the ECG application, I can tell you, you don't need hardware PWM. The bandwidth is low enough that you could use standard loop() timing with micros().

Nor do you need "phase correct" PWM. Not for this.

Please, also correct your post and put your code inside code tags.