8 Bit ADU 1V Signal get result every 1ms by timer0  Ver 1.0
kner 2016
start.cpp
Go to the documentation of this file.
1 
18 #include <Arduino.h>
19 
20 //#define DEBUG_LCD
21 #include "_debug.h"
22 
28 void setup()
29 {
30  DIDR0=(1<<ADC0D); //disable ADC0 digital Buffer
31  ADMUX|=(1<<REFS1) | (0<<REFS0); //internal 1.1 reference ADC0 as input
32  ADMUX|=(1<<ADLAR); //left adjust result, so 8 Bits in ADCH are used
33 
34  ADCSRA|=(1<<ADEN); //enable ADU
35  ADCSRA|=(1<<ADATE); // auto conversion
36  ADCSRA|=(1<<ADIE); // interrupt enable
37  ADCSRA|=(1<<ADPS2) | (0<<ADPS1) | (0<<ADPS0); //Conversion Prescaler = 16 means 1MHz conversion clock)
38  ADCSRB=(1<<ADTS2) | (0<<ADTS1) | (0<<ADTS0); // use Timer0 Overflow as start of conversion
39 
40  sei();
41 }
42 
44 void loop()
45 {
46  volatile static int dummy=0; dummy++; //needed for simulator if no additional lines of code
47 }
48 
51 ISR(ADC_vect)
52 {
53  // ADC comes up here when he done converting....
54  PORTB = ADCH; //most significant bits of the result
55  static int n=0; n++;
56  TDEC(n);
57 }
58 
void loop()
Definition: start.cpp:44
void setup()
Definition: start.cpp:28
ISR(ADC_vect)
Definition: start.cpp:51