ADC stuck waiting for COCO (KL02Z)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

ADC stuck waiting for COCO (KL02Z)

跳至解决方案
1,689 次查看
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.

标签 (1)
标记 (3)
1 解答
1,028 次查看
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 项奖励
4 回复数
1,028 次查看
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,028 次查看
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 项奖励
1,028 次查看
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 项奖励
1,029 次查看
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 项奖励