Ready to pull from altar.
[cerebrum.git] / pwm.c
blobc881f9b2436998e4a31ca1b5589a679408953f34
2 #include "pwm.h"
4 //The PWM has no loop function. It runs entirely out of the ISR.
5 void pwm_loop(){}
7 #ifdef HAS_PWM_SUPPORT
9 void pwm_setup(){
10 //s/w "BCM"(<== "Binary Code Modulation") timer setup
11 TCCR0A |= _BV(WGM00)|_BV(WGM01);
12 TCCR0B |= _BV(CS02);
13 TIMSK0 |= _BV(TOIE0);
14 //FIXME set PWM output DDRs
17 //Software PWM stuff
18 //Called every 256 cpu clks (i.e should not get overly long)
19 ISR(TIMER0_OVF_vect){
20 uint8_t Q = 0;
21 Q |= (pwm_val[0] & pwm_cycle);
22 Q |= (pwm_val[1] & pwm_cycle)?2:0;
23 Q |= (pwm_val[2] & pwm_cycle)?4:0;
24 Q |= (pwm_val[3] & pwm_cycle)?8:0;
25 Q |= (pwm_val[4] & pwm_cycle)?16:0;
26 PORTC = Q;
27 OCR0A = pwm_cycle;
28 pwm_cycle<<=1;
29 if(!pwm_cycle){
30 pwm_cycle = 1;
34 uint8_t pwm_cycle = 0;
35 uint8_t pwm_val[PWM_COUNT];
37 #else//HAS_PWM_SUPPORT
39 void pwm_setup(){}
41 #endif//HAS_PWM_SUPPORT