Hi Chris
I cannot completely understand your C code: I am an assembler lover. In any case I cannot see ADC configuration: this is usually done at the program initialization. You have to assign the ADC clock source and prescaler if any in ADCCFG and the physical pin I/O you intend to use for ADC input(s).
With standard device declaration.inc, in assembler this would be something like this:
; Initial declarations
; ADC
ADICLK1m equ %00000000 ; Bus clock
ADIV4m equ %01000000 ; Input Clock /4
ADMODE08m equ %00000000 ; 8-bit mode ADC
; I/O ADC used ports
Pt_Ch_L EQU APCTL2 ; AD11 pin control reg.
Ch_L_in_m EQU %00001011 ; channel AD11 (Ch Left)
Ch_L_in EQU APCTL2_ADPC11 ; pin control
Pt_Ch_R EQU APCTL1 ; AD7 pin control reg.
Ch_R_in_m EQU %00000111 ; channel AD7 (Ch Right)
Ch_R_in EQU APCTL1_ADPC7 ; pin control
; ADC initialization, 20MHz BusClock
; ADCclk= BusClock/4 (5MHz), 8bit ADC, short sample
lda #(ADICLK1m+ADIV4m+ADMODE08m)
sta ADCCFG
bset Ch_R_in,Pt_Ch_R ; assign Ch_R_in to ADC
bset Ch_L_in,Pt_Ch_L ; assign Ch_L_in to ADC
.
.
; ADC conversion on CH_L_in and Ch_R_in
mov #Ch_L_in_m,ADCSC1 ; start sample L
brclr ADCSC1_COCO,ADCSC1,* ; loops here untill conv. end
lda ADCRL ; 8bit result in A
mov #Ch_R_in_m,ADCSC1 ; start sample R
brclr ADCSC1_COCO,ADCSC1,* ; conv. end?
ldx ADCRL ; 8bit result in X
My code snippet does a sequential 8bit conversion on two different channels. I think you too may do an 8bit conversion to read 3 buttons: you do not need 10bit resolution for this, but this is a minor problem, the example would be the same with the addition of reading ADCRH as you correctly do.
You may see there is an ADC and I/O port initial configuration you completely miss. Obviously you do not need the first literal assignments if you use the correct numerical constants in the sequential instructions. Please note you, as in my case, do not need AD1SC2 writing: it is always =0 from CPU reset. You need only to write on ADC1SC1 to start the conversion.
I think this example is so simple you can easily translate in C in the same manner I read your code. Good luck
Salvatore