fantemp/thermistor/pwm.cpp

26 lines
375 B
C++
Raw Normal View History

#include "pwm.hpp"
#include "io/io.hpp"
namespace pwm {
static constexpr uint8_t PWM_TOP = 40;
void init()
{
io::Pin<io::P::D5> pwmPin;
pwmPin.dir(io::Dir::OUT);
pwmPin = false;
TCCR0A = (1 << COM0B1) | (1 << WGM00);
TCCR0B = (1 << WGM02) | (1 << CS01);
OCR0A = PWM_TOP;
}
void setDuty(uint8_t percent)
{
OCR0B = (percent * PWM_TOP) / 100;
}
} // namespace pwm