ATtiny461 ADC problem

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

I found a problem that ATtiny461 ADC cannot quickly switch from single ended input to differential for single conversion ADC mode with ADIE=1 for update ADMUX and create next conversions. In this way after switch to diff signal next conversion will be corrupt and (maybe) must be skipped. The following code address this problem:

#define AS1set BIN(10000011)//single ended signal
#define AS2set BIN(10010010)//diff signal
#define AS3set BIN(10000010)//single ended signal
__C_task void main (void) {
.
.
ADMUX = AS2set;
ADCSRA = BIN(10011101); // ADC 250kHz Fosc=8MHz,ADIE=1
ADCSRB = BIN(00000000);
__enable_interrupt();
SETBIT(ADCSRA,ADSC);//start 1st conversion
.
.
}

// ADC Conversion Complete
#pragma vector = ADC_vect
__interrupt void ADC_COMPLITE(void) {
  switch(ADMUX){
    case AS1set: ADMUX=AS2set;AS1value=ADC;break;
    case AS2set: ADMUX=AS3set;AS2value=ADC;break;
    case AS3set: ADMUX=AS1set;AS3value=ADC;break;    
  }
  SETBIT(ADCSRA,ADSC};
}

For this code AS2value (diff signal) always reads as zero and this is not correct for input pins measurement.
Is it a known issue or my code isn't correct?

IV

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

Not unexpected, in my experience with the AVR ADC. Although more "strict" than the datasheet notations, my rule is to discard the results of the first conversion after starting the A/D, changing reference, re-configuring, or waking from sleep.

The '461 datasheet doesn't give much guidance, does it? Try pulling up a recent datasheet such as Mega164P, and you find more details on what I believe is your situation:

Quote:
Special care should be taken when changing differential channels. Once a differential channel has been selected, the gain stage may take as much as 125 μs to stabilize to the new value. Thus conversions should not be started within the first 125 μs after selecting a new differential channel. Alternatively, conversion results obtained within this period should be discarded.

The same settling time should be observed for the first differential conversion after changing ADC reference (by changing the REFS1:0 bits in ADMUX).

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

You are measuring:
* ADC3
* (ADC4 - ADC3) x 20
* ADC2
all in unipolar mode.

if now ADC3 >= ADC4 then you get result = 0x000
(corrected: was "<=")

What voltages can you measure with a voltmeter at:
* ADC2
* ADC3
* ADC4?

Klaus
********************************
Look at: www.megausb.de (German)
********************************

Last Edited: Fri. Oct 12, 2007 - 07:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Digital voltmeter give the following:
ADC2 = 0.922V;
ADC3 = 0.539V;
ADC4 = 0.558V;
Now:
ADC4-ADC3=19mV; OPAMPoutput=(19*20)=380mV;ADCout=354;
But really with code above ADC always reads as zero.
Then I update my code and the 2nd conversion for AS2value give me correct result. Maybe, theuschright?

IV

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

Quote:

Maybe, theuschright?

theusch >>always<< right. :lol:

Certain AVR models do have special features, such as the high-speed PWM on your model. In doing apps with many AVR models over the years, though, to a large extent an AVR "feels like" an AVR. Subsystems such as timers & USARTs & SPI & ADC pretty much work the same across models.

Thus I'd think that the '164P info would in general apply to your model as well. You could try an experiment by trying different time delays as the note suggested to see if 125us is really the magic number for your model. Or whether the simple delay makes any difference at all, and you really have to discard that conversion result.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Quote:
theusch >>always<< right.

Yes, again and again. I can´t stand it any longer. ;-)

Klaus
********************************
Look at: www.megausb.de (German)
********************************