Hello! I wanted to generate a complementary PWM with dead time. I also wanted to control duty cycle and frequency. The program which I was took from other sources doesn't work. Anyone help me to achieve the requirements.
The bits in TCCR1A and TCCR1B set WGM10:3 to 0b1010 or WGM mode 10: PWM Phase Correct with TOP = ICR1;
The top bits of TCCR1A =0xB2 control the complimentary-ness of OC1A and OC1B.
Does the DDRB setting match the OC1A and OC1B for your device? I just guessed Uno/328p for the datasheet, but if the code is written for a different chip than you are using, things could need different settings.
If the setup code is correct, then you just need to figure out how to adjust ICR1 to control frequency, and how to adjust OCR1A and OCR1B to control deadtime or overlap.
// WGM 10 (Phase Correct PWM, TOP in ICR1)
// Normal PWM on A, Inverse PWM on B
// prescale = 1
TCCR1A = COM1A1 | COM1B1 | COM1B0 | WGM11
TCCR1B = WGM13 | CS10
0x01FFF = 511;
16MHz / 512 / 2 = 15625 Hz PWM
The Phase Correct means the timer will count from 0 to ICR1 and then back down to 0. The OC1A pin will turn off on the way up and on on the way down. The OC1B pin will turn on on the way up and off on the way down. As long as OCR1A is lower than OCR1B there will be dead time.
Setting them both to 100 will get you NO dead time and 100/512ths duty cycle (about 19.5%) on A and the inverse (about 80.5%) on B.
Change ICR1 to get different frequencies and change OCR1A and OCR1B relative to ICR1 to get different duty cycles. The difference between A and B will be the dead time in 16th's of a microsecond.