updated the todo file
[cerebrum.git] / pwm.c
blobfb4a1d257954dff656cddb80297e037b0ccb1f98
2 #include "pwm.h"
3 #include "led.h"
5 //The PWM has no loop function. It runs entirely out of the ISR.
6 void pwm_loop(){}
8 #ifdef HAS_PWM_SUPPORT
10 void pwm_setup(){
11 //s/w "BCM"(<== "Binary Code Modulation") timer setup
12 TCCR0A |= _BV(WGM01);
13 TCCR0B |= _BV(CS02);
14 TIMSK0 |= _BV(OCIE0A);
15 OCR0A = 1;
16 pwm_output_setup();
19 ISR(TIMER0_COMPA_vect){
20 pwm_unset_outputs();
21 pwm_cycle<<=1;
22 if(!pwm_cycle){
23 pwm_cycle = 1;
25 uint8_t Q = 0;
26 Q |= (pwm_val[0] & pwm_cycle)?1:0;
27 Q |= (pwm_val[1] & pwm_cycle)?2:0;
28 Q |= (pwm_val[2] & pwm_cycle)?4:0;
29 Q |= (pwm_val[3] & pwm_cycle)?8:0;
30 Q |= (pwm_val[4] & pwm_cycle)?16:0;
31 Q |= (pwm_val[5] & pwm_cycle)?32:0;
32 Q |= (pwm_val[6] & pwm_cycle)?64:0;
33 Q |= (pwm_val[7] & pwm_cycle)?128:0;
34 pwm_set_outputs(Q);
35 TCNT0 = 0;
36 OCR0A = pwm_cycle;
39 uint8_t pwm_cycle = 1;
40 uint8_t pwm_val[8];
42 #else//HAS_PWM_SUPPORT
44 void pwm_setup(){}
46 #endif//HAS_PWM_SUPPORT