SHARE
TWEET

Untitled

a guest May 26th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * LED_fading_02.c
  3. * with 10bit valuetable and phasecorrect pwm
  4. * Controller: ATmega88 @ 8MHz
  5. */
  6.  
  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9.  
  10. const unsigned int pwm_table_10[64] =
  11. {
  12.     0, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10,
  13.     11, 12, 13, 15, 17, 19, 21, 23, 26, 29, 32, 36, 40, 44, 49, 55,
  14.     61, 68, 76, 85, 94, 105, 117, 131, 146, 162, 181, 202, 225, 250,
  15.     279, 311, 346, 386, 430, 479, 534, 595, 663, 739, 824, 918, 1023
  16. };
  17.  
  18. int main(void)
  19. {
  20.     DDRB |= (1<<PB1); // OC1A = output
  21.     ICR1 = 1023;        // ICR1 = Top Value
  22.      
  23.     // Mode 10: PWM, Phase Correct, Prescaler = 1, Clear OC1A on compare match
  24.     TCCR1A = (1 << COM1A1) + (1 << WGM11);
  25.     TCCR1B = (1 << WGM13) + (1 << CS10);
  26.      
  27.     while(1)
  28.     {
  29.         for(int i=0; i<=63; i++)     // PWM inkrementieren
  30.         {
  31.             OCR1A = pwm_table_10[i];    // Tabellenwert i dem OCR1A zuweisen
  32.             _delay_ms(50);
  33.         }
  34.          
  35.         for(int i=63; i>= 1; i--)        // PWM dekrementieren
  36.         {
  37.             OCR1A = pwm_table_10[i];    // Tabellenwert i dem OCR1A zuweisen
  38.             _delay_ms(50);
  39.         }
  40.     }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top