ADC stuck waiting for COCO (KL02Z)

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

ADC stuck waiting for COCO (KL02Z)

Jump to solution
1,662 Views
sagha
Contributor II

I'm using the FRDM-KL02Z and reading from the ADC on an interrupt (OnEnd of a PWM signal). After running for a few minutes, the ADC will get stuck in the while loop of my getADC function:

int getADC(int adch) /* adch is the ADC channel (e.g. ADC_PDD_SINGLE_ENDED_AD10) */

{

  ADC_PDD_SetChannel(ADC0_BASE_PTR, ADC_SC1_ADCH_SHIFT, adch);

  while ((ADC0_SC1A & ADC_SC1_COCO_MASK) != ADC_SC1_COCO_MASK)

  {

  /* Wait for measurement to complete */

}

  return ADC0_RA; /* Return ADC value */

}

This happens even with no hardware averaging and the ADC resolution set to 8 bits. I calibrate the ADC at the program startup and set the ADC clock divisor to 1 and enable high speed mode. Why is the program hanging?

Thanks.

Labels (1)
Tags (3)
1 Solution
1,001 Views
adriancano
NXP Employee
NXP Employee

Hi,

Please check this threads, maybe you will find them useful.

Cannot read an ADC in a timer ISR

Re: ADC interrupt interfering with TI1

Regards,

Adrian

View solution in original post

0 Kudos
4 Replies
1,001 Views
sagha
Contributor II

Hi Adrian,

I had the same problem as the person who posted "Cannot read an ADC in a timer ISR". The solution in that thread (use the COCO interrupt) worked.

Thanks!

1,001 Views
adriancano
NXP Employee
NXP Employee

Hi Simone,

What is the Frequency of your ADC module? According to the datasheet the maximum frequency for the ADC module is 18 MHz:

adc max freq.png

You need to check that the configurations of the module do not exceed this limit.

I hope this information can help you.

Regards,

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. It would be nice!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,001 Views
sagha
Contributor II

Hi Adrian,

I set up the ADC using the Processor Expert with a prescaler of 2 resulting and a frequency of 10485.76 KHz. According to the PE, the time it takes for a single sample (HW averaging disabled, 8-bit) is 2.53 us.

I take an ADC measurement in an OnEnd interrupt after n cycles of a 200 KHz PWM signal (n still being adjusted during testing). Is there something with the timing of the PWM signal that is causing the ADC COCO to never be set? When I read the ADC at other points under other conditions in my program, it does not hang.

Thanks.

0 Kudos
1,002 Views
adriancano
NXP Employee
NXP Employee

Hi,

Please check this threads, maybe you will find them useful.

Cannot read an ADC in a timer ISR

Re: ADC interrupt interfering with TI1

Regards,

Adrian

0 Kudos