Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

analogRead(8) through analogRead(15) on GCM4
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

analogRead(8) through analogRead(15) on GCM4

by westfw on Fri Jul 17, 2020 4:20 am

How does analogRead() work on Grand Central with analog pin numbers greater than 7?
The code reads:
Code: Select all | TOGGLE FULL SIZE
uint32_t analogRead(uint32_t pin)
{
  uint32_t valueRead = 0;

#if defined(PIN_A6)
  if (pin == 6) {
    pin = PIN_A6;
  } else
#endif
#if defined(PIN_A7)
  if (pin == 7) {
    pin = PIN_A7;
  } else
#endif
  if (pin <= 5) {
    pin += A0;
  }

  pinPeripheral(pin, PIO_ANALOG);
//etc

But don't analog8 through analog15 map to digital pins LOWER than analog0? (and discontinuous enough from analog0..analog5 that it wouldn't work the other way, either.)

There's a analogInputToDigitalPin() macro in variant.h, but it's not used anywhere in the core, and I didn't think users were required to use it in sketches with analogRead()

westfw
 
Posts: 1720
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: analogRead(8) through analogRead(15) on GCM4

by westfw on Fri Jul 17, 2020 4:34 am

I'm working on an "explorer" for the internal state of the SAMD chips, and I noticed the possible analogRead() problem when my code did a bad job of translating digital pin numbers back to analog pins, while looking at the PMUX code. (I've attached the whole sketch, but note that it's not really ready for prime time!)

If I add simple code to read all of the analog pins, I see it setting "weird" pins to the ADC mux setting...
Code: Select all | TOGGLE FULL SIZE
  for (int i = 0; i < 16; i++) {
    sprintf(buffer, "Analog%d = %d\n", i, analogRead(i));
    Serial.print(buffer);SAMD_Explorer
  }



Code: Select all | TOGGLE FULL SIZE
SAMD Explorer> pins
0       PMUX(2) SERCOM
1       PMUX(2) SERCOM
2       GPIO I
3       GPIO I
4       GPIO I
5       GPIO I
6       GPIO I
7       GPIO I
8       PMUX(1) ADC              ?????
9       PMUX(1) ADC
10      PMUX(1) ADC
11      PMUX(1) ADC
12      PMUX(1) ADC
13      PMUX(1) ADC
14      PMUX(1) ADC
15      PMUX(1) ADC
16      GPIO I
17      GPIO I
18      GPIO I
19      GPIO I
20      GPIO I
21      GPIO I
22      GPIO I
23      GPIO I
24      GPIO I
25      GPIO I
26      GPIO I
27      GPIO I
28      GPIO I
29      GPIO I
30      GPIO I
31      GPIO I
32      GPIO I
33      GPIO I
34      GPIO I
35      GPIO I
36      GPIO I
37      GPIO I
38      GPIO I
39      GPIO I
40      GPIO I
41      GPIO I
42      GPIO I
43      GPIO I
44      GPIO I
45      GPIO I
46      GPIO I
47      GPIO I
48      GPIO I
49      GPIO I
50      GPIO I
51      GPIO I
52      GPIO I
53      GPIO I
54 (A-13) GPIO I            "Extra Analog" pins 54-61 NOT in ADC mode.
55 (A-12) GPIO I
56 (A-11) GPIO I
57 (A-10) GPIO I
58 (A-9) GPIO I
59 (A-8) GPIO I
60 (A-7) GPIO I
61 (A-6) GPIO I
62      GPIO I
63      GPIO I
64      GPIO I
65      GPIO I
66      GPIO I
67 (A0) PMUX(1) ADC             These are Analog0..7, so they're OK?
68 (A1) PMUX(1) ADC
69 (A2) PMUX(1) ADC
70 (A3) PMUX(1) ADC
71 (A4) PMUX(1) ADC
72 (A5) PMUX(1) ADC
73 (A6) PMUX(1) ADC
74 (A7) PMUX(1) ADC
75      GPIO O
76      GPIO O
77      GPIO I
78      PMUX(7) AC/GCLK
79      PMUX(7) AC/GCLK
80      GPIO I
81      GPIO I
82      GPIO I
83      GPIO I
84 (A17) GPIO I
85 (A18) PMUX(1) ADC      DAC pins in analog mode (I guess that A0/A1, so this is OK.)
86 (A19) PMUX(1) ADC
87      PMUX(1) ADC           ?????????  Alias for pin13...
Attachments
SAMD_Explorer.zip
(5.76 KiB) Not downloaded yet

westfw
 
Posts: 1720
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: analogRead(8) through analogRead(15) on GCM4

by westfw on Fri Jul 17, 2020 10:42 pm


westfw
 
Posts: 1720
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Please be positive and constructive with your questions and comments.