<?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>i.MX ProcessorsのトピックRe: i.MX8ULP LPADC compare function</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2421034#M247028</link>
    <description>&lt;P&gt;hardwardCompareValueHigh/Low stores the raw CV register values, you need to align them to the RESFIFO D-field format themselves, I checked internal data base, I didn't find&amp;nbsp; a confirmed SDK roadmap item indicating that the existing field-shift macros will be changed or that the driver will automatically apply this conversion.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Oct 2026 09:59:06 GMT</pubDate>
    <dc:creator>joanxie</dc:creator>
    <dc:date>2026-10-14T09:59:06Z</dc:date>
    <item>
      <title>i.MX8ULP LPADC compare function</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2419612#M246978</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use the i.MX8ULP ADC in comparator mode from the M33 core, specifically, setup the ADC such that if the conversion value falls below a threshold I get an interrupt to process the event.&lt;/P&gt;&lt;P&gt;My understanding from the reference manual is that this should be possible:&lt;/P&gt;&lt;P&gt;- setup the ADC with a fifo watermark of 1, so any data triggers the interrupt (this part works, in the example below I removed the interrupt code to make the code simpler)&lt;/P&gt;&lt;P&gt;- setup the compare function with "Repeat compare until true", CVH/CVL appropriately and trigger will then sample the ADC continuously and raise the data once it is appropriate&lt;/P&gt;&lt;P&gt;Unfortunately I've not been able to make the compare values work at all, the manual states that various operations are possible depending on CVL/CVH but none of them seemed to work for me using ADC1 / command 1 / trigger 1:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="martinetd_0-1791506359158.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/397556iD23FD6733C4DAB5A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="martinetd_0-1791506359158.png" alt="martinetd_0-1791506359158.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Experimentally, I've seen:&lt;/P&gt;&lt;P&gt;- CVL &amp;lt; CVH (manual says true if outside range e.g. val &amp;lt; CVL || val &amp;gt; CVH): value always returned (even if it falls within range)&lt;/P&gt;&lt;P&gt;- CVH max, CVL set (should be less than CVL): maximum value is not specified so I wasn't sure, setting CVH to 0xfff or 0x1000 the value is always returned regardless of CVL, setting CVH to 0xffff the value is never returned&lt;/P&gt;&lt;P&gt;- CVL min, CVH set (should be greater than CVH): value is always returned&lt;/P&gt;&lt;P&gt;- CVL &amp;gt; CVH (should be inside range e.g. CVH &amp;lt; val &amp;lt; CVL): value is never returned&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code I used:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;      lpadc_config_t adcConfig;
      LPADC_GetDefaultConfig(&amp;amp;adcConfig);
      adcConfig.FIFOWatermark           = 0;
      adcConfig.enableAnalogPreliminary = true;
      LPADC_Init(ADC1, &amp;amp;adcConfig);
  
      lpadc_conv_trigger_config_t triggerConfig;
      LPADC_GetDefaultConvTriggerConfig(&amp;amp;triggerConfig);
      triggerConfig.targetCommandId       = 1;
      triggerConfig.enableHardwareTrigger = true;
      LPADC_SetConvTriggerConfig(ADC1, 0, &amp;amp;triggerConfig);
  
      lpadc_conv_command_config_t commandConfig; 
      LPADC_GetDefaultConvCommandConfig(&amp;amp;commandConfig);
      commandConfig.channelNumber       = 5;
      commandConfig.sampleChannelMode   = kLPADC_SampleChannelSingleEndSideB;
      commandConfig.sampleScaleMode     = kLPADC_SampleFullScale;
      commandConfig.hardwareAverageMode = kLPADC_HardwareAverageCount2;
      commandConfig.hardwareCompareMode = kLPADC_HardwareCompareRepeatUntilTrue;
      commandConfig.hardwareCompareValueHigh = v_high; 
      commandConfig.hardwareCompareValueLow  = v_low;  
      LPADC_SetConvCommandConfig(ADC1, 1, &amp;amp;commandConfig);
  
      SDK_DelayAtLeastUs(1000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
      LPADC_DoSoftwareTrigger(ADC1, 1 &amp;lt;&amp;lt; 0);
      // this is LPADC_GetConvResultBlocking() with a timeout
      uint32_t tmp, cnt = 0;
      tmp = ((ADC_Type *)ADC1)-&amp;gt;RESFIFO;
      while (ADC_RESFIFO_VALID_MASK != (tmp &amp;amp; ADC_RESFIFO_VALID_MASK) &amp;amp;&amp;amp; cnt &amp;lt; 100000)
      {
          tmp = ((ADC_Type *)ADC1)-&amp;gt;RESFIFO;
          cnt++;
      }
      if (ADC_RESFIFO_VALID_MASK != (tmp &amp;amp; ADC_RESFIFO_VALID_MASK))
      {
          PRINTF("ADC timeout\r\n");
      }
      else
      {
          tmp &amp;amp;= ADC_RESFIFO_D_MASK;
          tmp &amp;gt;&amp;gt;= 3;
          PRINTF("got %d (%#x) in %d\r\n", tmp, tmp, cnt);
      }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also dumped registers, I'm confident the "compare repeat until true" part works because the STAT register considers the trigger/command to still be running, and I got identical results with "Store on true" setting (And fiddling with CV (compare value) while the command is running gets weird results, but properly returns the triggers that were waiting for condition to be true - I'm sure we're not supposed to change CV while running so let's ignore this bit)&lt;/P&gt;&lt;P&gt;Here's registers while waiting for conversion, with CVL = 0xffe and CVH = 0x1 (so should return any value between the two):&lt;/P&gt;&lt;LI-CODE lang="c"&gt;ADC1 0x280a2000
VERID: 0x200101a
PARAM: 0xf041004
CTRL: 0x1
^ ADCEN
STAT: 0x1000800
^ CMDACT 1, ADC_ACTIVE
IE: 0
DE: 0
CFG: 0x10800000
^ PWREN, PUDLY = 0x80
PAUSE: 0
TSTAT: 0
TCTRL[0]: 0x1000001
^ TCMD = CMD1, HTEN (no difference when disabled)
FCTRL: 0
CMD[0].CMDL: 0x2025
^ CSCALE full-scale, ABSEL = B, CH5
CMD[0].CMDH: 0x1003
^ AVGS = 2 conversions, CMPEN = repeat until true
CV[0]: 0x10ffe
^ compare value, CVH=1 and CVL=0xffe&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I holding this wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Dominique&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2026 01:07:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2419612#M246978</guid>
      <dc:creator>martinetd</dc:creator>
      <dc:date>2026-10-09T01:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: i.MX8ULP LPADC compare function</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2420891#M247020</link>
      <description>&lt;P&gt;refer to the Table 725. Data result register format description of reference manual,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="joanxie_0-1791946813576.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/397926i2721688E3223433E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="joanxie_0-1791946813576.png" alt="joanxie_0-1791946813576.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;the data is D[14:3],&amp;nbsp;for the compare value, I think you should 3bits shift , like&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;commandConfig.hardwareCompareValueHigh = v_high &amp;lt;&amp;lt; 3; //CVH=0x8&lt;/LI-CODE&gt;&lt;LI-CODE lang="c"&gt;commandConfig.hardwareCompareValueLow  = v_low &amp;lt;&amp;lt; 3;//CVL=0x7ff0&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2026 05:38:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2420891#M247020</guid>
      <dc:creator>joanxie</dc:creator>
      <dc:date>2026-10-14T05:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: i.MX8ULP LPADC compare function</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2420918#M247026</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/39586"&gt;@joanxie&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can confirm shifting the compare value appear to work! (I need to slow down the adc clock because the ADC is sampling too fast, even with&amp;nbsp;convPauseDelay = 1023, but that is something I can probably figure out)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the shift something one is supposed to be aware of, or will the&amp;nbsp;ADC_CV_CVL_SHIFT /&amp;nbsp;ADC_CV_CVH_SHIFT macros in&amp;nbsp;e.g. MIMX8UD5_cm33.h be updated so setting&amp;nbsp;hardwareCompareValueHigh/Low just works?&lt;/P&gt;&lt;P&gt;There's no example available at all in &lt;A href="https://github.com/nxp-mcuxpresso/mcuxsdk-examples" target="_blank"&gt;https://github.com/nxp-mcuxpresso/mcuxsdk-examples&lt;/A&gt;&amp;nbsp;so I'd like to confirm what (if anything) will be updated to clarify this in the future (either the comment in fsl_lpadc.h describing&amp;nbsp;hardwareCompareValueHigh or the device macro to make it work) -- if the macro is updated I'll need to be careful when updating the SDK, so it'd be great to know ahead of time to plan for it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2026 05:36:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2420918#M247026</guid>
      <dc:creator>martinetd</dc:creator>
      <dc:date>2026-10-14T05:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: i.MX8ULP LPADC compare function</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2421034#M247028</link>
      <description>&lt;P&gt;hardwardCompareValueHigh/Low stores the raw CV register values, you need to align them to the RESFIFO D-field format themselves, I checked internal data base, I didn't find&amp;nbsp; a confirmed SDK roadmap item indicating that the existing field-shift macros will be changed or that the driver will automatically apply this conversion.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2026 09:59:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2421034#M247028</guid>
      <dc:creator>joanxie</dc:creator>
      <dc:date>2026-10-14T09:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: i.MX8ULP LPADC compare function</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2421203#M247036</link>
      <description>Okay, I'll handle it in our code, thank you for confirming.</description>
      <pubDate>Thu, 15 Oct 2026 02:23:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/i-MX8ULP-LPADC-compare-function/m-p/2421203#M247036</guid>
      <dc:creator>martinetd</dc:creator>
      <dc:date>2026-10-15T02:23:17Z</dc:date>
    </item>
  </channel>
</rss>

