Mark, I posted up the question on the Freescale site and got the following reply which didn't work:
I modified it as follows, but it still didn't work even when the global optimization was lowered to 2.
#pragma opt_loop_invariants off
// Wait for converter A power up to complete
while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS0)
;
0001274C: 4A80 tst.l d0
0001274E: 66FC bne.s fnInit_adc+0x44 (0x1274c); 0x0001274c
// Wait for converter B power up to complete
while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS1)
#pragma opt_loop_invariants on
return;
00012750: 028100000800 andi.l #0x800,d1
00012756: 66000104 bne.w fnInit_adc+0x14a (0x1285c); 0x0001285c
Here's a copy of my ADC task that ini's the ADC and reads it every
second when the task wakes up. It works with the M52233DEMO
using the pot on AN0. It operates in the "Triggered parallel mode", scanning all 8 inputs when issued a START0 then stopping.
void fnADC(TTASKTABLE *ptrTaskTable) // ADC called regularly
{
MCF_ADC_CTRL1 = START0; // Start the scan
while (ADC_ADSTAT & (CIP0 | CIP1)) {} // Wait for any active ADC conversion to complete
usADC_result[0] = ADC_ADRSLT0 >> 3; // Save the present ADC values (note the order!!)
usADC_result[1] = ADC_ADRSLT1 >> 3;
usADC_result[2] = ADC_ADRSLT2 >> 3;
usADC_result[3] = ADC_ADRSLT3 >> 3;
usADC_result[4] = ADC_ADRSLT4 >> 3;
usADC_result[5] = ADC_ADRSLT5 >> 3;
usADC_result[6] = ADC_ADRSLT6 >> 3;
usADC_result[7] = ADC_ADRSLT7 >> 3;
fnDebugMsg("A0=");
fnDebugDec(usADC_result[0],0,0);
fnDebugMsg(" A1=");
fnDebugDec(usADC_result[1],0,0);
fnDebugMsg(" A2=");
fnDebugDec(usADC_result[2],0,0);
fnDebugMsg(" A3=");
fnDebugDec(usADC_result[3],0,0);
fnDebugMsg(" A4=");
fnDebugDec(usADC_result[4],0,0);
fnDebugMsg(" A5=");
fnDebugDec(usADC_result[5],0,0);
fnDebugMsg(" A6=");
fnDebugDec(usADC_result[6],0,0);
fnDebugMsg(" A7=");
fnDebugDec(usADC_result[7],0,0);
fnDebugMsg("\r\n");
}
/*********************************************************************
* init_adc - Analog-to-Digital Converter (ADC) *
**********************************************************************/
void fnInit_adc (void)
{
// Scan mode = Triggered parallel, converters A and B run simultaneously
// ADC clock frequency = 5.00 MHz
// Voltage reference supplied by VDDA and VSSA
// All ADC interrupts disabled
//
// Sample list for converter A:
// Sample 0 : AN0
// Low limit = $000, High limit = $FFF, Offset = $000
// Sample 1 : AN1
// Low limit = $000, High limit = $FFF, Offset = $000
// Sample 2 : AN2
// Low limit = $000, High limit = $FFF, Offset = $000
// Sample 3 : AN3
// Low limit = $000, High limit = $FFF, Offset = $000
//
// Sample list for converter B:
// Sample 4 : AN4
// Low limit = $000, High limit = $FFF, Offset = $000
// Sample 5 : AN5
// Low limit = $000, High limit = $FFF, Offset = $000
// Sample 6 : AN6
// Low limit = $000, High limit = $FFF, Offset = $000
// Sample 7 : AN7
// Low limit = $000, High limit = $FFF, Offset = $000
// Initialise LOLIM, HILIM and OFFST registers of enabled channels:
MCF_ADC_ADLLMT0 = 0;
MCF_ADC_ADHLMT0 = MCF_ADC_ADHLMT_HLMT(0xfff);
MCF_ADC_ADOFS0 = 0;
MCF_ADC_ADLLMT1 = 0;
MCF_ADC_ADHLMT1 = MCF_ADC_ADHLMT_HLMT(0xfff);
MCF_ADC_ADOFS1 = 0;
MCF_ADC_ADLLMT2 = 0;
MCF_ADC_ADHLMT2 = MCF_ADC_ADHLMT_HLMT(0xfff);
MCF_ADC_ADOFS2 = 0;
MCF_ADC_ADLLMT3 = 0;
MCF_ADC_ADHLMT3 = MCF_ADC_ADHLMT_HLMT(0xfff);
MCF_ADC_ADOFS3 = 0;
MCF_ADC_ADLLMT4 = 0;
MCF_ADC_ADHLMT4 = MCF_ADC_ADHLMT_HLMT(0xfff);
MCF_ADC_ADOFS4 = 0;
MCF_ADC_ADLLMT5 = 0;
MCF_ADC_ADHLMT5 = MCF_ADC_ADHLMT_HLMT(0xfff);
MCF_ADC_ADOFS5 = 0;
MCF_ADC_ADLLMT6 = 0;
MCF_ADC_ADHLMT6 = MCF_ADC_ADHLMT_HLMT(0xfff);
MCF_ADC_ADOFS6 = 0;
MCF_ADC_ADLLMT7 = 0;
MCF_ADC_ADHLMT7 = MCF_ADC_ADHLMT_HLMT(0xfff);
MCF_ADC_ADOFS7 = 0;
// Initialise ADC
MCF_ADC_ADZCC = 0;
MCF_ADC_ADLST1 = MCF_ADC_ADLST1_SAMPLE3(0x3) |
MCF_ADC_ADLST1_SAMPLE2(0x2) |
MCF_ADC_ADLST1_SAMPLE1(0x1);
MCF_ADC_ADLST2 = MCF_ADC_ADLST2_SAMPLE7(0x7) |
MCF_ADC_ADLST2_SAMPLE6(0x6) |
MCF_ADC_ADLST2_SAMPLE5(0x5) |
MCF_ADC_ADLST2_SAMPLE4(0x4);
MCF_ADC_ADSDIS = 0;
MCF_ADC_CAL = 0;
MCF_ADC_CTRL1 = MCF_ADC_CTRL1_STOP0 |
MCF_ADC_CTRL1_SMODE(0x5);
MCF_ADC_CTRL2 = MCF_ADC_CTRL2_STOP1 |
MCF_ADC_CTRL2_SIMULT |
MCF_ADC_CTRL2_DIV(0x2);
// Power up ADC converter(s) in use
MCF_ADC_POWER = MCF_ADC_POWER_PUDELAY(0xd) |
MCF_ADC_POWER_PD2;
// Wait for converter A power up to complete
while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS0)
;
// Wait for converter B power up to complete
while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS1)
;
PANPAR = 0xff; // Enable all ports as ADC inputs
}