ATTINY1614/16/17: ADC-Pins cannot be read with ADC1?

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

I'm just doing the experience that same analog-pin configuration in ADC1_MUXPOS results in different, enigmatic reading in ADC1_RES compared with ADC0/ADC0_MUXPOS/ADC0_RES... What could be the reason for this?

This topic has a solution.
Last Edited: Mon. Mar 12, 2018 - 07:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried ADC0 - AIN4 and ADC1 - AIN0 together with ATTINY1616.
They both see the same pin. (It is Pin2 in 20pin SOIC)
Using two 1Kohm and entering half of VDD, both got the correct result.

 

#include <avr/io.h>
#include <avr/interrupt.h>

static volatile uint16_t adc_res0, adc_res1;

int main(void){
    for (uint8_t i = 0; i < 8; i++) {
        *((uint8_t *)&PORTA.PIN0CTRL + i) = PORT_ISC_INPUT_DISABLE_gc;
        *((uint8_t *)&PORTB.PIN0CTRL + i) = PORT_ISC_INPUT_DISABLE_gc;
        *((uint8_t *)&PORTC.PIN0CTRL + i) = PORT_ISC_INPUT_DISABLE_gc;
    }

//	ADC_initialization();------------------------------------------------------------------------------
    adc_res0 = adc_res1 = 0;

    ADC0.CTRLA = ADC_ENABLE_bm;
    ADC0.CTRLC = ADC_REFSEL_VDDREF_gc | ADC_PRESC_DIV256_gc;
    ADC0.MUXPOS = ADC_MUXPOS_AIN4_gc;

    ADC1.CTRLA = ADC_ENABLE_bm;
    ADC1.CTRLC = ADC_REFSEL_VDDREF_gc | ADC_PRESC_DIV256_gc;
    ADC1.MUXPOS = ADC_MUXPOS_AIN0_gc;

    while (1) {
        ADC0.COMMAND = ADC_STCONV_bm;
        ADC1.COMMAND = ADC_STCONV_bm;
        while (!(ADC0.INTFLAGS & ADC1.INTFLAGS & ADC_RESRDY_bm));
        cli();
        adc_res0 = ADC0.RES;
        adc_res1 = ADC1.RES;
        sei();
    }
}

 

If your results are still strange please upload circuit and code.

 

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

The puzzle solution: I overlooked that assignment PINx <–> AINx=Muxcode not the same for ADC0/1.
Thanks Kabasan for your note that point me to this knowledge I not expected.