wonder ADC

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

Hello,

 

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

 

test1:

ldi Temp1, 1

sts ADC0_COMMAND, Temp1 ; start ADC cycle

wait:

lds Temp1, ADC0_COMMAND

sbrc Temp1, 0

rjmp wait

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?

 

Mike

This topic has a solution.
Last Edited: Wed. Mar 14, 2018 - 11:26 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No magic here - you've told the adc to accumulate 8 samples

 

 

ldi Temp1, 0x3

sts ADC0_CTRLB, Temp1

See the datasheet section 30.5.2

 

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

Ok, this feature was new for me. Thanx for the hint.

So, I have to shift three times to the right to get a correct result. perfekt.

 

Mike

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

or set ADC0_CTRLB to 0

 

The feature was new to me as well, so I read the datasheet.