<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC Microcontrollers中的主题 LPC546xx Internal ADC Threshold Interrupt Lockup</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Internal-ADC-Threshold-Interrupt-Lockup/m-p/1160839#M42428</link>
    <description>&lt;P&gt;So I've been using the ADC0 - channel 9 on the LPC546xx to try and setup a threshold comparison interrupt - triggering above roughly 2 volt. This triggers fine but I can not seem to clear this triggered status, the IRQ handler always seems to fire no matter what (resultantly halting the program), even when removing the power supplies VDDA, ADC0, VD2_ANA, VREFP, TS - and the ADC clock (causing ADC_GetStatusFlags(ADC0) used in the interrupt handler to return 0) and still the interrupt fires, ive tried manipulating the relevant bits in the NVIC registers: clearing the NVIC-&amp;gt;ISPR[0] (only the correct bit) and setting NVIC-&amp;gt;ICPR[0] (only the correct bit) etc, from what i can determine some internal sequence or hardware routine must stay alive and keep updating NVIC registers, that or i cant overwrite them for some reason (never tried before), same with ADC0-&amp;gt;FLAGS (which holds the threshold compare int trigger bit) and ADC0-&amp;gt;GDAT[0] (ADC_SEQ_GDAT_RESULT holds the last result and ADC_SEQ_GDAT_CHN is the corresponding channel - which seem valid) registers, but I can set all the other ADC0 registers (CTRL, SEQ_CTRL etc) to zero. Any ideas would be appreciated, all im trying to do is trigger on a threshold, remove the physical trigger condition, then clear the interrupt so it can be triggered again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I extracted this code from a more complex project and used keypresses to fire different test routines (so i could change the voltage and stuff and try different combinations), testing was more indepth than outlined below but this is the general idea of what i tried&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;adc_conv_seq_config_t a2dConvSeqConfigStruct;&lt;BR /&gt;adc_result_info_t a2dResultInfoStruct, a2dGlobalResultInfoStruct;&lt;BR /&gt;bool stopInterruptPlease = false;&lt;/P&gt;&lt;P&gt;#define CHANGE_THRESHOLD 0&lt;BR /&gt;#define CONFIG_ZERO 0&lt;BR /&gt;#define KILL_ADC 1&lt;BR /&gt;#define KEEP_READING_ONCE_INTERRUPTED 1&lt;/P&gt;&lt;P&gt;void main() {&lt;BR /&gt;while(1) {&lt;/P&gt;&lt;P&gt;if (stopInterruptPlease) {&lt;BR /&gt;#if KILL_ADC&lt;BR /&gt;SysTick_DelayTicks(100); // let die&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;// test methods to stop interrupt&lt;BR /&gt;#if CHANGE_THRESHOLD&lt;BR /&gt;// change threshold stuff - this should not trigger&lt;BR /&gt;ADC_SetThresholdPair0(ADC0, 4095, 4096); // shouldnt be in this range&lt;BR /&gt;ADC_SetChannelWithThresholdPair0(ADC0, (1 &amp;lt;&amp;lt; A2D_CHANNEL_9));&lt;BR /&gt;ADC_EnableThresholdCompareInterrupt(ADC0, A2D_CHANNEL_9, kADC_ThresholdInterruptDisabled/*kADC_ThresholdInterruptOnCrossing*/); // neither should trigger&lt;BR /&gt;#elif CONFIG_ZERO&lt;/P&gt;&lt;P&gt;ADC0-&amp;gt;CTRL = 0;&lt;BR /&gt;ADC0-&amp;gt;INSEL = 0;&lt;BR /&gt;ADC0-&amp;gt;SEQ_CTRL[0] = 0;&lt;BR /&gt;ADC0-&amp;gt;SEQ_CTRL[1] = 0;&lt;BR /&gt;ADC0-&amp;gt;SEQ_GDAT[0]; // read only - fsl driver says this should clear&lt;BR /&gt;ADC0-&amp;gt;SEQ_GDAT[1]; // read only - fsl driver says this should clear&lt;BR /&gt;// ADC0-&amp;gt;DAT[0 - 11]; // read-only &amp;amp; dont care i guess&lt;BR /&gt;ADC0-&amp;gt;THR0_LOW = 0;&lt;BR /&gt;ADC0-&amp;gt;THR1_LOW = 0;&lt;BR /&gt;ADC0-&amp;gt;THR0_HIGH = 0;&lt;BR /&gt;ADC0-&amp;gt;THR1_HIGH = 0;&lt;BR /&gt;ADC0-&amp;gt;CHAN_THRSEL = 0;&lt;BR /&gt;ADC0-&amp;gt;INTEN = 0;&lt;BR /&gt;ADC0-&amp;gt;FLAGS = 1; // fsl_adc says 1&lt;BR /&gt;ADC0-&amp;gt;STARTUP = 0;&lt;BR /&gt;ADC0-&amp;gt;CALIB = 0;&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#if KILL_ADC&lt;BR /&gt;// already dead need to recover ADC&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VDDA);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_ADC0);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VD2_ANA);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VREFP);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_TS);&lt;BR /&gt;CLOCK_EnableClock(kCLOCK_Adc0);&lt;BR /&gt;#else&lt;BR /&gt;NVIC_EnableIRQ(ADC0_THCMP_IRQn);&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;#if KEEP_READING_ONCE_INTERRUPTED&lt;BR /&gt;A2D_Read(A2D_CHANNEL_9); // triggered - testing with and without keep reading, makes no difference&lt;BR /&gt;#endif&lt;BR /&gt;} else&lt;BR /&gt;A2D_Read(A2D_CHANNEL_9); // not triggered yet - keep reading to keep threshold checks happening (is this correct?)&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void ADC0_THCMP_IRQHandler() {&lt;BR /&gt;uint32_t flags = ADC_GetStatusFlags(ADC0);&lt;BR /&gt;ADC_ClearStatusFlags(ADC0, 1); // fsl_adc driver says write 1 to clear (also tried 0x0)&lt;/P&gt;&lt;P&gt;if (NVIC_GetPendingIRQ(ADC0_THCMP_IRQn))&lt;BR /&gt;NVIC_ClearPendingIRQ(ADC0_THCMP_IRQn); // once threshold has triggered, this interrupt seems to continuously trigger - tried clearing, currently active but tried this outside interrupt stack also - makes no difference as continuously triggered&lt;BR /&gt;// NVIC-&amp;gt;ICPR &amp;amp;= ~(1 &amp;lt;&amp;lt; ADC0_THCMP_IRQn);&lt;/P&gt;&lt;P&gt;if ((1 &amp;lt;&amp;lt; A2D_CHANNEL_9) &amp;amp; flags)&lt;BR /&gt;stopInterruptPlease = true;&lt;BR /&gt;//todo else if // ... other channel callbacks&lt;BR /&gt;// else&lt;BR /&gt;// PrintErrorADC("*** Could not match source channel ***\n");&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#if KILL_ADC&lt;BR /&gt;// kill ADC&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_VDDA);&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_ADC0);&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_VD2_ANA);&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_VREFP);&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_TS);&lt;BR /&gt;CLOCK_DisableClock(kCLOCK_Adc0);&lt;BR /&gt;#else&lt;BR /&gt;NVIC_DisableIRQ(ADC0_THCMP_IRQn);&lt;BR /&gt;// memory barriers required&lt;BR /&gt;__DSB();&lt;BR /&gt;__ISB();&lt;BR /&gt;#endif&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void A2D_Read(uint8_t channel) {&lt;BR /&gt;a2dConvSeqConfigStruct.channelMask = (1U &amp;lt;&amp;lt; channel);&lt;BR /&gt;ADC_SetConvSeqAConfig(ADC0, &amp;amp;a2dConvSeqConfigStruct);&lt;BR /&gt;ADC_DoSoftwareTriggerConvSeqA(ADC0);&lt;BR /&gt;while (!ADC_GetChannelConversionResult(ADC0, channel, &amp;amp;a2dResultInfoStruct));&lt;BR /&gt;ADC_GetConvSeqAGlobalConversionResult(ADC0, &amp;amp;a2dGlobalResultInfoStruct);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void A2D_Init() {&lt;BR /&gt;// give necessary supplies and a clock&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VDDA);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_ADC0);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VD2_ANA);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VREFP);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_TS);&lt;BR /&gt;CLOCK_EnableClock(kCLOCK_Adc0);&lt;/P&gt;&lt;P&gt;if (!ADC_DoSelfCalibration(ADC0))&lt;BR /&gt;;//PrintErrorADC("*** ADC calibration failure ***\n");&lt;/P&gt;&lt;P&gt;adc_config_t adcConfigStruct;&lt;BR /&gt;// adcConfigStruct.clockDividerNumber = 19; // ~ 5MHz&lt;BR /&gt;adcConfigStruct.clockDividerNumber = 4000; // main clock is 96MHz, so ADC should run at like 24,000KHz right?&lt;BR /&gt;#if defined(FSL_FEATURE0_ADC_HAS_CTRL_ASYNMODE) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_ASYNMODE&lt;BR /&gt;adcConfigStruct.clockMode = kADC_ClockSynchronousMode;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_CTRL_RESOL) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_RESOL&lt;BR /&gt;adcConfigStruct.resolution = kADC_Resolution12bit;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_CTRL_BYPASSCAL) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_BYPASSCAL&lt;BR /&gt;adcConfigStruct.enableBypassCalibration = false;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_CTRL_TSAMP) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_TSAMP&lt;BR /&gt;adcConfigStruct.sampleTimeNumber = 0U;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_CTRL_LPWRMODE) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_LPWRMODE&lt;BR /&gt;adcConfigStruct.enableLowPowerMode = false;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_TRIM_REG) &amp;amp; FSL_FEATURE_ADC_HAS_TRIM_REG&lt;BR /&gt;adcConfigStruct.voltageRange = kADC_HighVoltageRange;&lt;BR /&gt;#endif&lt;BR /&gt;ADC_Init(ADC0, &amp;amp;adcConfigStruct);&lt;/P&gt;&lt;P&gt;#if !(defined(FSL_FEATURE_ADC_HAS_NO_INSEL) &amp;amp;&amp;amp; FSL_FEATURE_ADC_HAS_NO_INSEL)&lt;BR /&gt;ADC_EnableTemperatureSensor(ADC0, false);&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;a2dConvSeqConfigStruct.channelMask = (1U &amp;lt;&amp;lt; A2D_CHANNEL_9);&lt;BR /&gt;a2dConvSeqConfigStruct.triggerMask = 0U; // not hardware group interrupt triggered&lt;BR /&gt;a2dConvSeqConfigStruct.triggerPolarity = kADC_TriggerPolarityPositiveEdge;&lt;BR /&gt;a2dConvSeqConfigStruct.enableSingleStep = false /*true*/;&lt;BR /&gt;a2dConvSeqConfigStruct.enableSyncBypass = false;&lt;BR /&gt;a2dConvSeqConfigStruct.interruptMode = kADC_InterruptForEachConversion /*kADC_InterruptForEachSequence*/;&lt;BR /&gt;ADC_SetConvSeqAConfig(ADC0, &amp;amp;a2dConvSeqConfigStruct);&lt;BR /&gt;ADC_DoSoftwareTriggerConvSeqA(ADC0);&lt;BR /&gt;while (!ADC_GetChannelConversionResult(ADC0, A2D_CHANNEL_9, &amp;amp;a2dResultInfoStruct));&lt;BR /&gt;ADC_GetConvSeqAGlobalConversionResult(ADC0, &amp;amp;a2dGlobalResultInfoStruct);&lt;/P&gt;&lt;P&gt;ADC_SetThresholdPair0(ADC0, 0, 2500 /*respect to 2^12=4096*/); // no trigger between 0V and ~2V&lt;BR /&gt;ADC_SetChannelWithThresholdPair0(ADC0, (1 &amp;lt;&amp;lt; A2D_CHANNEL_9));&lt;BR /&gt;ADC_EnableThresholdCompareInterrupt(ADC0, A2D_CHANNEL_9, kADC_ThresholdInterruptOnOutside);&lt;BR /&gt;NVIC_EnableIRQ(ADC0_THCMP_IRQn); // threshold compare interrupt&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:51:44 GMT</pubDate>
    <dc:creator>koreycyrus</dc:creator>
    <dc:date>2020-09-29T16:51:44Z</dc:date>
    <item>
      <title>LPC546xx Internal ADC Threshold Interrupt Lockup</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Internal-ADC-Threshold-Interrupt-Lockup/m-p/1160839#M42428</link>
      <description>&lt;P&gt;So I've been using the ADC0 - channel 9 on the LPC546xx to try and setup a threshold comparison interrupt - triggering above roughly 2 volt. This triggers fine but I can not seem to clear this triggered status, the IRQ handler always seems to fire no matter what (resultantly halting the program), even when removing the power supplies VDDA, ADC0, VD2_ANA, VREFP, TS - and the ADC clock (causing ADC_GetStatusFlags(ADC0) used in the interrupt handler to return 0) and still the interrupt fires, ive tried manipulating the relevant bits in the NVIC registers: clearing the NVIC-&amp;gt;ISPR[0] (only the correct bit) and setting NVIC-&amp;gt;ICPR[0] (only the correct bit) etc, from what i can determine some internal sequence or hardware routine must stay alive and keep updating NVIC registers, that or i cant overwrite them for some reason (never tried before), same with ADC0-&amp;gt;FLAGS (which holds the threshold compare int trigger bit) and ADC0-&amp;gt;GDAT[0] (ADC_SEQ_GDAT_RESULT holds the last result and ADC_SEQ_GDAT_CHN is the corresponding channel - which seem valid) registers, but I can set all the other ADC0 registers (CTRL, SEQ_CTRL etc) to zero. Any ideas would be appreciated, all im trying to do is trigger on a threshold, remove the physical trigger condition, then clear the interrupt so it can be triggered again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I extracted this code from a more complex project and used keypresses to fire different test routines (so i could change the voltage and stuff and try different combinations), testing was more indepth than outlined below but this is the general idea of what i tried&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;adc_conv_seq_config_t a2dConvSeqConfigStruct;&lt;BR /&gt;adc_result_info_t a2dResultInfoStruct, a2dGlobalResultInfoStruct;&lt;BR /&gt;bool stopInterruptPlease = false;&lt;/P&gt;&lt;P&gt;#define CHANGE_THRESHOLD 0&lt;BR /&gt;#define CONFIG_ZERO 0&lt;BR /&gt;#define KILL_ADC 1&lt;BR /&gt;#define KEEP_READING_ONCE_INTERRUPTED 1&lt;/P&gt;&lt;P&gt;void main() {&lt;BR /&gt;while(1) {&lt;/P&gt;&lt;P&gt;if (stopInterruptPlease) {&lt;BR /&gt;#if KILL_ADC&lt;BR /&gt;SysTick_DelayTicks(100); // let die&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;// test methods to stop interrupt&lt;BR /&gt;#if CHANGE_THRESHOLD&lt;BR /&gt;// change threshold stuff - this should not trigger&lt;BR /&gt;ADC_SetThresholdPair0(ADC0, 4095, 4096); // shouldnt be in this range&lt;BR /&gt;ADC_SetChannelWithThresholdPair0(ADC0, (1 &amp;lt;&amp;lt; A2D_CHANNEL_9));&lt;BR /&gt;ADC_EnableThresholdCompareInterrupt(ADC0, A2D_CHANNEL_9, kADC_ThresholdInterruptDisabled/*kADC_ThresholdInterruptOnCrossing*/); // neither should trigger&lt;BR /&gt;#elif CONFIG_ZERO&lt;/P&gt;&lt;P&gt;ADC0-&amp;gt;CTRL = 0;&lt;BR /&gt;ADC0-&amp;gt;INSEL = 0;&lt;BR /&gt;ADC0-&amp;gt;SEQ_CTRL[0] = 0;&lt;BR /&gt;ADC0-&amp;gt;SEQ_CTRL[1] = 0;&lt;BR /&gt;ADC0-&amp;gt;SEQ_GDAT[0]; // read only - fsl driver says this should clear&lt;BR /&gt;ADC0-&amp;gt;SEQ_GDAT[1]; // read only - fsl driver says this should clear&lt;BR /&gt;// ADC0-&amp;gt;DAT[0 - 11]; // read-only &amp;amp; dont care i guess&lt;BR /&gt;ADC0-&amp;gt;THR0_LOW = 0;&lt;BR /&gt;ADC0-&amp;gt;THR1_LOW = 0;&lt;BR /&gt;ADC0-&amp;gt;THR0_HIGH = 0;&lt;BR /&gt;ADC0-&amp;gt;THR1_HIGH = 0;&lt;BR /&gt;ADC0-&amp;gt;CHAN_THRSEL = 0;&lt;BR /&gt;ADC0-&amp;gt;INTEN = 0;&lt;BR /&gt;ADC0-&amp;gt;FLAGS = 1; // fsl_adc says 1&lt;BR /&gt;ADC0-&amp;gt;STARTUP = 0;&lt;BR /&gt;ADC0-&amp;gt;CALIB = 0;&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#if KILL_ADC&lt;BR /&gt;// already dead need to recover ADC&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VDDA);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_ADC0);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VD2_ANA);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VREFP);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_TS);&lt;BR /&gt;CLOCK_EnableClock(kCLOCK_Adc0);&lt;BR /&gt;#else&lt;BR /&gt;NVIC_EnableIRQ(ADC0_THCMP_IRQn);&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;#if KEEP_READING_ONCE_INTERRUPTED&lt;BR /&gt;A2D_Read(A2D_CHANNEL_9); // triggered - testing with and without keep reading, makes no difference&lt;BR /&gt;#endif&lt;BR /&gt;} else&lt;BR /&gt;A2D_Read(A2D_CHANNEL_9); // not triggered yet - keep reading to keep threshold checks happening (is this correct?)&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void ADC0_THCMP_IRQHandler() {&lt;BR /&gt;uint32_t flags = ADC_GetStatusFlags(ADC0);&lt;BR /&gt;ADC_ClearStatusFlags(ADC0, 1); // fsl_adc driver says write 1 to clear (also tried 0x0)&lt;/P&gt;&lt;P&gt;if (NVIC_GetPendingIRQ(ADC0_THCMP_IRQn))&lt;BR /&gt;NVIC_ClearPendingIRQ(ADC0_THCMP_IRQn); // once threshold has triggered, this interrupt seems to continuously trigger - tried clearing, currently active but tried this outside interrupt stack also - makes no difference as continuously triggered&lt;BR /&gt;// NVIC-&amp;gt;ICPR &amp;amp;= ~(1 &amp;lt;&amp;lt; ADC0_THCMP_IRQn);&lt;/P&gt;&lt;P&gt;if ((1 &amp;lt;&amp;lt; A2D_CHANNEL_9) &amp;amp; flags)&lt;BR /&gt;stopInterruptPlease = true;&lt;BR /&gt;//todo else if // ... other channel callbacks&lt;BR /&gt;// else&lt;BR /&gt;// PrintErrorADC("*** Could not match source channel ***\n");&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#if KILL_ADC&lt;BR /&gt;// kill ADC&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_VDDA);&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_ADC0);&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_VD2_ANA);&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_VREFP);&lt;BR /&gt;POWER_EnablePD(kPDRUNCFG_PD_TS);&lt;BR /&gt;CLOCK_DisableClock(kCLOCK_Adc0);&lt;BR /&gt;#else&lt;BR /&gt;NVIC_DisableIRQ(ADC0_THCMP_IRQn);&lt;BR /&gt;// memory barriers required&lt;BR /&gt;__DSB();&lt;BR /&gt;__ISB();&lt;BR /&gt;#endif&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void A2D_Read(uint8_t channel) {&lt;BR /&gt;a2dConvSeqConfigStruct.channelMask = (1U &amp;lt;&amp;lt; channel);&lt;BR /&gt;ADC_SetConvSeqAConfig(ADC0, &amp;amp;a2dConvSeqConfigStruct);&lt;BR /&gt;ADC_DoSoftwareTriggerConvSeqA(ADC0);&lt;BR /&gt;while (!ADC_GetChannelConversionResult(ADC0, channel, &amp;amp;a2dResultInfoStruct));&lt;BR /&gt;ADC_GetConvSeqAGlobalConversionResult(ADC0, &amp;amp;a2dGlobalResultInfoStruct);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void A2D_Init() {&lt;BR /&gt;// give necessary supplies and a clock&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VDDA);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_ADC0);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VD2_ANA);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_VREFP);&lt;BR /&gt;POWER_DisablePD(kPDRUNCFG_PD_TS);&lt;BR /&gt;CLOCK_EnableClock(kCLOCK_Adc0);&lt;/P&gt;&lt;P&gt;if (!ADC_DoSelfCalibration(ADC0))&lt;BR /&gt;;//PrintErrorADC("*** ADC calibration failure ***\n");&lt;/P&gt;&lt;P&gt;adc_config_t adcConfigStruct;&lt;BR /&gt;// adcConfigStruct.clockDividerNumber = 19; // ~ 5MHz&lt;BR /&gt;adcConfigStruct.clockDividerNumber = 4000; // main clock is 96MHz, so ADC should run at like 24,000KHz right?&lt;BR /&gt;#if defined(FSL_FEATURE0_ADC_HAS_CTRL_ASYNMODE) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_ASYNMODE&lt;BR /&gt;adcConfigStruct.clockMode = kADC_ClockSynchronousMode;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_CTRL_RESOL) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_RESOL&lt;BR /&gt;adcConfigStruct.resolution = kADC_Resolution12bit;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_CTRL_BYPASSCAL) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_BYPASSCAL&lt;BR /&gt;adcConfigStruct.enableBypassCalibration = false;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_CTRL_TSAMP) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_TSAMP&lt;BR /&gt;adcConfigStruct.sampleTimeNumber = 0U;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_CTRL_LPWRMODE) &amp;amp; FSL_FEATURE_ADC_HAS_CTRL_LPWRMODE&lt;BR /&gt;adcConfigStruct.enableLowPowerMode = false;&lt;BR /&gt;#endif&lt;BR /&gt;#if defined(FSL_FEATURE_ADC_HAS_TRIM_REG) &amp;amp; FSL_FEATURE_ADC_HAS_TRIM_REG&lt;BR /&gt;adcConfigStruct.voltageRange = kADC_HighVoltageRange;&lt;BR /&gt;#endif&lt;BR /&gt;ADC_Init(ADC0, &amp;amp;adcConfigStruct);&lt;/P&gt;&lt;P&gt;#if !(defined(FSL_FEATURE_ADC_HAS_NO_INSEL) &amp;amp;&amp;amp; FSL_FEATURE_ADC_HAS_NO_INSEL)&lt;BR /&gt;ADC_EnableTemperatureSensor(ADC0, false);&lt;BR /&gt;#endif&lt;/P&gt;&lt;P&gt;a2dConvSeqConfigStruct.channelMask = (1U &amp;lt;&amp;lt; A2D_CHANNEL_9);&lt;BR /&gt;a2dConvSeqConfigStruct.triggerMask = 0U; // not hardware group interrupt triggered&lt;BR /&gt;a2dConvSeqConfigStruct.triggerPolarity = kADC_TriggerPolarityPositiveEdge;&lt;BR /&gt;a2dConvSeqConfigStruct.enableSingleStep = false /*true*/;&lt;BR /&gt;a2dConvSeqConfigStruct.enableSyncBypass = false;&lt;BR /&gt;a2dConvSeqConfigStruct.interruptMode = kADC_InterruptForEachConversion /*kADC_InterruptForEachSequence*/;&lt;BR /&gt;ADC_SetConvSeqAConfig(ADC0, &amp;amp;a2dConvSeqConfigStruct);&lt;BR /&gt;ADC_DoSoftwareTriggerConvSeqA(ADC0);&lt;BR /&gt;while (!ADC_GetChannelConversionResult(ADC0, A2D_CHANNEL_9, &amp;amp;a2dResultInfoStruct));&lt;BR /&gt;ADC_GetConvSeqAGlobalConversionResult(ADC0, &amp;amp;a2dGlobalResultInfoStruct);&lt;/P&gt;&lt;P&gt;ADC_SetThresholdPair0(ADC0, 0, 2500 /*respect to 2^12=4096*/); // no trigger between 0V and ~2V&lt;BR /&gt;ADC_SetChannelWithThresholdPair0(ADC0, (1 &amp;lt;&amp;lt; A2D_CHANNEL_9));&lt;BR /&gt;ADC_EnableThresholdCompareInterrupt(ADC0, A2D_CHANNEL_9, kADC_ThresholdInterruptOnOutside);&lt;BR /&gt;NVIC_EnableIRQ(ADC0_THCMP_IRQn); // threshold compare interrupt&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:51:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Internal-ADC-Threshold-Interrupt-Lockup/m-p/1160839#M42428</guid>
      <dc:creator>koreycyrus</dc:creator>
      <dc:date>2020-09-29T16:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: LPC546xx Internal ADC Threshold Interrupt Lockup</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Internal-ADC-Threshold-Interrupt-Lockup/m-p/1160989#M42431</link>
      <description>&lt;P&gt;Hi, Korey,&lt;/P&gt;
&lt;P&gt;I suggest you check each THCMPx bit in the following ADC FLAGS register, if one bit is set, clearing the bit by writing a 1 to the bit. I think it is okay to write 0x3FF to the ADC FLAGS register so that you can clear all bits. Pls have a try.&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Xiangjun Rong&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xiangjun_rong_0-1601432538840.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/126506iED607F32C010C21D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xiangjun_rong_0-1601432538840.png" alt="xiangjun_rong_0-1601432538840.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:25:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Internal-ADC-Threshold-Interrupt-Lockup/m-p/1160989#M42431</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2020-09-30T02:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: LPC546xx Internal ADC Threshold Interrupt Lockup</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Internal-ADC-Threshold-Interrupt-Lockup/m-p/1161212#M42432</link>
      <description>&lt;P&gt;Yeah that did it, thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 09:05:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Internal-ADC-Threshold-Interrupt-Lockup/m-p/1161212#M42432</guid>
      <dc:creator>koreycyrus</dc:creator>
      <dc:date>2020-09-30T09:05:43Z</dc:date>
    </item>
  </channel>
</rss>

