ADC is always in continuous mode

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

Hello freaks,
from data-sheets i figured out that if i enable ADC by ADEN, it shouldn't start any conversion without ADSC.
But for this moment it seems like that's always in continuous mode even if I never touch ADSC flag.

Info:
Atmega16 @ 16MHz (but exactly same behavior i have observed also on ATMEGA644P)
Serial over FTDI @ 250kbps (tested and functional)
Timer 0 interrupts every 1/62.5second -> toggling output pin PD6 (also tested and functional - output frequency about 31,119Hz)
ADC interrupt just toggles PD7 (for testing purpose)
Interrupt handlers are functional, no unexpected resets.

Original Goal: timer 0 compare triggering ADC conversion. However ADC is always free running -
for example if i set:

  ADMUX = _BV(REFS1) | _BV(REFS0);
  SFIOR = 3 << ADTS0; // timer 0 compare match trigger
  ADCSRA= _BV(ADEN) | _BV(ADIE) |/* _BV(ADATE) |*/ 7; // prescaler /128, enable ADC + interrupt

I can measure on PD7 (toggled by ADC interrupt) frequency about 4,46kHz
If i set ADC prescaler to dividing by 32 -> about 15,622kHz

If i enable ADATE it's still free running (ADC interrupt is far more faster than Timer0)

Am I such bad in reading of data-sheet? Did I miss something?

Attachment(s): 

This topic has a solution.

Computers don't make errors - What they do they do on purpose.

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

What do you have for an ADC ISR? If you're not actually ready ADC in the ISR to clear ADIF, then it will keep calling the ISR forever. As to why it would trigger that first interrupt, not sure.

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

Seems not possible. Datasheet didn't mention anything about clearing ADIF by reading ADC:

Quote:
ADIF is cleared by hardware when executing the corresponding interrupt handling vector.

And i think if ADIF stays set after ISR, AD prescaler couldn't change toggling frequency from ADC ISR
(and of course it shouldn't even start first conversion if i don't set ADSC and ADATE is off)

Thanks anyway for reply

Computers don't make errors - What they do they do on purpose.

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

Quote:
If you're not actually ready ADC in the ISR to clear ADIF, then it will keep calling the ISR forever.
Not true. The ADIF flag is cleared when the ISR is called, it has nothing to do with reading the ADC value.

Regards,
Steve A.

The Board helps those that help themselves.

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

True, I meant to ask if there was an ISR, period. What's in the ISr?

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

dksmall - ISR is just this:

ISR(ADC_vect) {
  PORTD ^= _BV(PD7);
  //ADCv = ADC;  
}

(whole code is attached in my first post)

Computers don't make errors - What they do they do on purpose.

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

Same behavior is observed also on atmega2560 (arduino mega 2560)
ie. set prescaler to 128, ADMUX, set just flags ADEN + ADIF -> AD is working in free running mode even without ADSC or ADATE explicitly enabled

without setting ADIF i can read correct values of ADC (just ADEN was set, nothing else)

Computers don't make errors - What they do they do on purpose.

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

Quote:

is working in free running mode even without ADSC or ADATE explicitly enabled

If ADSC is never set nothing ever happens (I guess reading ADCH/L at this stage probably returns 0x00 or 0xFF?). If you are getting "real" readings it suggests that something somewhere else is inadvertently writing to ADCSRA.

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

clawson wrote:
Quote:

is working in free running mode even without ADSC or ADATE explicitly enabled

If ADSC is never set nothing ever happens (I guess reading ADCH/L at this stage probably returns 0x00 or 0xFF?). If you are getting "real" readings it suggests that something somewhere else is inadvertently writing to ADCSRA.

Well, if .lss file shows corresponding assembler correctly, I can't imagine where is improperly set ADSC (and without ADATE it shouldn't measure continuously - which is)

(maybe someone else could try test this behaviour... on m16, m644p, m2560 - ie. if ADEN + ADIF fires interrupts like in free running mode without setting any other flags)

Computers don't make errors - What they do they do on purpose.

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

Is there a sleep in your application?

If the ADC is enabled then a conversion can be triggered by going to sleep (depending on the sleep mode)

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

Quote:

Is there a sleep in your application?

If the ADC is enabled then a conversion can be triggered by going to sleep (depending on the sleep mode)


Yes there is and this is exactly what I was seeing in the simulator. The RETI at the end of the ADC ISR returned to the instruction after SLEEP.

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

efc wrote:
Is there a sleep in your application?

If the ADC is enabled then a conversion can be triggered by going to sleep (depending on the sleep mode)

I'll check this "feature"... I'm using sleep almost allways...

Computers don't make errors - What they do they do on purpose.