forked from bastl-instruments/bastlMicroGranny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastAnalogRead.h
49 lines (37 loc) · 865 Bytes
/
fastAnalogRead.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* fastAnalogRead.h
*
* Created on: 22.09.2014
* Author: user
*/
#ifndef FASTANALOGREAD_H_
#define FASTANALOGREAD_H_
#include <Arduino.h>
#include <portManipulations.h>
namespace fastAnalogRead {
void init() {
ADMUX = (1<<REFS0); // external reference voltage
ADCSRA = (1<<ADEN); // enable ADC
ADCSRA |= (1<<ADPS2) | (1<<ADPS1) |(1<<ADPS0); // prescaler
}
// channel 8 can be used to measure the temperature of the chip
void connectChannel(uint8_t number) {
ADMUX &= (11110000);
ADMUX |= number;
DIDR0 = (1<<number);
}
void startConversion() {
setHigh(ADCSRA,ADSC);
}
bool isConversionFinished() {
return (ADCSRA & (1<<ADIF));
}
bool isConversionRunning() {
return !(ADCSRA & (1<<ADIF));
}
uint16_t getConversionResult() {
uint16_t result = ADCL;
return result | (ADCH<<8);
}
}
#endif /* FASTANALOGREAD_H_ */