How to address ADC and reference on Autonomo


As a new kid on the autonomo-block I can’t find out how to tell my Autonomo to do the following things:

  • The ADC seems to use 10-bit mode by default. How can I tell it to use another resolution (e.g. 12-bits)?
  • How to select taking differential voltage measurements in a single conversion? (so not indirectly by subtracting two samples)? The ADC seems capable of this.
  • How can I change the ADC reference voltage, e.g. from 3.3V (VCC) to the internal 1V?
  • How can I read the SAMD’s internal temperature sensor?

If anyone can hint me what syntax to use so I can get going that’d be great!

Have a look at the wiring_analog.h header file from the SAMD core.

You can find it here (on the Windows platform):

Some of the above is supported. For other operations, you will need to refer to the datasheet and manipulate the registers yourself.

Thanks Gabriel!

So reference selection and resolution are ready mades, great, now I can see what to do in wiring_analog.

I looked a bit deeper for differential measurements and internal temperature and see:

  • Register INPUTCTRL.bit.MUXPOS should be 0x18 to select the temperature sensor. Should work with single ended conversions.
  • CTRLB.bit.DIFFMODE selects single ended or differential measurement. For the latter I also need to select the required negative input using the MUXNEG register. This could be 0x00 thru 0x07 (or 0x18 or 0x19 -not useful here).

So I looked into variant.cpp. I noticed it doesn’t mention ADCchannel17/16/1. Why not? These are valid channels aren’t they?

If I want to be able to select differential measurements, I need to add MUXNEG (and CTRLB.bit.DIFFMODE) somewhere in a file(s). What would be the neat location to add that, inside variant.cpp? Or in multiple locations?
I can see a lot of structure in the files but I’m not sure where I can do my edits to suit my needs because I don’t oversee the structure of it. Maybe I’m aiming too high / asking too much. Any advice you have?

ADC channels 1, 16, & 17 are associated with pins PA03, PA08, & PA09.

These are currently tasked with AREF, VCC_SW, & D0.

The AREF and D0 pins could be setup as dual purpose, however, there are already 14 AIN pins available.

The registers are defined in the CMSIS source files. You do not need to define them yourself. Have a look in: /Users/[USERNAME]/AppData/Local/Arduino15/packages/Arduino/tools/

The naming scheme is pretty consistent and follows a clear pattern with regards to the datasheet. However, I don’t know of any good documentation on it.

You can modify and manipulate those registers directly within your sketch, the source for wiring_analog should give you some examples.

Silly of me not to look at the Sodaq schematic and see what channels 1, 16 and 17 are used for… Clearly I buried myself too deeply in the SAMD datasheet.

Thanks for navigating me to …packages/arduino/tools/CMSIS/Device/Atmel/Samd21/include/component- and instance libs. You really have to know your way around all these directories… pfew, there are a LOT of them.
But I think I should be able now to proceed with the clues you gave, Thanks again!