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