ATtiny1616 Temperature measurement on ADC1

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

Hi all,

 

I can't for the life of me figure out why this isn't working but break-point always shows RES= 0-4. Anything obvious?
 

VREF.CTRLC = VREF_ADC1REFSEL_1V1_gc;

ADC1.CALIB = ADC_DUTYCYC_DUTY25_gc;
ADC1.CTRLC = ADC_PRESC_DIV4_gc | ADC_REFSEL_INTREF_gc | ADC_SAMPCAP_bm; // 62.5KHz
ADC1.CTRLD = ADC_INITDLY_DLY256_gc;
ADC1.DBGCTRL = ADC_DBGRUN_bm;
ADC1.EVCTRL = ADC_STARTEI_bm; // Auto trigger
ADC1.SAMPCTRL = 0x1F;
ADC1.MUXPOS =  ADC_MUXPOS_TEMPSENSE_gc;
ADC1.CTRLA = ADC_RUNSTBY_bm | ADC_RESSEL_10BIT_gc | ADC_ENABLE_bm;

// the event is a rtc trigger at 2Hz and will be picked up by the main loop which on the intflag being set will run the following

inline void TEMPERATURE_Adc (void) {

    int8_t sigrow_offset = SIGROW.TEMPSENSE1;
    uint8_t sigrow_gain = SIGROW.TEMPSENSE0;

    uint16_t read = ADC1.RES;
    
    uint32_t work = read - sigrow_offset;
    work *= sigrow_gain; // Result might overflow 16 bit variable (10bit+8bit)
    work += 0x80;  // Add 1/2 to get correct rounding on division below

    temperature.kelvin = work >> 8; // into kelvin
    temperature.warn = temperature.warn 
            ? 
        (temperature.kelvin < TEMPERATURE_WARN_KELVIN - TEMPERATURE_WARN_KELVIN_HYSTERESIS? 0:1)
            :
        (temperature.kelvin > TEMPERATURE_WARN_KELVIN + TEMPERATURE_WARN_KELVIN_HYSTERESIS? 1:0);
}

 

This topic has a solution.
Last Edited: Tue. May 24, 2022 - 11:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've swapped to ADC0 and all is well. Nothing in the errata about it.

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

snoopy33 wrote:
 I've swapped to ADC0 and all is well. Nothing in the errata about it. 

 

It is not an erratum.

 

The truth is more important than the facts.

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

Read the MUXPOS register description in the datasheet, specifically the TEMPSENSE description.

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

What about it?

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you read the TEMPSENSE description and not see it, or not read it at all?

 

I didn't think I needed to spell it out because it was so obvious, but to save time- the TEMPSENSE description specifies that adc0 reads the temperature sensor, adc1 reads dac1.

 

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

I didn't realise my datasheet is from 2019, the 0x1E is missing from the MUXPOS, I just assumed it was added later and both could read it.

Well that explains it then! Cheers!