How to inverter synchronization to Grid

Here my code to generate spwm inverter
'''
// MakeIdea [Hemant]
#include <avr/io.h>
#include <avr/interrupt.h>
#include <math.h>

#define SinDivisions (200)

static int microMHz = 16;
static int freq = 50;
static long int period;
static unsigned int lookUp[SinDivisions];
static char theTCCR1A = 0b10000010;

const byte vfbPin = A0,
tfbPin = A1,
battPin = A2;

void setup()
{
double temp;

period = microMHz*1e6/freq/SinDivisions;

for(int i = 0; i < SinDivisions/2; i++)
{
temp = sin(i2M_PI/SinDivisions)*period;
lookUp[i] = (int)(temp+0.5);
}

TCCR1A = theTCCR1A;

TCCR1B = 0b00011001;

TIMSK1 = 0b00000001;

ICR1 = period;
sei();

DDRB = 0b00000110;
}

void loop(){;}

ISR(TIMER1_OVF_vect)
{
static int num;
static int delay1;
static char trig;

if(delay1 == 1)
{
  theTCCR1A ^= 0b10100000;
  TCCR1A = theTCCR1A;
  delay1 = 0;        
} 
else if(num >= SinDivisions/2)
{
  num = 0;                
  delay1++;
  // trig ^=0b00000001;
  // digitalWrite(13,trig);
}
OCR1A = OCR1B = lookUp[num];
num++;

}
'''

but i don't know to synchronization to Grid, i was build zero crossing detector to detect phase grid. Plese help code to syncron grid with zero crossing detector.

With a zero crossing detection, you can be 180 degrees out of sync and could not know it. What does Google say about synchronizing to your grid?

that reference to syncron grid with zero crossing detector. but I tried with the same method with this can not sync yet

Moderator edit: spammy link removed

@ethan_scholes22, you will have to find another source for that material. That webpage is way too spammy.

okee, try here

Try the technique described in the Yopie post and let us know how well it works.

Stop posting a link to that site.

That should work.

I wonder the purpose of sync to the grid wave form. One cycle it may be in sync, then next not in sync.

Good point. You'd have to let the grid do the synchronization.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.