Search This Blog

Saturday, November 24, 2018

PWM Atmega32:Inverter Mode Register Settings

SPWM

  // INVERTED MODE
TCCR1A = _BV(COM1A0) | _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);

// NON INVERTED MODE                    // set on match
// TCCR1A =   _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
TCCR1B = _BV(WGM13) | _BV(WGM12);

/* start with a duty */
OCR1A = 0;
OCR1B = 0;

/* enable interrupt on timer overflow */
TIMSK = _BV(TOIE1);
/* enable interrupt      */
 sei();

TCCR1B |= _BV(CS00);

These can be used as bipolar settings.
Use sine table entries and update OCR1A/B after a particular time/interupt.

Sine wave points dc (Duty cycle array) (top - TOP for timer)
for(j=0;j {
   val = (j  * PI)/points;
   val = 1000 * sin(val) + 1000;
   val = val/2000;
   val = (val-0.5)* percentage + 0.5;
   dc[j]=top * val;
}

No comments:

Post a Comment