SAMD21 ADC reading internal temp and external pin issue

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I am working with the SAMD21 Xplained Pro PCB.

I am seeing an issue when reading an external pin and then the internal MCU temperature sensor.

 

When I read the external pin 1st the ADC value is correct and the internal temperature is incorrect.

In the opposite case, where I read the internal temperature 1st and then the external pin, the temperature is correct and the analog 

voltage on the external pin is incorrect.

 

The values for the two ADC reads are vary close to each other.

For example:

In the screen capture above, the external ADC pin reads the internal temperature sensor and then battery voltage.

Notice the values are vary close. The battery voltage should be 0 since it is reading a grounded input.

 

The adc_init() function returns an error code 0x1C when reading either input.

Yet, adc_init() does not return an error code the very first time it is run.

 

My project is based upon the examples in the Atmel ADC app note.

The examples run and produce the correct result by themselves however, when combined, there is a conflict.

 

I have tried numerous different variations of my code using adc_reset() and adc_flush().  These functions lock up the MCU

in the default interrupt handlers infinite while loop if placed near the start of the initialization code.

 

My suspicion is that I have an issue with the input multiplexer or the sample buffer.

 

Before I post a boatload of code here, is there some general advice that anyone could offer?

 

Thanks

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I solved the issue.

After looking into the 0x1C code returned by adc_init() I found there was no

specific ADC code for 0x1C

This looks to be a combination of 0x10 (STATUS_CATEGORY_COMMON) ORed with

and 0x0C(STATUS_ERR_DENIED)

This error is returned by adc_init() since adc_init() expects the ADC to be disabled before a call to adc_init() is called.

 

calling adc_disable() before calling adc_init()  seemed to be a workable way to handle whatever the ASF code is doing to set up the mux.

However, as I discovered, this causes a system lockup.

Instead, I make the call to adc_disable() just before returning from each of my ADC sensor read functions.

 

Be very careful where you place the calls to adc_disable(), adc_reset(), and adc_flush() !!

The ADC ASF library is very fragile. You will sling shot yourself into the default interrupt handler infinite while loop if you are not careful.

Below is an example of some of my experimentation with placing these functions in my external voltage sensor read function where they caused a system lockup:

I can now make consecutive ADC channel reads between internal temperature sensor and external pin measurements without any status errors.

Hopefully this will save some folks from experiencing some necessary frustration.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey forrestjon,

 

i have a problem to read out the intern temperature sensor from the atsamd21.

my ADC result is only 0xFF.

could you please show me your code from the NVM control / the function to get the AD Value?

thanks a lot.

 

greets

Manu