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.
Solved! Go to Solution.
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
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!
Hi Simone,
What is the Frequency of your ADC module? According to the datasheet the maximum frequency for the ADC module is 18 MHz:
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!
-----------------------------------------------------------------------------------------------------------------------
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.
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