Skip to content

Commit 1cac8fa

Browse files
authored
Merge pull request #730 from LeeLeahy2/adc-id
Rework ADC ID values
2 parents 238d1ea + 34f4104 commit 1cac8fa

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

Firmware/RTK_Surveyor/Begin.ino

+28-20
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,37 @@ Begin.ino
1515
#define TOLERANCE 4.75 // Percent: 95.25% - 104.75%
1616

1717
//----------------------------------------
18-
// Macros
18+
// Hardware initialization functions
1919
//----------------------------------------
2020

2121
// ADC input
2222
// Ra KOhms | Rb KOhms
2323
// MAX_ADC_VOLTAGE -----/\/\/\/\-----+-----/\/\/\/\----- Ground
2424
//
25-
#define ADC_ID_mV(RaK, RbK) ((uint16_t)(MAX_ADC_VOLTAGE * RbK / (RaK + RbK)))
26-
27-
//----------------------------------------
28-
// Hardware initialization functions
29-
//----------------------------------------
3025

3126
// Determine if the measured value matches the product ID value
32-
bool idWithAdc(uint16_t mvMeasured, uint16_t mvProduct)
27+
bool idWithAdc(uint16_t mvMeasured, float resVcc, float resGnd)
3328
{
3429
uint16_t lowerThreshold;
30+
float raK;
31+
float rbK;
3532
uint16_t upperThreshold;
33+
float voltage;
34+
35+
// Compute the upper threshold
36+
raK = resVcc * (1.0 - (TOLERANCE / 100.));
37+
rbK = resGnd * (1.0 + (TOLERANCE / 100.));
38+
voltage = MAX_ADC_VOLTAGE * rbK / (raK + rbK);
39+
upperThreshold = (int)ceil(voltage);
40+
41+
// Compute the lower threshold
42+
raK = (double)resVcc * (1.0 + (TOLERANCE / 100.));
43+
rbK = (double)resGnd * (1.0 - (TOLERANCE / 100.));
44+
voltage = MAX_ADC_VOLTAGE * rbK / (raK + rbK);
45+
lowerThreshold = (int)floor(voltage);
3646

3747
// Return true if the mvMeasured value is within the tolerance range
3848
// of the mvProduct value
39-
upperThreshold = (1.0 + (TOLERANCE / 100.)) * mvProduct;
40-
lowerThreshold = (1.0 - (TOLERANCE / 100.)) * mvProduct;
4149
return (upperThreshold > mvMeasured) && (mvMeasured > lowerThreshold);
4250
}
4351

@@ -55,32 +63,32 @@ void identifyBoard()
5563

5664
// Order checks by millivolt values high to low
5765

58-
// Facet L-Band Direct: 4.7/1 --> 551mV < 579mV < 607mV
59-
if (idWithAdc(idValue, ADC_ID_mV(4.7, 1)))
66+
// Facet L-Band Direct: 4.7/1 --> 534mV < 578mV < 626mV
67+
if (idWithAdc(idValue, 4.7, 1))
6068
productVariant = RTK_FACET_LBAND_DIRECT;
6169

62-
// Express: 10/3.3 --> 779mV < 819mV < 858mV
63-
else if (idWithAdc(idValue, ADC_ID_mV(10, 3.3)))
70+
// Express: 10/3.3 --> 761mV < 818mV < 879mV
71+
else if (idWithAdc(idValue, 10, 3.3))
6472
productVariant = RTK_EXPRESS;
6573

66-
// Reference Station: 20/10 --> 1047mV < 1100mV < 1153mV
67-
else if (idWithAdc(idValue, ADC_ID_mV(20, 10)))
74+
// Reference Station: 20/10 --> 1031mV < 1100mV < 1171mV
75+
else if (idWithAdc(idValue, 20, 10))
6876
{
6977
productVariant = REFERENCE_STATION;
7078
// We can't auto-detect the ZED version if the firmware is in configViaEthernet mode,
7179
// so fake it here - otherwise messageSupported always returns false
7280
zedFirmwareVersionInt = 112;
7381
}
7482
// Facet: 10/10 --> 1571mV < 1650mV < 1729mV
75-
else if (idWithAdc(idValue, ADC_ID_mV(10, 10)))
83+
else if (idWithAdc(idValue, 10, 10))
7684
productVariant = RTK_FACET;
7785

78-
// Facet L-Band: 10/20 --> 2095mV < 2200mV < 2305mV
79-
else if (idWithAdc(idValue, ADC_ID_mV(10, 20)))
86+
// Facet L-Band: 10/20 --> 2129mV < 2200mV < 2269mV
87+
else if (idWithAdc(idValue, 10, 20))
8088
productVariant = RTK_FACET_LBAND;
8189

82-
// Express+: 3.3/10 --> 2363mV < 2481mV < 2600mV
83-
else if (idWithAdc(idValue, ADC_ID_mV(3.3, 10)))
90+
// Express+: 3.3/10 --> 2421mV < 2481mV < 2539mV
91+
else if (idWithAdc(idValue, 3.3, 10))
8492
productVariant = RTK_EXPRESS_PLUS;
8593

8694
// ID resistors do not exist for the following:

0 commit comments

Comments
 (0)