Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

ATMega1284p ADC running before "Start Conversion"?

ATMega1284p ADC running before "Start Conversion"?

2012-11-05 by Chuck Hackett

In debugging some ADC code I discovered that I had never set the ADSC bit in
ADCSRA but I was still getting conversions.

I was turning ADEN on (when I intended the conversion to start after setting
ADCMUX) and off (in the interrupt handler) but (accidently) I had never set
ADSC.


For the ADEN (ADC Enable) bit the manual says:

"Writing this bit to one enables the ADC. By writing it to zero, the ADC is
turned off. Turning the
ADC off while a conversion is in progress, will terminate this conversion."

Note that it does not say anything about setting it to 1 causing a
conversion to start.


For the ADSC (ADC Start Conversion) bit the manual says:

"In Single Conversion mode, write this bit to one to start each conversion.
In Free Running Mode,
write this bit to one to start the first conversion."

If the ADSC bit starts the conversion (I'm in 'Single Conversion' mode) I
don't understand why any conversion started and I got an interrupt (I
accidently never set the ADSC bit).  I would have expected that I never
would have gotten an interrupt ...

I am obviously missing something ... Can anyone tell me where I'm going
wrong?

My intent is to:

1) start a sequence of conversions from interrupt context (a timer
interrupt) by setting ADMUX(MUX) to the appropriate channel and starting a
conversion
2) Upon interrupt: Retrieve the data from ADCL/ADCH, if I have more channels
to sample (from a list), update ADMUX(MUX) and start conversi0on and return
from interrupt.  If no more channels, disable the ADC (0 -> ADEN) and return
from interrupt.
3) start again at #1 upon next timer interrupt ...

If someone has example code that does such a sequence (i.e.: interrupt
driven 'Single Conversion' mode sampling non-contigious channels) I could
maybe use an example to check mine against.
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

RE: [AVR-Chat] ATMega1284p ADC running before "Start Conversion"?

2012-11-05 by Chuck Hackett

> From: Chuck Hackett
> ....
> If the ADSC bit starts the conversion (I'm in 'Single Conversion' mode) I
don't
> understand why any conversion started and I got an interrupt (I accidently
> never set the ADSC bit).  I would have expected that I never would have
> gotten an interrupt ...
> ....

To answer my own email ...

It turns out that the ADC was started in "noise canceling mode" when my
"idle loop" executed a "sleep()" statement (sleep mode was set to "Sleep
Mode = Idle" and ADEN and ADIE were set to 1).  

So, I think you need to disable the ADC if you don't want the ADC conversion
to start when sleep mode "Idle" or "ADCNRM" is used ...
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Re: [AVR-Chat] ATMega1284p ADC running before "Start Conversion"?

2012-11-06 by David VanHorn

On Mon, Nov 5, 2012 at 10:20 AM, Chuck Hackett <egroupscdh@up844.us> wrote:
> In debugging some ADC code I discovered that I had never set the ADSC bit in
> ADCSRA but I was still getting conversions.

Most likely, something is writing that bit.
I've never seen the ADC in any AVR just take off on it's own.
Check your source for writes to that address, both in I/O and SRAM space.

RE: [AVR-Chat] ATMega1284p ADC running before "Start Conversion"?

2012-11-06 by Chuck Hackett

> From: David VanHorn
> ....
> Most likely, something is writing that bit.
> I've never seen the ADC in any AVR just take off on it's own.
> Check your source for writes to that address, both in I/O and SRAM space.
> ....

Problem was caused by going into sleep mode (sleep mode = Idle) while ADEN
was set.  As I later found described in the data sheet this (also) causes a
conversion to start (noise reduction mode).
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Re: [AVR-Chat] ATMega1284p ADC running before "Start Conversion"?

2012-11-06 by David VanHorn

Ah!  :)  Glad you found it.  Sleep mode can be entertaining.
Show quoted textHide quoted text
On Mon, Nov 5, 2012 at 7:06 PM, Chuck Hackett <egroupscdh@up844.us> wrote:
>> From: David VanHorn
>> ....
>> Most likely, something is writing that bit.
>> I've never seen the ADC in any AVR just take off on it's own.
>> Check your source for writes to that address, both in I/O and SRAM space.
>> ....
>
> Problem was caused by going into sleep mode (sleep mode = Idle) while ADEN
> was set.  As I later found described in the data sheet this (also) causes a
> conversion to start (noise reduction mode).
>
> Cheers,
>
> Chuck Hackett
> "Good judgment comes from experience, experience comes from bad judgment"
> 7.5" gauge Union Pacific Northern (4-8-4) 844
> http://www.whitetrout.net/Chuck
>
>
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.