<?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>topic Re: Error in fsl_adc12.c in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Error-in-fsl-adc12-c/m-p/1023417#M56312</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello &lt;A _jive_internal="true" data-content-finding="Community" data-userid="350911" data-username="sean.dvorscak@craneae.com" href="https://community.nxp.com/people/sean.dvorscak@craneae.com"&gt;Sean Dvorscak&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you enter ADC12_DoAutoCalibration function, the variable &lt;EM&gt;averageMode&lt;/EM&gt; stores the value that is in AVGS field of ADC_SC3 register.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to calibrate the ADC the average value must be 32 samples, so you change temporarily this field to calibrate the device, when the calibration is complete you return to the average value that was before entering the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if this is helpful.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Omar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 06 Feb 2020 18:50:43 GMT</pubDate>
    <dc:creator>Omar_Anguiano</dc:creator>
    <dc:date>2020-02-06T18:50:43Z</dc:date>
    <item>
      <title>Error in fsl_adc12.c</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Error-in-fsl-adc12-c/m-p/1023416#M56311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using an MKE18F512VLH16 MCU.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have found a small issue in the ADC12_DoAutoCalibration function that is in the fsl_adc12.c file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The function attempts to reset the SC3 register back to its original state after it does some auto calibrating.&amp;nbsp; However, when attempting to restore the AVGS field in the SC3 register, the code does this to restore it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Stores current SC3 register value&lt;/P&gt;&lt;P&gt;tmp32 = base-&amp;gt;SC3;&lt;BR /&gt; averageMode = ((tmp32 &amp;amp; ADC_SC3_AVGS_MASK) &amp;gt;&amp;gt; ADC_SC3_AVGS_SHIFT); // (Saves the AVGS Field)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Triggers a calibration&lt;/P&gt;&lt;P&gt;tmp32 &amp;amp;= ~ADC_SC3_AVGS_MASK;&lt;BR /&gt; tmp32 |= (ADC_SC3_AVGE_MASK | ADC_SC3_AVGS(ADC_SC3_AVGS_MASK &amp;gt;&amp;gt; ADC_SC3_AVGS_SHIFT));&lt;/P&gt;&lt;P&gt;tmp32 |= ADC_SC3_CAL_MASK;&lt;BR /&gt; base-&amp;gt;SC3 = tmp32;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Attempt to restore&lt;/P&gt;&lt;P&gt;tmp32 = base-&amp;gt;SC3;&lt;/P&gt;&lt;P&gt;tmp32 |= ADC_SC3_AVGS(averageMode); // (This is where I see an issue)&lt;BR /&gt; base-&amp;gt;SC3 = tmp32;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The or'ing&amp;nbsp; of tmp32 and&amp;nbsp;&lt;SPAN&gt;ADC_SC3_AVGS(averageMode) will result in no change to the field if the averageMode is 0, and can cause errors for other values as well.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would also like to understand if this AVGS field will tamper with ADC data results after calibration, or is this field only for doing an auto calibration?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have attached the code to this post as well.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jan 2020 19:27:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Error-in-fsl-adc12-c/m-p/1023416#M56311</guid>
      <dc:creator>sean_dvorscak</dc:creator>
      <dc:date>2020-01-30T19:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error in fsl_adc12.c</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Error-in-fsl-adc12-c/m-p/1023417#M56312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello &lt;A _jive_internal="true" data-content-finding="Community" data-userid="350911" data-username="sean.dvorscak@craneae.com" href="https://community.nxp.com/people/sean.dvorscak@craneae.com"&gt;Sean Dvorscak&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you enter ADC12_DoAutoCalibration function, the variable &lt;EM&gt;averageMode&lt;/EM&gt; stores the value that is in AVGS field of ADC_SC3 register.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to calibrate the ADC the average value must be 32 samples, so you change temporarily this field to calibrate the device, when the calibration is complete you return to the average value that was before entering the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if this is helpful.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Omar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Feb 2020 18:50:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Error-in-fsl-adc12-c/m-p/1023417#M56312</guid>
      <dc:creator>Omar_Anguiano</dc:creator>
      <dc:date>2020-02-06T18:50:43Z</dc:date>
    </item>
  </channel>
</rss>

