-
Notifications
You must be signed in to change notification settings - Fork 0
/
adwandler.h
65 lines (52 loc) · 2.92 KB
/
adwandler.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Adwandler.h - Copyright 2016, HZB, ILL/SANE & ISIS
// Add the following commands:
//
// => void adc_init(uint8_t channel);
// => uint16_t readChannel(uint8_t mux, uint8_t avg);
// => uint16_t readChannel_calib(uint8_t channel, uint8_t nb_readings, double adc_zero);
// => double get_he_level(double res_min, double res_max, double r_span, double r_zero, uint8_t count, double t_nil, uint8_t show_progress);
// => uint8_t get_batt_level(double batt_min, double batt_max, double r_zero);
// => double round_double(double number, int digits);
// => double map_to_default(uint16_t adcVal);
// => double map_to_current(uint16_t adcVal);
// => double map_to_volt(uint16_t adcVal);
// => double map_to_batt(uint16_t adcVal);
// => int16_t map_to_pres(uint16_t adcVal, double zero, double span);
// => double calc_he_level(double res_x, double res_min, double res_max);
// => double map_to_test(uint16_t adcVal);
#ifndef ADWANDLER_H
#define ADWANDLER_H
#define VOLTAGE_REF (3.34) // Voltage reference measured on the PCB
#define MAP_TO_CURRENT_FACTOR 0.29058 // Prop. constant between Current and measured ADC-Value
#define MAP_TO_CURRENT_OFFSET -2.2581 // Offset Current and measured ADC-Value
#define MAP_TO_VOLTAGE_FACTOR 0.0756 // Prop. constant between Voltage and measured ADC-Value
#define MAP_TO_VOLTAGE_OFFSET 0 // Offset between Voltage and measured ADC-Value
#define MAP_TO_BATT_FACTOR 0.01685 // Prop. constant between Battery voltage and measured ADC-Value
#define MAP_TO_BATT_OFFSET 0 // Offset between Battery voltage and measured ADC-Value
#define MAP_TO_PRESS_FACTOR 0.00978 // Prop. constant between pressure and measured ADC-Value will be corrected by span and zero
//Analog to Digital Converter channels on Port A
#define VOLT_SUPPLY_MEAS 0
#define CURRENT_PROBE_MEAS 1
#define VOLT_PROBE_MEAS 2
#define BATTERY 3
#define PRESSURE 4
#define ADC_LOOPS 10
#define MEASURE_PIN_OFF PORTC&=~(1<<PC0); // Set PORTC.0 to 0 to switch off the Wandler-L1720 (current supply board)
#define MEASURE_PIN_ON PORTC|=(1<<PC0); // Set PORTC.0 to 1 to switch on the Wandler-L1720 (current supply board)
#define CHECK_MEASURE_PIN (PINC & (1<<PC0)) // ???
#define errCode_TooHighRes 2000
void adc_init(uint8_t channel); // Initialize analog to digital converter on selected channel
double round_double(double number, int digits); ///rounds double number
double map_to_current(double adcVal);
double map_to_volt(double adcVal);
double map_to_default(double adcVal);
double map_to_test(double adcVal);
double map_to_batt(double adcVal);
double map_to_pres(double adcVal, double zero, double span);
double calc_he_level(double res_x, double res_min, double res_max);
double readChannel(uint8_t mux, uint16_t avg);
double readChannel_calib(uint8_t channel, uint8_t nb_readings, double adc_zero);
uint8_t get_batt_level(double batt_min, double batt_max);
double read_Vcc();
uint32_t readChannel_ILM(uint8_t channel, uint16_t avg);
#endif //adwandler.h