THW-Funk-Audio-Switch/Programm/Audio-Switch/io/Timer.hpp

53 lines
803 B
C++
Raw Normal View History

2020-10-30 23:22:11 +01:00
/*
* Timer.h
*
* Created: 30.10.2020 19:46:04
* Author: netz
*/
#ifndef TIMER_H_
#define TIMER_H_
2020-11-02 00:27:02 +01:00
#include <avr/io.h>
template <long int timer_count_till, int timer_prescaler>
class TimerT {
2020-10-30 23:22:11 +01:00
// Methods
private:
protected:
public:
2020-11-02 00:27:02 +01:00
TimerT() {
TCCR1A = 0;
TCCR1B = 0;
TCCR1C = 0;
TCNT1 = 0;
OCR1AH = (timer_count_till<<8);
OCR1AL = timer_count_till;
TIMSK1 = (1<<ICIE1) | (1<<OCIE1A);
}
void Stop() {
TCCR1B = 0;
}
void Start() {
TCCR1B = timer_prescaler;
}
void Reset() {
TCNT1 = 0;
}
2020-10-30 23:22:11 +01:00
// Variables
private:
protected:
public:
};
2020-11-02 00:27:02 +01:00
typedef TimerT<settings_timer_count_till, settings_timer_prescaler> Timer;
2020-10-30 23:22:11 +01:00
#endif /* TIMER_H_ */