I doing my first steps with the ADC in an ATTiny816 and I am fighting with total erratic readings from this ADC. Perhaps there is someone out there to enlight me. :)
So, the datasheet says I have one 10-bit ADC in my 816. Now I am doing tests with a simple assembler routine and I got results between 0 and 0x1FFF. But this would mean I have a 13-bit ADC in front of me ?!
I checked against GND and got 0x0000 - OK. I checked MUXPORT against vref and got 0x1FFE. Pretty close to 0x1FFF :) I checked a variable signal on a real port between 0 and 4,3V and got results between 0 - 1FFF. How can this be ????
This is my program I tested:
ldi Temp1, 0b0011_0001
sts VREF_CTRLA, Temp1 ; set DAC work range to 0 - 1,1V / set ADC reference voltage to 4,3V
;**** init ADC
ldi Temp1, 0x3
sts ADC0_CTRLB, Temp1
ldi Temp1, 0b0000_0010
sts ADC0_CTRLC, Temp1
ldi Temp1, 0b0100_0000
sts ADC0_CTRLD, Temp1
ldi Temp1, 0b0000_1111
sts ADC0_SAMPCTRL, Temp1
ldi Temp1, 0x08
sts ADC0_MUXPOS, Temp1 ; tested against GND = 0x1F, against Vref = 0x1D and a signal on AIN8
ldi Temp1, 1
sts ADC0_CTRLA, Temp1 ; enable ADC
ldi Temp1, 1
sts ADC0_COMMAND, Temp1 ; start ADC cycle
lds Temp1, ADC0_COMMAND
sbrc Temp1, 0
lds Temp1, ADC0_RESL
lds Temp2, ADC0_RESH ; input ADC value
I am writing the results into the eeprom and read it out. And the results are between 0-1FFF. Stable and clean.
Anyone an idea if I have a magical ADC in my Tiny816?