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