2 #include <avr/interrupt.h>
3 #include <util/delay.h>
12 /* Synchronize to the phase lock */
14 while ((PLLCSR & _BV(PLOCK)) == 0)
18 // PWM channel D is inverted, ...
19 TCCR1C = _BV(COM1D1) | _BV(COM1D0) | _BV(PWM1D);
20 // PWM channels A and B are not
21 TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(PWM1A) | _BV(PWM1B);
23 TCCR1B = _BV(CS10); // no clock prescaling
26 OCR1C = PWM_MAX & 0xFF; // TOP value
28 TC1H = PWM_MAX >> 8; // PWM3 is inverted
29 OCR1D = PWM_MAX & 0xFF;
32 OCR1B = OCR1A = 0; // initial stride is 0
34 DDRB &= ~(_BV( PB1 ) | _BV( PB3 ) | _BV( PB5 )); // tristate it
35 PORTB &= ~(_BV( PB1 ) | _BV( PB3 ) | _BV( PB5 )); // set to zero
40 DDRB &= ~(_BV( PB1 ) | _BV( PB3 ) | _BV( PB5 ));
41 TCCR1D = TCCR1C = TCCR1B = TCCR1A = 0;
46 void pwm_off(unsigned char n)
49 case 0: DDRB &= ~_BV(PB1); break;
50 case 1: DDRB &= ~_BV(PB3); break;
51 case 2: DDRB &= ~_BV(PB5); break;
55 void pwm_set(unsigned char n, uint16_t stride)
63 stride = PWM_MAX - stride;
88 static void inline pwm_handler()