#define TCNT2_PERIOD_US 1000
#define TCNT2_PRESCALER 64
void initADC()
{
noInterrupts();
ADMUX |= (1 << REFS1) | (1 << REFS0); // Internal 1.1V Voltage Reference with external capacitor at AREF pin
ADCSRA |= (1 << ADIE); // Activating ADC Conversion Complete Interrupt
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Division factor between the system clock frequency and the input clock to the ADC set to 128 -> 125 kHz
while(!(ADCSRA & ADIF)); // Wait until first conversion is complete, which takes 200 µs
interrupts();
}
void initTimer()
{
noInterrupts();
TCCR2A |= (1 << WGM21); // set CTC-MODE: WGM21 = 1
OCR2A = TCNT2_PERIOD_US * F_CPU / 1e6 / TCNT2_PRESCALER; // set Output Compare Register A
TIMSK2 |= (1 << OCIE2A); // enable Output Compare A Match Interrupt
TCCR2B |= (1 << CS22); // clkT2S/8 (From prescaler)
interrupts();
}
unsigned int adc_value = 0;
ISR(ADC_vect)
{
adc_value = ADC;
}
ISR(TIMER2_COMPA_vect)
{
}
void setup()
{
}
void loop()
{
}