2 #include <avr/interrupt.h>
4 #include <util/delay.h>
5 #include <util/atomic.h>
10 * Single PWM channel on OC1B (pin PB4 of Tiny45).
11 * Counts from 0 to 0xFF, without OCR1C compare.
14 static unsigned char pwm_enabled;
16 static void inline enable_pll()
19 PLLCSR = _BV(PLLE) | _BV(LSM);
21 /* Synchronize to the phase lock */
23 while ((PLLCSR & _BV(PLOCK)) == 0)
31 power_timer1_enable();
33 TCCR1 = _BV(CTC1) | _BV(CS11); // pll_clk/2
34 GTCCR = _BV(COM1B1) | _BV(PWM1B);
37 OCR1B = 0; // initial stride is 0
39 DDRB &= ~(_BV( PB4 ));
40 PORTB &= ~_BV(PB4); // set to zero
45 DDRB &= ~(_BV( PB4 ));
46 PORTB &= ~(_BV( PB4 ));
51 PLLCSR &= ~(_BV(PLLE) | _BV(PCKE));
59 PLLCSR &= ~(_BV(PLLE) | _BV(PCKE));
63 void pwm_set(uint8_t stride)