Hello!
I'm trying to use LPC804 ADC threshold compare interrupt to do some certain things when defined threshold are exceeded, but whenever I set the voltage upper or lower than these thresholds, my system hangs up.
I'm using SDK_2.x_LPC804 (2.11.0 version) to create ADC peripheral and the following code:
static void ADC_init(void) {
/* Initialize ADC peripheral */
ADC_Init(ADC_PERIPHERAL, &ADCconfigStruct);
/* Configure the conversion sequence A */
ADC_SetConvSeqAConfig(ADC_PERIPHERAL, &ADCConvSeqAConfigStruct);
/* Enable the conversion sequence A */
ADC_EnableConvSeqA(ADC_PERIPHERAL, true);
/* Initialize 0. pair of threshold setting */
ADC_SetThresholdPair0(ADC_PERIPHERAL, 1100U, 1500U);
/* Assign threshold setting pairs to channels */
ADC_SetChannelWithThresholdPair0(ADC_PERIPHERAL, 512U);
/* Configure threshold compare interrupt on channel 9 */
ADC_EnableThresholdCompareInterrupt(ADC_PERIPHERAL, 9U, kADC_ThresholdInterruptOnOutside);
/* Enable interrupt ADC_THCMP_IRQn request in the NVIC. */
EnableIRQ(ADC_ADC_THCMP_IRQN);
}
...
/* ADC_THCMP_IRQn interrupt handler */
void ADC_ADC_THCMP_IRQHANDLER(void) {
/* Get status flags */
if (kADC_ThresholdCompareInterruptFlag == (kADC_ThresholdCompareInterruptFlag & ADC_GetStatusFlags(ADC_PERIPHERAL)))
{
/* Place your interrupt code here */
// Get ADC level of interrupt (LOW/HIGH)
adc_result_info_t info;
ADC_GetChannelConversionResult(ADC_PERIPHERAL, 9, &info);
if (info.thresholdCorssingStatus == kADC_ThresholdCrossingDownward) {
// LOW THRESHOLD Do something
lowThresFunc(); //dummy function
} else if (info.thresholdCorssingStatus == kADC_ThresholdCrossingUpward) {
// HIGH THRESHOLD Do other thing
highThresFunc(); //dummy function
}
/* Clear status flags */
ADC_ClearStatusFlags(ADC_PERIPHERAL, kADC_ThresholdCompareInterruptFlag);
}
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F
Store immediate overlapping exception return operation might vector to incorrect interrupt. */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}
Any ideas?
Thank you for your help
Thanks, @xiangjun_rong . I'll check it out and I will let you know the results.
Hi, @xiangjun_rong .
If happens the same using ADC_EnableThresholdCompareInterrupt(ADC_PERIPHERAL, 9U, kADC_ThresholdInterruptOnCrossing) as you suggested. It was my first attemp as it can be seen in IRQ handler when comparing to
thresholdCorssingStatus
I'm using software trigger to start the sequence.
Any other ideas?
Thank you
Hi, @xiangjun_rong .
I finally managed to make it work by setting irq code inside "exterrn C" area, but it kept still hanging when system started outside thresholds range. There was no problem if system was turned on inside thresholds range, adc irq was working fine in both crossing and out_of_level modes, but when Voltage was out of low-high thresholds range when turning system on, system kept hanging.
My project is not so critical to need using adc interrupt but it was a smart option, especially the out_of_range mode, as long as threshold crossing mode only uses low threshold for comparing.
I finally handled it by polling adc measurement via MRT timer interrupt.
Thank you anyway.
Kind regards!