SAMD21 - with several parallel ADC channels (e.g. A0 and A1)

Continuing the discussion from Addressing SAM D21 ADC:

Not sure how to setup several ADC channels in parallel (e.g. A0 and A1)?

If you're trying to use MartinL's high-res code, you'd change this line:


But the mapping from Analog pins to MUXPOS values is a bit ... odd.
See Section 7 of the datasheet "I/O Multiplexing and Considerations."
For an Arduino Zero, it looks like A0..A5 are [0, 2, 3, 4, 5, 10]
(See the appropriate section of the variant.cpp file
(and you should be able to look up the MUX channel from a pin number with

  if (pin < A0) {
    pin += A0;
  ADC->INPUTCTRL.bit.MUXPOS = g_APinDescription[pin].ulADCChannelNumber;

Thanks for reply! Does that mean that I have to go through the whole setup code every time I change the channel or only have to change the muxpos?

I’m not sure. Almost certainly NOT the whole initialization, but perhaps more than just the muxpos. (In particular, I think some ADCs can require an extra bit of waiting after changing the muxpos, or two conversions, or something like that, to make sure the s&h settles.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.