Hi All,

Can you help to see what I have been doing wrong? I have tried for awhile now but still do not have any success. I am trying to do a continous adc sampling of just the first channel. I then scoop the samples every once in awhile. So far I can get 128 samples, but the numbers do not represent a sine wave I am trying to get. They seem like random numbers, but they do stay within the high and low limits of the adc output. My divider is 0x1F to get the lowest sampling rate. I think my system frequency is 80 MHz. I am also using the samples as unsigned, so I do not do any special offseting. I just use the result as is.

Thank you,

FWFan

void gpio_init(void) {

/* Enable the proper UART pins */

switch (TERMINAL_PORT)

{

case 2:

MCF_GPIO_PUCPAR = 0

| MCF_GPIO_PUCPAR_URXD2_URXD2

| MCF_GPIO_PUCPAR_UTXD2_UTXD2;

break;

case 1:

MCF_GPIO_PUBPAR = 0

| MCF_GPIO_PUBPAR_URXD1_URXD1

| MCF_GPIO_PUBPAR_UTXD1_UTXD1;

break;

case 0:

default:

MCF_GPIO_PUAPAR = 0

| MCF_GPIO_PUAPAR_URXD0_URXD0

| MCF_GPIO_PUAPAR_UTXD0_UTXD0;

}

/* PANPAR: PANPAR0=1, assumes adc primary function */

/* this code dosn't seem to effect the functioning. */

MCF_GPIO_PANPAR |= (unsigned char)0x01;

}

void adc_init(void)

{

/* ### Init_ADC init code */

/* CTRL1: STOP0=1,START0=0,SYNC0=1,EOSIE0=0,ZCIE=0,LLMTIE=0,HLMTIE=0,CHNCFG=0,SMODE=2 */

MCF_ADC_CTRL1 = 0x5002U;

/* CTRL2: DIV=0x1F */

MCF_ADC_CTRL2 = (unsigned short int)((MCF_ADC_CTRL2 & (unsigned short int)~0x87C0) | 0x1FU);

/* ADSDIS: DS7=1,DS6=1,DS5=1,DS4=1,DS3=1,DS2=1,DS1=1,DS0=0 */

MCF_ADC_ADSDIS = 0xfcU/*FeU*/;

/* ADSTAT: CIP0=0,CIP1=0,EOSI1=1,EOSI0=1,ZCI=0,LLMTI=0,HLMTI=0,RDY7=0,RDY6=0,RDY5=0,RDY4=0,RDY3=0,RDY2=0,RDY1=0,RDY0=0 */

MCF_ADC_ADSTAT = 0x1800U;

/* ADLSTAT: HLS7=1,HLS6=1,HLS5=1,HLS4=1,HLS3=1,HLS2=1,HLS1=1,HLS0=1,LLS7=1,LLS6=1,LLS5=1,LLS4=1,LLS3=1,LLS2=1,LLS1=1,LLS0=1 */

MCF_ADC_ADLSTAT = 0xFFFFU;

/* ADZCSTAT: ZCS7=1,ZCS6=1,ZCS5=1,ZCS4=1,ZCS3=1,ZCS2=1,ZCS1=1,ZCS0=1 */

MCF_ADC_ADZCSTAT = 0xFFU;

/* ADLLMT0: LLMT=0 */

MCF_ADC_ADLLMT0 = 0x00U;

/* ADLLMT1: LLMT=0 */

MCF_ADC_ADLLMT1 = 0x00U;

/* ADLLMT2: LLMT=0 */

MCF_ADC_ADLLMT2 = 0x00U;

/* ADLLMT3: LLMT=0 */

MCF_ADC_ADLLMT3 = 0x00U;

/* ADLLMT4: LLMT=0 */

MCF_ADC_ADLLMT4 = 0x00U;

/* ADLLMT5: LLMT=0 */

MCF_ADC_ADLLMT5 = 0x00U;

/* ADLLMT6: LLMT=0 */

MCF_ADC_ADLLMT6 = 0x00U;

/* ADLLMT7: LLMT=0 */

MCF_ADC_ADLLMT7 = 0x00U;

/* ADHLMT0: HLMT=0x0FFF */

MCF_ADC_ADHLMT0 = 0x7FF8U;

/* ADHLMT1: HLMT=0x0FFF */

MCF_ADC_ADHLMT1 = 0x7FF8U;

/* ADHLMT2: HLMT=0x0FFF */

MCF_ADC_ADHLMT2 = 0x7FF8U;

/* ADHLMT3: HLMT=0x0FFF */

MCF_ADC_ADHLMT3 = 0x7FF8U;

/* ADHLMT4: HLMT=0x0FFF */

MCF_ADC_ADHLMT4 = 0x7FF8U;

/* ADHLMT5: HLMT=0x0FFF */

MCF_ADC_ADHLMT5 = 0x7FF8U;

/* ADHLMT6: HLMT=0x0FFF */

MCF_ADC_ADHLMT6 = 0x7FF8U;

/* ADHLMT7: HLMT=0x0FFF */

MCF_ADC_ADHLMT7 = 0x7FF8U;

/* ADOFS0: OFFSET=0 */

MCF_ADC_ADOFS0 = 0x00U;

/* ADOFS1: OFFSET=0 */

MCF_ADC_ADOFS1 = 0x00U;

/* ADOFS2: OFFSET=0 */

MCF_ADC_ADOFS2 = 0x00U;

/* ADOFS3: OFFSET=0 */

MCF_ADC_ADOFS3 = 0x00U;

/* ADOFS4: OFFSET=0 */

MCF_ADC_ADOFS4 = 0x00U;

/* ADOFS5: OFFSET=0 */

MCF_ADC_ADOFS5 = 0x00U;

/* ADOFS6: OFFSET=0 */

MCF_ADC_ADOFS6 = 0x00U;

/* ADOFS7: OFFSET=0 */

MCF_ADC_ADOFS7 = 0x00U;

/* ADZCC: ZCE7=0,ZCE6=0,ZCE5=0,ZCE4=0,ZCE3=0,ZCE2=0,ZCE1=0,ZCE0=0 */

MCF_ADC_ADZCC = 0x00U;

/* ADLST1: SAMPLE3=3,SAMPLE2=2,SAMPLE1=1,SAMPLE0=0 */

MCF_ADC_ADLST1 = 0x3210U;

/* ADLST2: SAMPLE7=7,SAMPLE6=6,SAMPLE5=5,SAMPLE4=4 */

MCF_ADC_ADLST2 = 0x7654U;

/* CAL: SEL_VREFH=0,SEL_VREFL=0 */

MCF_ADC_CAL = 0x00U;

/* POWER: ASB=0,PSTS2=0,PSTS1=0,PSTS0=0,PUDELAY=0x0D,APD=0,PD2=1,PD1=1,PD0=0 */

MCF_ADC_POWER = 0xD6U;

/* CTRL1: STOP0=0,START0=0 */

MCF_ADC_CTRL1 &= (unsigned short int)~0x6000;

MCF_ADC_POWER &= ~(MCF_ADC_POWER_PD0 | MCF_ADC_POWER_PD1 | MCF_ADC_POWER_PD2);

// power-up converter A, converter B and voltage reference circuit

while (MCF_ADC_POWER & (MCF_ADC_POWER_PSTS0 | MCF_ADC_POWER_PSTS1 | MCF_ADC_POWER_PSTS2))

{}; // stay here as long as converter A, B and voltage reference circuit are power-down

}

I start the conversion and let it go forever.

void startAdc(void)

{

/* write 1 to START0 to initiate conversion */

MCF_ADC_CTRL1 |= MCF_ADC_CTRL1_START0/*(uint16)0x2000*/;

}

This is how I scoop the samples.

uint16 *adcArryPtr(void)

{

uint16 i;

static uint16 adcRes[ARRAYSIZE];

for(i=0; i<ARRAYSIZE; i++){

*(adcRes+i) = (uint16)MCF_ADC_ADRSLT0;

}

return adcRes;

}

This is how I set up and initialize the adc.

void __initialize_hardware(void)

{

asm

{

/* Initialize IPSBAR */

move.l #__IPSBAR,d0

andi.l #0xC0000000,d0 // need to mask

add.l #0x1,d0

move.l d0,0x40000000

/* Initialize FLASHBAR */

move.l #__FLASHBAR,d0

andi.l #0xFFF80000,d0 // need to mask

add.l #0x61,d0

movec d0,FLASHBAR

}

pll_init();

gpio_init();

adc_init();

allow_interrupts();

initialize_exceptions();

}

Hi,

If you need to see samples as a sine-wave you must start

the ADC at regular time intervals = sine_period/Number_of_samples

and stop afer the aquisition of all samples and then process them.

Depending on application, you must take into account also the need

to use an anti-aliasing filter.

Regards,

ipa