That strange "no serial comm against all logic"-error reappeared.
[cerebrum.git] / pwm.c
blobe2522ca02a5a1cd4afe26f64a18233b81145fc9f
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(WGM00)|_BV(WGM01);
13 TCCR0B |= _BV(CS01)|_BV(CS00)|_BV(WGM02);
14 TIMSK0 |= _BV(TOIE0);
15 OCR0A = 1;
16 pwm_output_setup();
17 //FIXME debug stuff
18 DDRB |= 0x20;
21 //Software PWM stuff
22 //Called every 256 cpu clks (i.e should not get overly long)
23 ISR(TIMER0_OVF_vect){
24 pwm_cycle<<=1;
25 if(!pwm_cycle){
26 pwm_cycle = 1;
28 uint8_t Q = 0;
29 if(pwm_cycle&0x80)
30 PORTB ^= 0x20;
31 pwm_unset_outputs();
32 Q |= !!(pwm_val[0] & pwm_cycle);
33 Q |= (pwm_val[1] & pwm_cycle)?2:0;
34 Q |= (pwm_val[2] & pwm_cycle)?4:0;
35 Q |= (pwm_val[3] & pwm_cycle)?8:0;
36 /*Q |= (pwm_val[4] & pwm_cycle)?16:0;
37 Q |= (pwm_val[5] & pwm_cycle)?32:0;
38 Q |= (pwm_val[6] & pwm_cycle)?64:0;
39 Q |= (pwm_val[7] & pwm_cycle)?128:0;
41 pwm_set_outputs(Q);
42 OCR0A = pwm_cycle;
45 uint8_t pwm_cycle = 1;
46 uint8_t pwm_val[8];
48 #else//HAS_PWM_SUPPORT
50 void pwm_setup(){}
52 #endif//HAS_PWM_SUPPORT