PWM code to drive 4 IGBTs to made single phase power inverter

Hello, i’m beginner in arduino programming and i’m wrote this code to switching 4 IGBTs to made single phase power inverter,.
i using timer0 and timer2 in phase corrected PWM mode , with prescaller N=256 to achived the desired frequances .
i designed outputs of timer0 (5,6) to switch IGBT 1,2 and outputs of timer2 to switch IGBT (3,4)
and i change the TOP value by changing yhe value in register OCRnA by use DO WHILE loop with counter
i=i+1 j=j+1 and IF statement in the code .
the problem is when compiling the code by IDE that’s no error put when upload HEX file to the board (arduino uno ) on Proteus and measure the output by oscope there is nothing happen .
please any one can help me ?

int i=0;
int j=0;

void setup() {

//timer 0
pinMode(6, OUTPUT);//6-A
pinMode(5, OUTPUT);//5-B

//non-inverted
TCCR0A = _BV(COM0A1) | _BV(COM0B1) ;
//phase correct pwm with prescaler N=256
TCCR1B = _BV(WGM02) | _BV(WGM00) | _BV(CS02);

// timer 2
pinMode(3, OUTPUT);//3-B
pinMode(11, OUTPUT);//11-A

//non-inverted
TCCR2A = _BV(COM2A1) | _BV(COM2B1) ;
//phase correct pwm with prescaler N=256
TCCR2B = _BV(WGM22) | _BV(WGM20) | _BV(CS22) | _BV(CS21) ;

}

void loop() {
j = 0;
i = 0;

do
{
//for timer 0 ( IGBT-1 & IGBT-3 )
//TOP = OCR0A at mode 5
// Fout=16 000 000 / 2 * N * OCR0A

if ( i = 0 ) OCR0A = 13; // 2500Hz
if ( i = 1 ) OCR0A = 16; // 2000Hz
if ( i = 2 ) OCR0A = 21; // 1500Hz
if ( i = 3 ) OCR0A = 31; // 1000Hz
if ( i = 4 ) OCR0A = 39; // 800Hz
if ( i = 5 ) OCR0A = 78; // 400Hz
if ( i = 6 ) OCR0A = 156; // 200Hz
if ( i = 7 ) OCR0A = 78; // 400Hz
if ( i = 8 ) OCR0A = 39; // 800Hz
if ( i = 9 ) OCR0A = 31; // 1000Hz
if ( i = 10 ) OCR0A = 21; // 1500Hz
if ( i = 11 ) OCR0A = 16; // 2000Hz
if ( i = 12 ) OCR0A = 13; // 2500Hz
if ( i > 12 ) OCR2A = 0; //duty cycle = 0%
i = i + 1;

}while ( i <= 12 );

do
{
//for timer 2 ( IGBT-2 & IGBT-4 )
//TOP = OCR2A at mode 5
// Fout=16 000 000 / 2 * N * OCR2A

if ( j = 0 ) OCR2A = 13; // 2500Hz
if ( j = 1 ) OCR2A = 16; // 2000Hz
if ( j = 2 ) OCR2A = 21; // 1500Hz
if ( j = 3 ) OCR2A = 31; // 1000Hz
if ( j = 4 ) OCR2A = 39; // 800Hz
if ( j = 5 ) OCR2A = 78; // 400Hz
if ( j = 6 ) OCR2A = 156; // 200Hz
if ( j = 7 ) OCR2A = 78; // 400Hz
if ( j = 8 ) OCR2A = 39; // 800Hz
if ( j = 9 ) OCR2A = 31; // 1000Hz
if ( j = 10 ) OCR2A = 21; // 1500Hz
if ( j = 11 ) OCR2A = 16; // 2000Hz
if ( j = 12 ) OCR2A = 13; // 2500Hz
if ( j > 12 ) OCR2A = 0; //duty cycle = 0%
j = j+1;

}while ( j <= 12 );

}

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :slight_smile:

You have used TCCR1B in place of TCCR0B.

You are using i=n when you mean i == n.

= is not the same as ==
Edit
Coffee took too long
OK John got it.