-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpwm.c
48 lines (41 loc) · 868 Bytes
/
pwm.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "pwm.h"
#include "display.h" //Provides millis()
#include "hwprofile.h"
#include "status.h"
static uint16_t gPwmPeriod = 0;
static uint16_t gPwmLevel = 0;
static uint32_t gPwmPeriodStart = 0;
void pwm_init()
{
//Set pin direction
PWM_DIR_REG |= kPwmPinMask;
}
void pwm_set_period(uint16_t period)
{
gPwmPeriod = period;
gPwmLevel = 0;
gPwmPeriodStart = millis();
}
void pwm_update(void)
{
uint32_t timestamp = millis();
if (timestamp > gPwmPeriodStart + gPwmPeriod)
gPwmPeriodStart = timestamp;
if (timestamp < gPwmPeriodStart + gPwmLevel) {
//PWM Active
PWM_OUTPUT_REG |= kPwmPinMask;
status_set(kStatusHeat);
} else {
//PWM Inactive
PWM_OUTPUT_REG &= ~kPwmPinMask;
status_clear(kStatusHeat);
}
}
void pwm_set_level(uint16_t level)
{
gPwmLevel = level;
}
uint16_t pwm_period()
{
return gPwmPeriod;
}