SPWM phase shfit

I want the 60hz SPWM waveforms to come out phase at 0, 90, 180 and 270 degrees on each of the 4 pins. I found the code that comes out when it's 0 degrees 180 degrees.
But I don't know how to implement two SPWM pins with 90 degree 270 degree phase shift.

#include <avr/io.h>
#include <avr/interrupt.h>
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
int lookUp1[] = {15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 
179, 194, 209, 223, 238, 252, 266, 280, 294, 308, 322, 336, 350, 
363, 377, 390, 403, 416, 429, 441, 454, 466, 478, 490, 502, 514, 
525, 537, 548, 559, 569, 580, 590, 600, 610, 620, 629, 638, 647, 
656, 664, 673, 681, 689, 696, 703, 711, 717, 724, 730, 736, 742, 
747, 753, 758, 762, 767, 771, 775, 778, 782, 785, 788, 790, 792, 
794, 796, 797, 798, 799, 800, 800, 800, 800, 799, 798, 797, 795, 
794, 792, 789, 787, 784, 781, 777, 774, 770, 765, 761, 756, 751, 
746, 740, 734, 728, 722, 715, 708, 701, 694, 686, 678, 670, 662, 
653, 644, 635, 626, 616, 607, 597, 587, 576, 566, 555, 544, 533, 
521, 510, 498, 486, 474, 462, 450, 437, 424, 412, 399, 385, 372, 
359, 345, 332, 318, 304, 290, 276, 262, 247, 233, 218, 204, 189, 
175, 160, 145, 130, 115, 100, 85, 70, 55, 40, 25, 10, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0};
int lookUp2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 30, 45, 60, 
75, 90, 105, 120, 135, 150, 165, 179, 194, 209, 223, 238, 252, 266, 
280, 294, 308, 322, 336, 350, 363, 377, 390, 403, 416, 429, 441, 
454, 466, 478, 490, 502, 514, 525, 537, 548, 559, 569, 580, 590, 
600, 610, 620, 629, 638, 647, 656, 664, 673, 681, 689, 696, 703, 
711, 717, 724, 730, 736, 742, 747, 753, 758, 762, 767, 771, 775, 
778, 782, 785, 788, 790, 792, 794, 796, 797, 798, 799, 800, 800, 
800, 800, 799, 798, 797, 795, 794, 792, 789, 787, 784, 781, 777, 
774, 770, 765, 761, 756, 751, 746, 740, 734, 728, 722, 715, 708, 
701, 694, 686, 678, 670, 662, 653, 644, 635, 626, 616, 607, 597, 
587, 576, 566, 555, 544, 533, 521, 510, 498, 486, 474, 462, 450, 
437, 424, 412, 399, 385, 372, 359, 345, 332, 318, 304, 290, 276, 
262, 247, 233, 218, 204, 189, 175, 160, 145, 130, 115, 100, 85, 70, 
55, 40, 25, 10};
//PWM Output Pins115

int spwm1 = 11;
int spwm2 = 12;
int pin9 = 9;
int pin10 = 10;
//Analog Input Pins
int Voltage = 1;
int Current = 3;
int Bus = 5;
//Digital Output Pins
int relayControl = 21;
int Temperature = 24;
int OverCurrent = 26;
int Error = 30;
int flag = 0;
//LCD Pins
LiquidCrystal lcd(8, 2, 4, 5, 6, 7);
//(rs, enable, d4, d5, d6, d7) 
// Data wire for the temperature sensor on pin 3
#define ONE_WIRE_BUS 24
//Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
//Pass our oneWire reference to Dallas Temperature. (Onewire and 
//dallas temperature libraries had to be downloaded for the DS18b20 
//temperature sensor)
DallasTemperature sensors( & oneWire);
void setup() {
 Serial.begin(9600);
 // Register initialization
 TCCR1A = 0b10100010;
 TCCR1B = 0b00011001;
 TIMSK1 = 0b00000001;
//Input Compare Register, TOP value, Arduino Clock/Desired 
//Switching frequency
ICR1 = 800;
sei(); // Enable global interrupts.
pinMode(spwm1, OUTPUT);
pinMode(spwm2, OUTPUT);
pinMode(pin9, OUTPUT);
pinMode(pin10, OUTPUT);
pinMode(relayControl, OUTPUT);

pinMode(OverCurrent, OUTPUT);
pinMode(Error, OUTPUT);
//LCD Setup
while (flag == 0) {
 lcd.begin(16, 2);
 sensors.begin(); // starts the temperature sensor reading
 sensors.requestTemperatures(); 
 // Send the command to get temperature readings
 // set cursor position to start of first line on the LCD
 // read the input on analog pin 1:
 int voltageSensor = analogRead(Voltage);
 
 // Convert the analog reading (which goes from 0 - 1023) 
 // to a voltage (0 - 5V):
 float fivevolt = voltageSensor * (5.0 / 1023.0);
 
 // Linearly Interpolate [0,5]V to [0,150]V
 float voltageOutput = 30 * voltageSensor * (5.0 / 1023.0);
 lcd.setCursor(0, 0);
 lcd.print("Voltage: ");
 lcd.print(voltageOutput);
 lcd.print("V");
 // read the input on analog pin 3:
 int currentSensor = analogRead(Current);
 
 // Convert the analog reading (which goes from 0 - 1023) 
 // to a voltage (0 - 5V):
 float currentOutput = currentSensor * (5.0 / 1023.0);
 lcd.setCursor(0, 1);
 lcd.print("Current: ");
 lcd.print(currentOutput);
 lcd.print("A");
 delay(1000);
 lcd.clear();
 // read the input on analog pin 5:
 int busSensor = analogRead(Bus);
 
 // Convert the analog reading (which goes from 0 - 1023) 
 // to a voltage (0 - 5V):
 float busVoltage = busSensor * (5.0 / 1023.0);
 // Linearly Interpolate [0,2.5]V to [0,180]V
 float busOutput = busVoltage * 72;
 lcd.setCursor(0, 0);
 lcd.print("Bus Volt: ");
 lcd.print(busOutput);

 lcd.print("V");
 if (busOutput >= 180 || busOutput <= 150.0) {
 digitalWrite(relayControl, HIGH); 
 // If busoutput > 180V then turn on the relay 
 // to shutdown the Inverter
 digitalWrite(Error, HIGH);
 flag = 1;
 }
 if (currentOutput >= 4) {
 // If the current is > 4A then pin26 set to HIGH 
 // to the over current protection circuit
 digitalWrite(OverCurrent, HIGH);
 digitalWrite(Error, HIGH);
 flag = 2;
 }
 // Temperature reading
 lcd.setCursor(0, 1);
 lcd.print(" Temp: ");
 lcd.print(sensors.getTempCByIndex(0));
 // You can have more than one DS18B20 on the same bus; 
 // 0 refers to the first IC on the wire
 lcd.print("C");
 delay(1000);
 lcd.clear();
 float Power = voltageOutput * currentOutput;
 lcd.print(" Power: ");
 lcd.print(Power);
 lcd.print("W");
 delay(1000);
 lcd.clear();
}
if (flag == 1) {
 lcd.setCursor(0, 0);
 lcd.print("Error");
 lcd.setCursor(0, 1);
 lcd.print("Check Bus O/P");
}
if (flag == 2) {
 lcd.setCursor(0, 0);
 lcd.print("Error");
 lcd.setCursor(0, 1);
 lcd.print("Check Current");
}
}//end of void setup118

void loop() {}
ISR(TIMER1_OVF_vect) {
 static int num;
 OCR1A = lookUp1[num];
 if (num < 166) {
 digitalWrite(pin9, LOW);
 digitalWrite(pin10, HIGH);

 } else if (num > 166) {
 digitalWrite(pin9, HIGH);
 digitalWrite(pin10, LOW);

 }
 OCR1B = lookUp2[num];
 if (++num >= 332) {
 num = 0; // Reset num
 }
}

This is the code I used. What more should I add?
use mega2560

Hi, @ewsdfsdsa
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

Where did you find the code? (link to site please).

I would suggest you try that code first and make sure it works in your application, before editing it to get the extra outputs.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia: