Implementing deadtime for SPWM

Hi, I’m using mega2560 and needed to implement a complementary pulse with deadtime. Currently, I have an issue in implementing deadtime for the first pulse which is cleared when compared. I’ve manage to implement deadtime for the second pulse. Is there any way that I could solve this issue?

 TCCR1A=0;                         
  TCCR1B=0;                        
  TCNT1=0;
  TCCR1A=0b10110010;              
  TCCR1B=0b00011001;                
  ICR1=1600;

ISR(TIMER1_OVF_vect){               //Interrupt when timer 1 overflows

  if(i<200)
  {
    OCR1A=sinPWM[i];
    OCR1B=sinPWM[i]+3;
  }
  i++;

What initial compare values do you use for OCR1A and OCR1B which will trigger on the initial timer cycle before the first overflow interrupt starts picking from the table?

If they are both 0, then one wave form will be 100% on for the first cycle. Perhaps one should be 0 and the other 1600.

If working with the initial values doesn't fix your issue, perhaps you could start with both outputs in non inverted mode, set them both to 0, and change over one mode on the first overflow interrupt.

Which timer PWM mode are you using? You need to use a phase-correct mode for deadtime generation.

I tried using phase correct mode but I couldn’t get the right duty cycle for both pulses (e.g. OCR1A = 40% duty cycle, OCR1B=60% duty cycle). since I only modified OCR1B and didnt do anything on OCR1A. If I add a -3 to OCR1A then no deadtime would be introduced.There would be a small difference in the duty cycle with OCR1B having a lower cycle.

I generating sine lookup table.

for(m=0;m<200;m++)
  {                                 
    temp=(sin(m*PI/(199)))*1600;
    sinPWM[m]=int(temp+0.5);
  }

Is there any way that I could do when pwm is doing

up-counting:

OCR1A=sinPWM*;*
OCR1B=sinPWM*+3;*
down-counting:
OCR1A=sinPWM*-3;*
OCR1B=sinPWM*;*
Or is there any way that I could access to the carrier signal function (i.e. the triangular waveform) of the pwm?
I tried using TCNT to find whether it is up/down counting but it’s don’t work too.

Or is there any access to the TOVn and ICFn flag? so I could know whether it is up/down counting.
Or is there any way to invert OCR1A? where I use the inverted setting and +3 and then invert again to get non-inverting output?

Ran12345:
Or is there any way to invert OCR1A? where I use the inverted setting and +3 and then invert again to get non-inverting output?

I think, you better use two timers, instead of tweaking one twice per each cycle. Check the code in reply #7, set the phase 180 between timer 1 and 3, and duty as necessary.