49 |
49 |
50 |
50 |
51 TCCR1A = (1<<WGM10)|(1<<COM1A1) // Set up the two Control registers of Timer1. |
51 TCCR1A = (1<<WGM10)|(1<<COM1A1) // Set up the two Control registers of Timer1. |
52 |(1<<COM1B1); // Wave Form Generation is Fast PWM 8 Bit, |
52 |(1<<COM1B1); // Wave Form Generation is Fast PWM 8 Bit, |
53 TCCR1B = (1<<WGM12) // OC1A and OC1B are cleared on compare match |
53 TCCR1B = (1<<WGM12) // OC1A and OC1B are cleared on compare match |
54 |(1<<CS10); // and set at BOTTOM. Clock Prescaler is 1024. |
54 |(1<<CS11); // and set at BOTTOM. Clock Prescaler is 1024. |
55 |
55 |
56 |
56 |
57 uint8_t i; |
57 uint8_t i; |
58 for(i = 0; i<5; i++) { |
58 for(i = 0; i<5; i++) { |
59 led(i); |
59 led(i); |
72 void pwm_update(void) { |
72 void pwm_update(void) { |
73 PORTB |= _BV(0); // switch on led driver |
73 PORTB |= _BV(0); // switch on led driver |
74 |
74 |
75 switch (mode) { |
75 switch (mode) { |
76 case 1: |
76 case 1: |
77 OCR1A = 63; // Dutycycle of OC1A = 25% |
77 OCR1A = 40; // Dutycycle of OC1A = 25% |
78 break; |
78 break; |
79 case 2: |
79 case 2: |
80 OCR1A = 127; // Dutycycle of OC1A = 50% |
80 OCR1A = 110; // Dutycycle of OC1A = 50% |
81 break; |
81 break; |
82 case 3: |
82 case 3: |
83 OCR1A = 189; // Dutycycle of OC1A = 75% |
83 OCR1A = 160; // Dutycycle of OC1A = 75% |
84 break; |
84 break; |
85 case 4: |
85 case 4: |
86 OCR1A = 255; // Dutycycle of OC1A = 100% |
86 OCR1A = 255; // Dutycycle of OC1A = 100% |
87 break; |
87 break; |
88 default: |
88 default: |