PWM with atmega16 help !!

Discussion in 'Homework Help' started by ht systems, Mar 21, 2012.

  1. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    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 :


    Code ( (Unknown Language)):
    1.    
    2. #include <avr/io.h>
    3. #include <avr/interrupt.h>
    4. static void avr_init(void);
    5. volatile uint8_t x ;
    6. int main(void)
    7. {
    8.     avr_init();
    9.    
    10.     for(;;)
    11.     {
    12.         // Tasks here.
    13.       OCR0 = x ;
    14.      
    15.    
    16.     }
    17.    
    18.     return(0);
    19. }
    20.  
    21. static void avr_init(void)
    22. {
    23.     // Initialize device here.
    24.     DDRB = 0XFF ;
    25.  
    26.  TCCR0= 1 | _BV(WGM01) ;
    27.          //| _BV(COM01) | _BV(CS00) ;
    28.  TIMSK |=_BV(OCIE0);
    29.  
    30.  TCCR0= _BV(WGM00) |_BV(WGM01)
    31.      |_BV(COM01) |_BV(CS00) ;
    32.  
    33.     PORTB = 0 ;
    34.  
    35.  sei();
    36.     return;
    37. }
    38.    
    39. ISR(TIMER0_COMP_vect)
    40. {
    41.  
    42.  x+=200 ;
    43.    
    44. }
    45.  
     
    Last edited by a moderator: Mar 22, 2012
  2. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    always no answer ....................
     
  3. bug13

    Well-Known Member

    Feb 13, 2012
    1,208
    38
Loading...