AnsweredAssumed Answered

[Kinetis KEAZN64] ADC conversion does not start

Question asked by Mohammed Aboelnasr on Nov 14, 2017
Latest reply on Dec 11, 2017 by Stefano De Blasiis

Hello,

 

When I try to convert ADC channel once, it is working good.

However; when i do this conversion many consecutive times by for loop for example, sometimes conversion does not start. Note that I read 4 channels 10 consecutive times.

 

here is my code,

 

Regarding initialization function:

/* Select ADCACLK, no divide, 12 bit conversion,
* ADLPC = 0 (default) => hi speed config,
* ADIV = 0 (default) => clock rate = input clock/1,
* ADLSMP = 0 (default) => short sample time,
* MODE = 2 => 12 bit conversion,
* ADICLK= 0 => Bus clock source */
ADC_SC3 = 0x00000008;

 

/* ADTRG = 0 (default) => SW Trigger,
* ACFE = 0 (default) => compare function disabled,
* REFSEL = 0 (default)=> default ref volt pin pair */
ADC_SC2 = 0x00000000;

 

/* Disable module (default state),
* AIEN = 0 => Interrupts disabled,
* ADCO = 0 => Continuous conversions disabled,
* ADCH = 1F => Module disabled */
ADC_SC1 = 0x0000001F;

 

Regarding conversion function with the for loop:

 

channelsResults[0] = 0;
channelsResults[1] = 0;
channelsResults[2] = 0;
channelsResults[3] = 0;

 

for (iteration = 0; iteration < 10; iteration++)

{
/* Specify next channel for conversion */
ADC_SC1 = ADC_SC1_ADCH(12);
/* Test conversion complete flag */
while (ConversionCompleted () == 0){}
/* Read converted value */
channelsResults[0] = channelsResults[0] + ADC_R;


/* Specify next channel for conversion */
ADC_SC1 = ADC_SC1_ADCH(13);
/* Test conversion complete flag */
while (ConversionCompleted () == 0){}
/* Read converted value */
channelsResults[1] = channelsResults[1] + ADC_R;


/* Specify next channel for conversion */
ADC_SC1 = ADC_SC1_ADCH(14);
/* Test conversion complete flag */
while (ConversionCompleted () == 0){}
/* Read converted value */
channelsResults[2] = channelsResults[2] + ADC_R;


/* Specify next channel for conversion */
ADC_SC1 = ADC_SC1_ADCH(15);
/* Test conversion complete flag */
while (ConversionCompleted () == 0){}
/* Read converted value */
channelsResults[3] = channelsResults[3] + ADC_R;


}

 

channelsResults[0] = channelsResults[0] / 10;
channelsResults[1] = channelsResults[1] / 10;
channelsResults[2] = channelsResults[2] / 10;
channelsResults[3] = channelsResults[3] / 10;

Outcomes