Skip to content

Commit 6f8975d

Browse files
committed
Internal ADC channels correctly removed from variants. Updated example. Variants modified.
In normal course, general pins are converted to pads. With this commit any pin number over 99 is treated as a special internal ADC channel. These 'pins' are not converted to pads via ap3_gpio_pin2pad() (calls the board variant). ADC works correctly. The analogRead was updated as well. Internal temp is now more accurately calculated. All variants updated.
1 parent 8162eb2 commit 6f8975d

File tree

7 files changed

+55
-72
lines changed

7 files changed

+55
-72
lines changed

cores/arduino/ard_sup/analog/ap3_analog.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,17 @@ uint16_t analogRead(uint8_t pinNumber)
129129
am_hal_adc_sample_t Sample;
130130
uint32_t ui32NumSamples = 1;
131131

132-
uint8_t padNumber = ap3_gpio_pin2pad(pinNumber);
132+
uint8_t padNumber;
133+
134+
if (pinNumber >= ADC_DIFF0 && pinNumber <= ADC_INTERNAL_VSS)
135+
{
136+
//Special handling of internal ADC channels
137+
padNumber = pinNumber;
138+
}
139+
else
140+
{
141+
padNumber = ap3_gpio_pin2pad(pinNumber);
142+
}
133143

134144
//Look up configuration status based on pad number
135145
uint8_t indi;
@@ -292,18 +302,7 @@ ap3_err_t ap3_set_pin_to_analog(uint8_t pinNumber)
292302

293303
uint8_t funcsel = 0;
294304
am_hal_gpio_pincfg_t pincfg = INPUT;
295-
296-
//Handle special ADC channels
297-
if (pinNumber >= ADC_DIFF0 && pinNumber <= ADC_INTERNAL_VSS)
298-
{
299-
//Don't use the pin to pad lookup from the variant file
300-
retval = ap3_analog_pad_funcsel(pinNumber, &funcsel);
301-
}
302-
else
303-
{
304-
//Normal pin lookup
305-
retval = ap3_analog_pad_funcsel(ap3_gpio_pin2pad(pinNumber), &funcsel);
306-
}
305+
retval = ap3_analog_pad_funcsel(ap3_gpio_pin2pad(pinNumber), &funcsel);
307306

308307
if (retval != AP3_OK)
309308
{

cores/arduino/ard_sup/ap3_analog_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SOFTWARE.
2828

2929
enum EXTRA_ADC_PADS
3030
{
31-
AP3_ADC_DIFF0_PAD = 51, //More than physical pads on Apollo3
31+
AP3_ADC_DIFF0_PAD = 100, //More than physical pads on Apollo3
3232
AP3_ADC_DIFF1_PAD,
3333
AP3_ADC_TEMP_PAD,
3434
AP3_ADC_DIV3_PAD,

libraries/Examples/examples/Example4_analogRead/Example4_analogRead.ino

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
Feel like supporting open source hardware?
1515
Buy a board from SparkFun!
16-
SparkFun Edge: https://www.sparkfun.com/products/15170
16+
SparkFun Edge: https://www.sparkfun.com/artemis
1717
1818
Hardware Connections:
1919
Upload code
@@ -30,37 +30,37 @@ void setup()
3030

3131
pinMode(LED, OUTPUT);
3232

33-
//analogReadResolution(14); //Set resolution to 14 bit
33+
analogReadResolution(14); //Set resolution to 14 bit
3434
//analogReadResolution(16); //Set resolution to 16 bit - will pad ADC output with two zeros
3535
}
3636

3737
void loop()
3838
{
3939
digitalWrite(LED, LOW);
4040

41-
int myValue1 = analogRead(A1); //Automatically sets pin to analog input
42-
Serial.print("A1: ");
41+
int myValue1 = analogRead(A3); //Automatically sets pin to analog input
42+
Serial.print("A3: ");
4343
Serial.print(myValue1);
4444

45-
int internalTemp = analogRead(ADC_TEMP); //Read internal temp sensor. 3.8mV/C, +/-3C
46-
Serial.print("\tinternalTemp: ");
47-
Serial.print(internalTemp);
48-
49-
int vss = analogRead(ADC_VSS); //Read internal VSS
50-
Serial.print("\tvss: ");
51-
Serial.print(vss);
52-
5345
//TODO enable battload
54-
int div3 = analogRead(ADC_DIV3); //Read VCC across a 1/3 resistor divider
46+
int div3 = analogRead(ADC_INTERNAL_VCC_DIV3); //Read VCC across a 1/3 resistor divider
5547
Serial.print("\tVCC/3: ");
5648
Serial.print(div3);
5749

58-
float vcc = (float)div3 * 6 / 1024.0; //Convert 1/3 VCC to VCC
50+
float vcc = (float)div3 * 6 / 16384.0; //Convert 1/3 VCC to VCC
5951
Serial.print(" VCC: ");
6052
Serial.print(vcc, 2);
6153
Serial.print("V");
6254

63-
//pinMode(A4, OUTPUT); //Reset analog function to false.
55+
int internalTempVoltage = analogRead(ADC_INTERNAL_TEMP); //Read internal temp sensor. 3.8mV/C, +/-3C
56+
double internalTemp = internalTempVoltage * vcc / 16384.0; //Convert internal temp reading to voltage
57+
internalTemp /= 0.0038; //Convert voltage to degrees C
58+
Serial.print("\tinternalTemp: ");
59+
Serial.print(internalTemp, 2);
60+
61+
int vss = analogRead(ADC_INTERNAL_VSS); //Read internal VSS (should be 0)
62+
Serial.print("\tvss: ");
63+
Serial.print(vss);
6464

6565
Serial.println();
6666

variants/SparkFun_BlackBoard_Artemis_ATP/config/variant.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,10 @@ const ap3_gpio_pad_t ap3_variant_pinmap[AP3_VARIANT_NUM_PINS] = {
7070
43,
7171
44,
7272
45,
73-
46,
73+
AP3_GPIO_PAD_UNUSED, //The one pad not broken out of the Apollo3 on the Artemis
7474
47,
7575
48,
7676
49,
77-
AP3_ADC_DIFF0_PAD, //50 - Not a real pad, ADC_DIFF0
78-
AP3_ADC_DIFF1_PAD, //51 - Not a real pad, ADC_DIFF1
79-
AP3_ADC_TEMP_PAD, //52 - Not a real pad, ADC_TEMP
80-
AP3_ADC_DIV3_PAD, //53 - Not a real pad, ADC_DIV3
81-
AP3_ADC_VSS_PAD, //54 - Not a real pad, ADC_VSS
8277
};
8378

8479
// Uart Definitions

variants/SparkFun_BlackBoard_Artemis_ATP/config/variant.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424

2525
#include "Arduino.h"
2626

27-
#define AP3_VARIANT_NUM_PINS (55)
27+
#define AP3_VARIANT_NUM_PINS (50)
2828

2929
// Pin map declaration
3030
extern const ap3_gpio_pad_t ap3_variant_pinmap[AP3_VARIANT_NUM_PINS];
@@ -58,12 +58,6 @@ extern Uart Serial1;
5858
#define A33 33
5959
#define A35 35
6060

61-
#define ADC_DIFF0 50 //Not legal pins. Used for pad lookup
62-
#define ADC_DIFF1 51
63-
#define ADC_TEMP 52
64-
#define ADC_DIV3 53
65-
#define ADC_VSS 54
66-
6761
#define LED_BUILTIN 5
6862

6963
// Pins with dedicated silk covering the pin number

variants/SparkFun_BlackBoard_Artemis_Nano/config/variant.cpp

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,30 @@ SOFTWARE.
2525
const ap3_gpio_pad_t ap3_variant_pinmap[AP3_VARIANT_NUM_PINS] = {
2626
//~ = PWM, A = ADC
2727
//Apollo Pad, //Silkscreen indicator
28-
13, //A0 - ~I2SBCLK/RX1
29-
33, //A1 - ~SWO/32kHz
30-
11, //A2 - ~PDMDATA
31-
29, //A3 - ~PDMDATA
32-
18, //4 - ~CMPIN1/SCCIO
33-
31, //A5 - ~SCCCLK
34-
43, //6 - ~SDA3/MISO3/RX1
35-
42, //7 - SCL3/SCK3/TX1
36-
38, //8 - MOSI3/RX1
37-
39, //9 - ~SCL4/SCK4/TX1
38-
40, //10 - SDA4/MISO4/RX1
39-
5, //11 - ~SCL0/SCK0
40-
7, //12 - ~MOSI0/CLKOUT
41-
6, //13 - ~SDA0/MISO0/I2SDAT
42-
35, //A14 - ~TX1/I2SDAT/PDMCLK
43-
32, //A15 - ~SCCIO
44-
12, //A16 - ~PDMCLK/TX1
45-
32, //17 - ~SDA2/MISO3/RX1
46-
12, //18 - ~SCL2/SCK2
47-
19, //19 - ~Not exposed, Status LED
48-
48, //20 - Not exposed, TX0
49-
49, //21 - Not exposed, RX0
50-
36, //22 - Not exposed, PDMDATA of Mic
51-
37, //23 - Not exposed, PDMCLK of Mic
52-
AP3_ADC_DIFF0_PAD, //24 - Not a real pad, ADC_DIFF0
53-
AP3_ADC_DIFF1_PAD, //25 - Not a real pad, ADC_DIFF1
54-
AP3_ADC_TEMP_PAD, //26 - Not a real pad, ADC_TEMP
55-
AP3_ADC_DIV3_PAD, //27 - Not a real pad, ADC_DIV3
56-
AP3_ADC_VSS_PAD, //28 - Not a real pad, ADC_VSS
28+
13, //A0 - ~I2SBCLK/RX1
29+
33, //A1 - ~SWO/32kHz
30+
11, //A2 - ~PDMDATA
31+
29, //A3 - ~PDMDATA
32+
18, //4 - ~CMPIN1/SCCIO
33+
31, //A5 - ~SCCCLK
34+
43, //6 - ~SDA3/MISO3/RX1
35+
42, //7 - SCL3/SCK3/TX1
36+
38, //8 - MOSI3/RX1
37+
39, //9 - ~SCL4/SCK4/TX1
38+
40, //10 - SDA4/MISO4/RX1
39+
5, //11 - ~SCL0/SCK0
40+
7, //12 - ~MOSI0/CLKOUT
41+
6, //13 - ~SDA0/MISO0/I2SDAT
42+
35, //A14 - ~TX1/I2SDAT/PDMCLK
43+
32, //A15 - ~SCCIO
44+
12, //A16 - ~PDMCLK/TX1
45+
32, //17 - ~SDA2/MISO3/RX1
46+
12, //18 - ~SCL2/SCK2
47+
19, //19 - ~Not exposed, Status LED
48+
48, //20 - Not exposed, TX0
49+
49, //21 - Not exposed, RX0
50+
36, //22 - Not exposed, PDMDATA of Mic
51+
37, //23 - Not exposed, PDMCLK of Mic
5752
};
5853

5954
// Uart Definitions

variants/SparkFun_BlackBoard_Artemis_Nano/config/variant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424

2525
#include "Arduino.h"
2626

27-
#define AP3_VARIANT_NUM_PINS (29)
27+
#define AP3_VARIANT_NUM_PINS (24)
2828

2929
// Pin map declaration
3030
extern const ap3_gpio_pad_t ap3_variant_pinmap[AP3_VARIANT_NUM_PINS];

0 commit comments

Comments
 (0)