AnsweredAssumed Answered

Hardware averaging of internal temperature sensor gives random values.

Question asked by larsl on Nov 19, 2013
Latest reply on Nov 20, 2013 by larsl



I'm currently running a set of prototypes on the MKL04Z32xxx4 MCU. I've written some code for the ADC in order to be able to read a set of different channels. All used channels are working fine when hardware averaging is turned on, except the internal chip temperature one. The code is set up to use 12-bit measurements, and looks does this after calibration:


ADC0_SC1A |= ADC_SC1_AIEN_MASK; //Enable interrupt
ADC0_CFG1 |= ADC_CFG1_MODE(1); // Set 12 bit mode
//ADC0_SC3  &= (uint8_t)(~ADC_SC3_AVGE_MASK); //Averaging disabled when this line is run.
ADC0_SC3  = ADC_SC3_AVGE_MASK | ADC_SC3_AVGS(0); //4 samples enabled with this.


I can get a proper reading on the chip temp when hardware averaging is turned off (un-commented line above), but not when the code runs as above. I've recorded twenty samples over a period of 20 seconds. As you can see the one with HW averaging acts in a random fashion...


//4 HW samples:

array[0]    uint16_t    1216  

array[1]    uint16_t    941  

array[2]    uint16_t    783  

array[3]    uint16_t    850  

array[4]    uint16_t    822  

array[5]    uint16_t    928  

array[6]    uint16_t    903  

array[7]    uint16_t    980  

array[8]    uint16_t    958  

array[9]    uint16_t    807  

array[10]    uint16_t    717  

array[11]    uint16_t    906  

array[12]    uint16_t    821  

array[13]    uint16_t    793  

array[14]    uint16_t    821  

array[15]    uint16_t    806  

array[16]    uint16_t    1102  

array[17]    uint16_t    822  

array[18]    uint16_t    906  

array[19]    uint16_t    643  


//With averaging disabled:

array[0]    uint16_t    1412  

array[1]    uint16_t    1412  

array[2]    uint16_t    1412  

array[3]    uint16_t    1412  

array[4]    uint16_t    1412  

array[5]    uint16_t    1412  

array[6]    uint16_t    1412  

array[7]    uint16_t    1412  

array[8]    uint16_t    1412  

array[9]    uint16_t    1412  

array[10]    uint16_t    1412  

array[11]    uint16_t    1412  

array[12]    uint16_t    1412  

array[13]    uint16_t    1412  

array[14]    uint16_t    1412  

array[15]    uint16_t    1412  

array[16]    uint16_t    1412  

array[17]    uint16_t    1412  

array[18]    uint16_t    1412  

array[19]    uint16_t    1412


Does anybody know what might be going on? This problem is driving me nuts..