47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
|
/*
|
||
|
* Comperator.hpp
|
||
|
*
|
||
|
* Created: 17.11.2014 23:50:04
|
||
|
* Author: netz
|
||
|
*/
|
||
|
|
||
|
|
||
|
#ifndef COMPERATOR_H_
|
||
|
#define COMPERATOR_H_
|
||
|
|
||
|
#include "hardware/pin.hpp"
|
||
|
|
||
|
template <typename Port, int pin_ain0, int pin_ain1>
|
||
|
class Comperator {
|
||
|
public:
|
||
|
Comperator() {
|
||
|
init();
|
||
|
}
|
||
|
uint8_t is_active() {
|
||
|
return ACSR & (1<<ACO);
|
||
|
}
|
||
|
private:
|
||
|
void init() {
|
||
|
comppin0::make_input();
|
||
|
comppin1::make_input();
|
||
|
init_comperator();
|
||
|
}
|
||
|
void init_comperator() {
|
||
|
// Analog Comparator initialization
|
||
|
// Analog Comparator: On
|
||
|
// The Analog Comparator's positive input is
|
||
|
// connected to the AIN0 pin
|
||
|
// The Analog Comparator's negative input is
|
||
|
// connected to the AIN1 pin
|
||
|
// Analog Comparator Input Capture by Timer/Counter 1: Off
|
||
|
ACSR=(0<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
|
||
|
ADCSRB=(0<<ACME);
|
||
|
// Digital input buffer on AIN0: Off
|
||
|
// Digital input buffer on AIN1: Off
|
||
|
DIDR1=(1<<AIN0D) | (1<<AIN1D);
|
||
|
}
|
||
|
const typedef avrlib::pin<Port, pin_ain0> comppin0;
|
||
|
const typedef avrlib::pin<Port, pin_ain1> comppin1;
|
||
|
};
|
||
|
|
||
|
#endif /* COMPERATOR_H_ */
|