Skip to content

Commit b27a2b5

Browse files
authored
Merge pull request #723 from LeeLeahy2/adc-id
Better document the resistor divider and the ADC ID value
2 parents 4607bc5 + b96e8a8 commit b27a2b5

File tree

1 file changed

+74
-43
lines changed

1 file changed

+74
-43
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,93 @@
1-
// Initial startup functions for GNSS, SD, display, radio, etc
1+
/*------------------------------------------------------------------------------
2+
Begin.ino
23
3-
void identifyBoard()
4+
This module implements the initial startup functions for GNSS, SD, display,
5+
radio, etc.
6+
------------------------------------------------------------------------------*/
7+
8+
//----------------------------------------
9+
// Constants
10+
//----------------------------------------
11+
12+
#define MAX_ADC_VOLTAGE 3300 // Millivolts
13+
14+
// Testing shows the combined ADC+resistors is under a 1% window
15+
#define TOLERANCE 4.75 // Percent: 95.25% - 104.75%
16+
17+
//----------------------------------------
18+
// Macros
19+
//----------------------------------------
20+
21+
// ADC input
22+
// Ra KOhms | Rb KOhms
23+
// MAX_ADC_VOLTAGE -----/\/\/\/\-----+-----/\/\/\/\----- Ground
24+
//
25+
#define ADC_ID_mV(RaK, RbK) ((uint16_t)(MAX_ADC_VOLTAGE * RbK / (RaK + RbK)))
26+
27+
//----------------------------------------
28+
// Hardware initialization functions
29+
//----------------------------------------
30+
31+
// Determine if the measured value matches the product ID value
32+
bool idWithAdc(uint16_t mvMeasured, uint16_t mvProduct)
433
{
5-
// Use ADC to check resistor divider
6-
// Express: 10/3.3
7-
// Express+: 3.3/10
8-
// Facet: 10/10
9-
// Facet L-Band: 10/20
10-
// Reference Station: 20/10
11-
// Facet L-Band Direct: 10/100
12-
// Surveyor: ID resistors do not exist
13-
14-
const float rtkExpressID = 3.3 / (10 + 3.3) * 3300; // 819mV
15-
const float rtkExressPlusID = 10.0 / (10 + 3.3) * 3300; // 2481mV
16-
const float rtkFacetID = 10.0 / (10 + 10) * 3300; // 1650mV
17-
const float rtkFacetLbandID = 20.0 / (20 + 10) * 3300; // 2200mV
18-
const float rtkReferenceStationID = 10.0 / (10 + 20) * 3300; // 1100mV
19-
const float rtkFacetLbandDirectID = 1.0 / (4.7 + 1) * 3300; // 579mV
20-
21-
const float tolerance = 0.0475; // 4.75% Testing shows the combined ADC+resistors is under a 1% window
22-
const float upperThreshold = 1 + tolerance; // 104.75%
23-
const float lowerThreshold = 1 - tolerance; // 95.25%
34+
uint16_t lowerThreshold;
35+
uint16_t upperThreshold;
36+
37+
// Return true if the mvMeasured value is within the tolerance range
38+
// of the mvProduct value
39+
upperThreshold = (1.0 + (TOLERANCE / 100.)) * mvProduct;
40+
lowerThreshold = (1.0 - (TOLERANCE / 100.)) * mvProduct;
41+
return (upperThreshold > mvMeasured) && (mvMeasured > lowerThreshold);
42+
}
2443

44+
// Use a pair of resistors on pin 35 to ID the board type
45+
// If the ID resistors are not available then use a variety of other methods
46+
// (I2C, GPIO test, etc) to ID the board.
47+
// Assume no hardware interfaces have been started so we need to start/stop any hardware
48+
// used in tests accordingly.
49+
void identifyBoard()
50+
{
51+
// Use ADC to check the resistor divider
2552
int pin_deviceID = 35;
2653
uint16_t idValue = analogReadMilliVolts(pin_deviceID);
2754
log_d("Board ADC ID (mV): %d", idValue);
2855

29-
if (idValue > (rtkFacetID * lowerThreshold) && idValue < (rtkFacetID * upperThreshold))
30-
{
31-
productVariant = RTK_FACET;
32-
}
33-
else if (idValue > (rtkFacetLbandID * lowerThreshold) && idValue < (rtkFacetLbandID * upperThreshold))
34-
{
35-
productVariant = RTK_FACET_LBAND;
36-
}
37-
else if (idValue > (rtkExpressID * lowerThreshold) && idValue < (rtkExpressID * upperThreshold))
38-
{
56+
// Order checks by millivolt values high to low
57+
58+
// Facet L-Band Direct: 4.7/1 --> 551mV < 579mV < 607mV
59+
if (idWithAdc(idValue, ADC_ID_mV(4.7, 1)))
60+
productVariant = RTK_FACET_LBAND_DIRECT;
61+
62+
// Express: 10/3.3 --> 779mV < 819mV < 858mV
63+
else if (idWithAdc(idValue, ADC_ID_mV(10, 3.3)))
3964
productVariant = RTK_EXPRESS;
40-
}
41-
else if (idValue > (rtkExressPlusID * lowerThreshold) && idValue < (rtkExressPlusID * upperThreshold))
42-
{
43-
productVariant = RTK_EXPRESS_PLUS;
44-
}
45-
else if (idValue > (rtkReferenceStationID * lowerThreshold) && idValue < (rtkReferenceStationID * upperThreshold))
65+
66+
// Reference Station: 20/10 --> 1047mV < 1100mV < 1153mV
67+
else if (idWithAdc(idValue, ADC_ID_mV(20, 10)))
4668
{
4769
productVariant = REFERENCE_STATION;
4870
// We can't auto-detect the ZED version if the firmware is in configViaEthernet mode,
4971
// so fake it here - otherwise messageSupported always returns false
5072
zedFirmwareVersionInt = 112;
5173
}
52-
else if (idValue > (rtkFacetLbandDirectID * lowerThreshold) && idValue < (rtkFacetLbandDirectID * upperThreshold))
53-
{
54-
productVariant = RTK_FACET_LBAND_DIRECT;
55-
}
74+
// Facet: 10/10 --> 1571mV < 1650mV < 1729mV
75+
else if (idWithAdc(idValue, ADC_ID_mV(10, 10)))
76+
productVariant = RTK_FACET;
77+
78+
// Facet L-Band: 10/20 --> 2095mV < 2200mV < 2305mV
79+
else if (idWithAdc(idValue, ADC_ID_mV(10, 20)))
80+
productVariant = RTK_FACET_LBAND;
81+
82+
// Express+: 3.3/10 --> 2363mV < 2481mV < 2600mV
83+
else if (idWithAdc(idValue, ADC_ID_mV(3.3, 10)))
84+
productVariant = RTK_EXPRESS_PLUS;
85+
86+
// ID resistors do not exist for the following:
87+
// Surveyor
88+
// Unknown
5689
else
57-
{
5890
productVariant = RTK_UNKNOWN; // Need to wait until the GNSS and Accel have been initialized
59-
}
6091
}
6192

6293
// Setup any essential power pins

0 commit comments

Comments
 (0)