summaryrefslogtreecommitdiff
path: root/software_pwm.h
blob: 1976c6546cf1fe9d110faae562594ff5622a559b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef SOFTWARE_PWM_H
#define SOFTWARE_PWM_H

#include <stdint.h>

#define SOFTPWM_PIN_COUNT 8
#define PWM_FREQ 300  //hz

/** Our microcontroller we have laying around only has 4 hardware pwm channels.
 * Because we want 8, we will create software PWM as an alternative.
 *
 * Notes to self to forcast nessessary optimizations (translates to color accuracy): 
 *  Our error margin is 1/255th (13us at pwm freq 300hz) of a cycle. 
 *  Cycles until next channel could be triggered:
 *    209 at 16Mhz
 *    130 at 10Mhz (have one available)
 *    104 at 8Mhz
 *    13 at 1Mhz (have one available)
 *
 * To decrease the amount of cycles every pwm timer interrupt, we'll generate the 
 *
 * We might also want to make sure these values aren't updated every loop
 *  from random noise coming from the potentiometer. Test without, decide then.
 */

void init_softpwm();
void initilize_duty_cycle(uint8_t pin);
void softpwm_set(uint8_t pin, uint8_t duty);


#endif