28#define CURRENT_CLASS ATmega2560
38#if defined(IR_USE_TIMER1)
40#define TIMER_INTR_NAME TIMER1_COMPA_vect
43 TCCR1A |= _BV(COM1A1);
47 TCCR1A &= ~(_BV(COM1A1));
61 const uint16_t pwmval = F_CPU / 2 / frequency;
63 TCCR1B = _BV(WGM13) | _BV(CS10);
65 OCR1A = pwmval * dutyCycle / 100;
70 TCCR1B = _BV(WGM12) | _BV(CS10);
78#elif defined(IR_USE_TIMER2)
81#define TIMER_INTR_NAME TIMER2_COMPA_vect
84 TCCR2A |= _BV(COM2B1);
88 TCCR2A &= ~(_BV(COM2B1));
100 const uint8_t pwmval = F_CPU / 2 / frequency;
102 TCCR2B = _BV(WGM22) | _BV(CS20);
104 OCR2B = pwmval * dutyCycle / 100;
107#define TIMER_COUNT_TOP (F_CPU * microsPerTick / 1000000UL)
118 OCR2A = TIMER_COUNT_TOP / 8;
126#elif defined(IR_USE_TIMER3)
128#define TIMER_INTR_NAME TIMER3_COMPA_vect
131 TCCR3A |= _BV(COM3A1);
135 TCCR3A &= ~(_BV(COM3A1));
139 TIMSK3 = _BV(OCIE3A);
147 const uint16_t pwmval = F_CPU / 2 / frequency;
149 TCCR3B = _BV(WGM33) | _BV(CS30);
151 OCR3A = pwmval * dutyCycle / 100;
156 TCCR3B = _BV(WGM32) | _BV(CS30);
164#elif defined(IR_USE_TIMER4)
166#define TIMER_INTR_NAME TIMER4_COMPA_vect
169 TCCR4A |= _BV(COM4A1);
173 TCCR4A &= ~(_BV(COM4A1));
177 TIMSK4 = _BV(OCIE4A);
185 const uint16_t pwmval = F_CPU / 2 / frequency;
187 TCCR4B = _BV(WGM43) | _BV(CS40);
189 OCR4A = pwmval * dutyCycle / 100;
194 TCCR4B = _BV(WGM42) | _BV(CS40);
202#elif defined(IR_USE_TIMER5)
204#define TIMER_INTR_NAME TIMER5_COMPA_vect
207 TCCR5A |= _BV(COM5A1);
211 TCCR5A &= ~(_BV(COM5A1));
215 TIMSK5 = _BV(OCIE5A);
223 const uint16_t pwmval = F_CPU / 2 / frequency;
225 TCCR5B = _BV(WGM53) | _BV(CS50);
227 OCR5A = pwmval * dutyCycle / 100;
232 TCCR5B = _BV(WGM52) | _BV(CS50);
242#error Config error, either IR_USE_TIMER1, IR_USE_TIMER2, IR_USE_TIMER3, IR_USE_TIMER4, or IR_USE_TIMER5 must be defined.
int8_t dutycycle_t
Type for duty cycle in percent.
uint32_t frequency_t
Type for modulation frequency in Hz.
This class serves as an HAL (Hardware Abstraction Layer).
virtual void timerEnableIntr()=0
Start periodic sampling routine.
virtual void timerDisablePwm()=0
Turn off PWM output.
virtual void timerConfigHz(frequency_t hz, dutycycle_t dutyCycle=defaultDutyCycle)=0
Configure hardware PWM, but do not enable it.
static const unsigned long microsPerTick
virtual void timerDisableIntr()=0
Turn off periodic interrupts.
virtual void timerEnablePwm()=0
Start PWM output.
virtual void timerConfigNormal()=0
Disables the PWM configuration.