I'm having a problem getting an ADC reading, in a transient case. I'm probably missing something obvious.. :-P The processor has recently come out of reset, so I'm trying to assume nothing. Ints are disabled, this is a test that I have to make before the main system comes up and the normal ADC routines would work, which are interrupt driven and free running. The only discrepancy I see with the data sheet is that they call out the register as ADCSRA, but the M128def.inc file I have has no such callout, they used ADCSR. I want to read a voltage on channel 2, with the internal 2.5V reference. I set bit 2 of port F as input, by: lds TEMP,DDRF ;There are other pins set that I don't want to bother andi TEMP,0xFB ;Set bit 2 (ADC channel 2) to input sts DDRF,TEMP ; Then I wait for any pending conversion to complete: Volt_First: sbic ADCSR,ADSC ;Loop here till ADSC is zero rjmp Volt_First ;This makes sure any pending conversion finishes. Then I set up to read channel 2 Volt_Test_Setup: ldi TEMP,0xE2 ;11XXXXXX Internal 2.5V Vref ;XX1XXXXX Left adjust result into ADCH out ADMUX,TEMP ;XXX00010 Select battery input channel ldi TEMP,0x83 ;1XXXXXXX Enable ADC ;X0XXXXXX Don't Start Conversion yet ;XX0XXXXX Don't freerun ;XXX0XXXX Interrupt flag (not needed) ;XXXX0XXX Int disabled out ADCSR,TEMP ;XXXXX111 125 kHz clock from 16 MHz Xtal ldi TEMP,0xFF ; VT_Delay: dec TEMP ;Delay, before starting. brne VT_Delay ;15uS. sbi ADCSR,ADSC ;Start the ADC So now, I wait till this conversion completes, discard it, and run another. Volt_First_Wait: sbic ADCSR,ADSC ;Atmel says to toss the first conversion result. rjmp Volt_First_Wait ;So just wait till it's done. Volt_Test_Again: sbi ADCSR,ADSC ;ReStart the ADC Volt_Wait: sbic ADCSR,ADSC ;Loop here till ADSC is zero rjmp Volt_Wait ; IN TEMP,ADCH ;GET 8 BIT RESULT I always get to this point, indicating that I am indeed talking to the ADC, since the conversion complete bit does clear. At this point, I only ever get 0x00 in ACCUM. If I compare to anything >0, then I just loop here forever. Start_Volt_Test: cpi TEMP,162 ;Battery should be greater than 6.0V brcs Volt_Test_Again ;If not, just wait till that happens.
Message
M128 ADC problem
2003-12-30 by David VanHorn
Attachments
- No local attachments were found for this message.