-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRefVoltage.ino
67 lines (59 loc) · 2.13 KB
/
RefVoltage.ino
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
66
67
/*
#include <avr/io.h>
#include <avr/eeprom.h>
#include "Transistortester.h"
#include "Makefile.h" //J-L
*/
// computes RHmultip, adc_internal_reference (ADCconfig.U_Bandgap) and ref_mv_offs
void RefVoltage(void) {
// RefVoltage interpolates table RHtab corresponding to voltage ref_mv_offs .
// RHtab contain the factors to get capacity from load time with 470k for
// different Band gab reference voltages.
// for remember:
//resistor 470000 Ohm 1000 1050 1100 1150 1200 1250 1300 1350 1400 mV
//uint16_t RHTAB[] MEM_TEXT = { 954, 903, 856, 814, 775, 740, 707, 676, 648};
#define Ref_Tab_Abstand 50 // displacement of table is 50mV
#define Ref_Tab_Beginn 1000 // begin of table is 1000mV
unsigned int referenz;
unsigned int y1, y2;
uint8_t tabind;
uint8_t tabres;
#ifdef AUTO_CAL
referenz = ref_mv + (int16_t)eeprom_read_word((uint16_t *)(&ref_offset));
#else
referenz = ref_mv + REF_C_KORR;
#endif
ref_mv_offs = referenz;
#ifdef AUTO_RH
if (referenz >= Ref_Tab_Beginn) {
referenz -= Ref_Tab_Beginn;
} else {
referenz = 0; // limit to begin of table
}
tabind = referenz / Ref_Tab_Abstand;
tabres = referenz % Ref_Tab_Abstand;
tabres = Ref_Tab_Abstand-tabres;
if (tabind > 7) {
tabind = 7; // limit to end of table
}
// interpolate the table of factors
y1 = pgm_read_word(&RHtab[tabind]);
y2 = pgm_read_word(&RHtab[tabind+1]);
// RHmultip is the interpolated factor to compute capacity from load time with 470k
RHmultip = ((y1 - y2) * tabres + (Ref_Tab_Abstand/2)) / Ref_Tab_Abstand + y2;
//########################################
#else
RHmultip = DEFAULT_RH_FAKT; // default Multiplier for capacity measurement with R_H (470KOhm)
#endif
#if PROCESSOR_TYP == 8
referenz = 2560; // use defined internal ADC Voltage
#else
referenz = ref_mv; // use the read out internal Reference voltage
#endif
#ifdef AUTO_CAL
ADCconfig.U_Bandgap = (referenz + (int8_t)eeprom_read_byte((uint8_t *)&RefDiff));
#else
ADCconfig.U_Bandgap = (referenz + REF_R_KORR);
#endif
adc_internal_reference = ADCconfig.U_Bandgap;
} /* end of RefVoltage */