PWM for 3-phase Inverter

MarkT:
I've been thinking about this some more and looking at what the Arduino
timers can do.

I've realised the Mega has some timers with 3 output pins, and this allows a
clever way to modulate 3 output signals for doing this.

It relies on having an inverter module that takes one input per phase (in
other words it generates its own high/low gate signals with appropriate
dead-time automatically generated - without this you'd need some
circuitry to do this).

Using phase-correct mode you can effectively get two control pulses per
cycle (where the pulses are differential between separate phase outputs).

So here's some test code - it drives pins 6/7/8 which are the pins for timer4.

// For the MEGA!

#define HALF 400
#define PERIOD 800

void setup ()
{
  setup_cosines () ;
  TCCR4A = 0xFE ;  // phase correct (mode 1010)
  TCCR4B = 0x11 ;  // prescale by 1
  TIMSK4 = 0x01 ;  // overflow interrupt
  ICR4  = PERIOD+1 ;    // 100us cycle time, so effectively 50us.
  OCR4A = HALF ;
  OCR4B = HALF ;
  OCR4C = HALF ;
  pinMode (6, OUTPUT) ;  // the OCR4A pin, our U phase
  pinMode (7, OUTPUT) ;  // the OCR4B pin, our V phase
  pinMode (8, OUTPUT) ;  // the OCR4C pin, our W phase
}

// control time values, in units of 62.5ns
volatile int u = HALF ;
volatile int v = HALF ;
volatile int w = HALF ;

// every complete cycle we update the registers.
ISR (TIMER4_OVF_vect)
{
  OCR4A = u ;
  OCR4B = v ;
  OCR4C = w ;
}

// a cosine table, 1024 entries in range +/-127
char cosine [0x400] ;

void setup_cosines ()
{
  for (int i = 0 ; i < 0x400 ; i++)
  {
    float a = PI * i / 0x200 ;
    cosine [i] = round (127.0 * cos (a)) ;
  }
}

int phase = 0 ; // taken modulo 1024
int amplitude = 200 ;  // 201 is maximum value without overflow.

void loop ()
{
  phase ++ ;  // phase increment, normally this would be done by DDS loop
  int newu = (cosine [phase & 0x3FF] * amplitude + 0x1F) >> 6 ;
  int newv = (cosine [(phase + 0x155) & 0x3FF] * amplitude + 0x1F) >> 6 ;
  int neww = - newu - newv ;
  newu += HALF ;
  newv += HALF ;
  neww += HALF ;
  noInterrupts () ;  // interrupt-safe updating of u,v,w
  u = newu ;
  v = newv ;
  w = neww ;
  interrupts () ;
  delay (2) ;
}




[ edited to fix mistake in the ISR ]

I have tested this Code and it really works very good. That was a great favor for my project.
Please help to define the base frequency of this code. I mean I have connected to 3 phase motor and it run with approx 0.5Hz. How it happens? any justification???