ADC stuck waiting for COCO (KL02Z)

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

ADC stuck waiting for COCO (KL02Z)

ソリューションへジャンプ
2,068件の閲覧回数
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,407件の閲覧回数
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,407件の閲覧回数
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,407件の閲覧回数
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,407件の閲覧回数
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,408件の閲覧回数
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 件の賞賛
返信