|
1 |
| -// Initial startup functions for GNSS, SD, display, radio, etc |
| 1 | +/*------------------------------------------------------------------------------ |
| 2 | +Begin.ino |
2 | 3 |
|
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) |
4 | 33 | {
|
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 | +} |
24 | 43 |
|
| 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 |
25 | 52 | int pin_deviceID = 35;
|
26 | 53 | uint16_t idValue = analogReadMilliVolts(pin_deviceID);
|
27 | 54 | log_d("Board ADC ID (mV): %d", idValue);
|
28 | 55 |
|
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))) |
39 | 64 | 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))) |
46 | 68 | {
|
47 | 69 | productVariant = REFERENCE_STATION;
|
48 | 70 | // We can't auto-detect the ZED version if the firmware is in configViaEthernet mode,
|
49 | 71 | // so fake it here - otherwise messageSupported always returns false
|
50 | 72 | zedFirmwareVersionInt = 112;
|
51 | 73 | }
|
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 |
56 | 89 | else
|
57 |
| - { |
58 | 90 | productVariant = RTK_UNKNOWN; // Need to wait until the GNSS and Accel have been initialized
|
59 |
| - } |
60 | 91 | }
|
61 | 92 |
|
62 | 93 | // Setup any essential power pins
|
|
0 commit comments