PWM with atmega16 help !!

Thread Starter

ht systems

Joined Aug 2, 2011
71
Hello , Im building a circuit transform 12vdc to 220vac using pwm in atmega16 to create a sinewave on the output but the problem is that the the output gives a strange wave so i guess that my code is wrong .
Note : Im using winavr and i chose PORTB and fast PWM .
I post a pdf file about my circuit and the code .
Please i really need help and thank you very much .

The code is :


Rich (BB code):
#include <avr/io.h>
#include <avr/interrupt.h>
static void avr_init(void);
volatile uint8_t x ;
int main(void)
{
    avr_init();
    
    for(;;)
    {
        // Tasks here.
      OCR0 = x ;
     
   
    }
    
    return(0);
}
 
static void avr_init(void)
{
    // Initialize device here.
    DDRB = 0XFF ; 
 
 TCCR0= 1 | _BV(WGM01) ;
         //| _BV(COM01) | _BV(CS00) ;
 TIMSK |=_BV(OCIE0);
 
 TCCR0= _BV(WGM00) |_BV(WGM01) 
     |_BV(COM01) |_BV(CS00) ; 
  
    PORTB = 0 ; 
 
 sei();
    return;
}
    
ISR(TIMER0_COMP_vect) 
{
 
 x+=200 ;
   
}
 

Attachments

Last edited by a moderator:
Top