How to initialize the ADC into continuous conversion mode?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to initialize the ADC into continuous conversion mode?

2,605 Views
thulzh
Contributor III

I have met some problem when using ADC12B_LBA_V1 module on the MC9S12ZVC192(64 pin).

The hardware I use is the NXP official DEVKIT-S12ZVC board.

I want to use the ADC module in continuous conversion mode like the reference manual says:

>>

Applications that only need to continuously convert a list of channels, without the need for timing control

or the ability to perform different sequences of conversions (grouped number of different channels to

convert) can make use of the following simple setup:

• “Trigger Mode” configuration

• Single buffer CSL

• Depending on data transfer rate either use single or double buffer RVL configuration

• Define a list of conversion commands which only contains the “End Of List” command with automatic wrap to top of CSL

After finishing the configuration and enabling the ADC an initial Restart Event is sufficient to launch the

continuous conversion until next device reset or low power mode

>>

so I initial the ADC module in this way:

>>

volatile u32 __attribute__ ((aligned (4))) adc0_cmdlist[2] = {
0x00D04000UL,
0x80D14000UL};
volatile u16 __attribute__ ((aligned (4))) adc0_results[16]={
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void ADC_init(void){
u16 tmp;
ADC0CTL_0 = 0x0D; /*Dual Access mode and trigger mode selected */
ADC0CTL_1 = 0x00; /* Single command and result value list */
ADC0TIM = 0x07; /*  prescaler selected \*/
ADC0FMT = 0x82; /*Right justified and 10 bit resolution*/

/* ADC0 Command & Result Base Pointers */
ADC0CBP_0 = (unsigned char)(((long)adc0_cmdlist) >> 16);
ADC0CBP_1 = (unsigned char)(((long)adc0_cmdlist) >> 8);
ADC0CBP_2 = (unsigned char)((long)adc0_cmdlist);

// ADC0 Result Base Pointer
ADC0RBP_0 = (unsigned char)(((long)adc0_results) >> 16);
ADC0RBP_1 = (unsigned char)(((long)adc0_results) >> 8);
ADC0RBP_2 = (unsigned char)((long)adc0_results);
ADC0CTL_0_ADC_EN= 1;/* Enables the ADC*/
for(tmp=0;tmp<10000;tmp++){}
ADC0FLWCTL_RSTA=1;
for(tmp=0;tmp<10000;tmp++){}

}

>>

When I try to periodically read the conversion result  of AN1 by 'my_result=adc0_results[1]', I found that the value does not change at all although I have changed the position of the potentiometer on the DEVKIT-S12ZVC board which is linked to the AN1.

Since I think it is initialized into the continuous conversion mode, I do not give one more trigger or restart event after initialization and directly read the conversion result per 10 ms:

void TenmsInt(void)
{
   my_result = adc0_results[1];
}

So anyone can help me to figure out where is the problem?

Labels (1)
Tags (1)
4 Replies

2,357 Views
kef2
Senior Contributor V

Hi,

Your initialization is working, try adding adc_result to Variables tab in debugger, enable continuous refresh and run. I see values changing as you turn potentiometer. Perhaps something is wrong in the way you observe my_result, compiler optimization or something odd.

2,357 Views
thulzh
Contributor III

Hi,

I have try another way and it worked. The result changed as I turn potentiometer.

1.volatile u32 __attribute__ ((aligned (4))) adc0_cmdlist[2] = {
0x00D04000UL,
0xC0D14000UL // change the CMD_SEL from 2'b 10 to 2'b 11, the previous one is 0x80D14000UL

};

2. u16 tmp;
ADC0FLWCTL_RSTA=1;
for(tmp=0;tmp<10000;tmp++){} //give a restart even before read the results
my_result = 50*adc0_results[1];

Does this attempt provide some useful information for analyzing the problem?

0 Kudos
Reply

2,357 Views
kef2
Senior Contributor V

0x80D14000UL is correct.

You code from your first message works on my DEVKIT-S12ZVC, adc0_results update as I turn potentiometer.

2,357 Views
thulzh
Contributor III

Thank you!

I have added the adc_result[] to Variables tab in debugger, enable contious refresh and run. The adc_result[1] did not change but stay silent at the value which I think it to be the cooresponding value of the very beginning position of  potentiometer. It seems that the ADC has converted once at the beginning. 

0 Kudos
Reply