Files
RGBController/pwm.cpp
2017-05-14 23:29:55 +02:00

35 lines
482 B
C++

#include "pwm.h"
Pwm16b::Pwm16b()
{
DDRB |= (1<<PB1);
OCR1A = 0x0; //0% pwm to start0
TCNT1=0;
TCCR1A|=(1<<COM1A1); //enable OCR1A only;
ICR1=100;
on();
}
void Pwm16b::off()
{
TCCR1B = 0x00;
}
void Pwm16b::on()
{
// Phase and freq correct 16 bit PWM start pwm with /1024 prescaller
TCCR1B|=(1<<WGM13) | (1<<WGM10);
TCCR1B|= (1 << CS12);
}
void Pwm16b::setDuty(const uint16_t duty)
{
OCR1A = duty;
}
Pwm16b::~Pwm16b()
{
off();
}