LPC804 ADC threshold compare interrupt hangs the device

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC804 ADC threshold compare interrupt hangs the device

892 Views
Hector_Jimenez
Contributor I

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

0 Kudos
5 Replies

858 Views
Hector_Jimenez
Contributor I

Thanks, @xiangjun_rong . I'll check it out and I will let you know the results.

0 Kudos

867 Views
Hector_Jimenez
Contributor I

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

0 Kudos

882 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport
Hi, I suppose that you use burst mode, only when the analog voltage exceeds the high threshold can the ISR is entered and sample is acquired. Once the analog voltage is above the upper threshold voltage, you set the ADC_EnableThresholdCompareInterrupt(ADC_PERIPHERAL, 9U, kADC_ThresholdInterruptOnOutside); mode, and ADC runs in burst mode, the void ADC_ADC_THCMP_IRQHANDLER(void) is entered for each ADC conversion, the core is overloaded, so it seems that the chip hangs on. I suggest you use ADC_EnableThresholdCompareInterrupt(ADC_PERIPHERAL, 9U, kADC_ThresholdInterruptOnCrossing); so that the ADC_ADC_THCMP_IRQHANDLER(void) is entered only once. It is only my guess, pls check if it is your case. If you use burst mode, I suggest you use software triggering mode. BR XiangJun Rong
0 Kudos

862 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport
Hi, At the time being, what your problem is that the ADC mode mode triggers ADC conversion too frequently, which leads to the fact that the cpu has not enough time to handle the ISR. I do not suggest you use burst mode, but you can use the CTimer to hardware trigger ADC so that you can control the sampling frequency, in burst mode, you can not control the ADC sampling frequency. For your application, it appears that you are only interested in the analog signal which is out of ADC compare range, you do not need to read the ADC sample, you only need to handle the ADC compare interrupt ISR. It appears that you can use the CMP_OUT signal to trigger ADC, pls check yourself. For ADC hardware trigger source, pls refer to Table 271. ADC hardware trigger inputs in UM11065.pdf Hope it can help you BR XiangJun Rong
0 Kudos

847 Views
Hector_Jimenez
Contributor I

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!

0 Kudos