<?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のトピックRe: LPC55S16-EVK - Temperature sensor reads</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S16-EVK-Temperature-sensor-reads/m-p/1409538#M47834</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/192990"&gt;@PabloAvalos&lt;/a&gt;, thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found the problem, I had to use different parameters for the ADC command&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  const lpadc_conv_command_config_t config = {
    .sampleChannelMode = kLPADC_SampleChannelDiffBothSide,
    .channelNumber = 26,
    .chainedNextCommandNumber = 0,
    .enableAutoChannelIncrement = false,
    .loopCount = FSL_FEATURE_LPADC_TEMP_SENS_BUFFER_SIZE - 1U,
    .hardwareAverageMode = kLPADC_HardwareAverageCount128,
    .sampleTimeMode = kLPADC_SampleTimeADCK131,
    .hardwareCompareMode = kLPADC_HardwareCompareDisabled,
    .hardwareCompareValueHigh = 0UL,
    .hardwareCompareValueLow = 0UL,
    .conversionResolutionMode = kLPADC_ConversionResolutionHigh,
    .enableWaitTrigger = false
  };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I had to reset the FIFOs after an ADC read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Feb 2022 08:35:00 GMT</pubDate>
    <dc:creator>embedded_eng_</dc:creator>
    <dc:date>2022-02-07T08:35:00Z</dc:date>
    <item>
      <title>LPC55S16-EVK - Temperature sensor reads</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S16-EVK-Temperature-sensor-reads/m-p/1407155#M47793</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm using&amp;nbsp;&lt;SPAN&gt;LPC55S16-EVK, and I'm trying to add temperature reads using the built in temperature sensor to my application.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I followed&amp;nbsp;lpcxpresso55s16_lpadc_temperature_measurement example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ADC initialization&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;void init_adc_peripheral()
{
  const lpadc_config_t config = {
    .enableInDozeMode = true,
    .conversionAverageMode = kLPADC_ConversionAverage128,
    .enableAnalogPreliminary = true,
    .powerUpDelay = 0x80UL,
    .referenceVoltageSource = ADC_REF,
    .powerLevelMode = kLPADC_PowerLevelAlt1,
    .triggerPriorityPolicy = kLPADC_TriggerPriorityPreemptImmediately,
    .enableConvPause = false,
    .convPauseDelay = 0UL,
    .FIFO0Watermark = 0UL,
    .FIFO1Watermark = 0UL
  };

  POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC);

  LPADC_Init(ADC_BASE, &amp;amp;config);

  LPADC_DoOffsetCalibration(ADC_BASE);

  LPADC_DoAutoCalibration(ADC_BASE);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Command initialization&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;void init_adc_command()
{
  const lpadc_conv_command_config_t config = {
    .sampleChannelMode = kLPADC_SampleChannelSingleEndSideA,
    .channelNumber = 26,
    .chainedNextCommandNumber = 0,
    .enableAutoChannelIncrement = false,
    .loopCount = 0UL,
    .hardwareAverageMode = kLPADC_HardwareAverageCount1,
    .sampleTimeMode = kLPADC_SampleTimeADCK3,
    .hardwareCompareMode = kLPADC_HardwareCompareDisabled,
    .hardwareCompareValueHigh = 0UL,
    .hardwareCompareValueLow = 0UL,
    .conversionResolutionMode = kLPADC_ConversionResolutionHigh,
    .enableWaitTrigger = false
  };

  LPADC_SetConvCommandConfig(ADC_BASE, 3, &amp;amp;config);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trigger&amp;nbsp;initialization&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;void init_adc_trigger()
{
  const lpadc_conv_trigger_config_t config = {
    .targetCommandId = 3,
    .delayPower = 0,
    .priority = 0,
    .channelAFIFOSelect = 0,
    .channelBFIFOSelect = 0,
    .enableHardwareTrigger = false
  };

  LPADC_SetConvTriggerConfig(ADC_BASE, 2, &amp;amp;config);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Function to read temperature sensor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;uint32_t read_adc()
{
  lpadc_conv_result_t config;

  /*trigger ADC read*/
  LPADC_DoSoftwareTrigger(ADC_BASE, 4);

  /*wait for result*/
  while (!LPADC_GetConvResult(ADC_BASE, &amp;amp;config, 0U)){};
  /*return data*/
  return (uint32_t) config.convValue;
}


float calculate_temperature()
{
  uint16_t Vbe1            = 0U;
  uint16_t Vbe8            = 0U;
  uint32_t convResultShift = 3U;
  float parameterSlope     = DEMO_LPADC_TEMP_PARAMETER_A;
  float parameterOffset    = DEMO_LPADC_TEMP_PARAMETER_B;
  float parameterAlpha     = DEMO_LPADC_TEMP_PARAMETER_ALPHA;
  float temperature        = -273.15f; /* Absolute zero degree as the incorrect return value. */

  /* If the temperature sensor need calibration, then read the calibration from the flash. */
  uint32_t temperatureSlopeSolidifyValue  = (*((volatile uint32_t *)(FSL_FEATURE_FLASH_NMPA_TEMP_SLOPE_ADDRS)));
  uint32_t temperatureOffsetSolidifyValue = (*((volatile uint32_t *)(FSL_FEATURE_FLASH_NMPA_TEMP_OFFSET_ADDRS)));

  if (((temperatureSlopeSolidifyValue &amp;amp; 0x1UL) != 0UL) &amp;amp;&amp;amp; ((temperatureOffsetSolidifyValue &amp;amp; 0x1UL) != 0UL))
  {
      /* Rejustify slope value and Offset value based on the calibration value. */
      parameterSlope  = ((float)(uint32_t)(temperatureSlopeSolidifyValue &amp;gt;&amp;gt; 1UL) / 1024.0f);
      parameterOffset = ((float)(uint32_t)(temperatureOffsetSolidifyValue &amp;gt;&amp;gt; 1UL) / 1024.0f);
  }


      Vbe1 = read_adc() &amp;gt;&amp;gt; convResultShift;

      Vbe8 = read_adc() &amp;gt;&amp;gt; convResultShift;
          /* Final temperature = A*[alpha*(Vbe8-Vbe1)/(Vbe8 + alpha*(Vbe8-Vbe1))] - B. */
          temperature = parameterSlope * (parameterAlpha * ((float)Vbe8 - (float)Vbe1) /
                                          ((float)Vbe8 + parameterAlpha * ((float)Vbe8 - (float)Vbe1))) -
                        parameterOffset;

  return temperature;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I get is around the value: 582.&lt;/P&gt;&lt;P&gt;What I'm doing wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jan 2022 15:52:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S16-EVK-Temperature-sensor-reads/m-p/1407155#M47793</guid>
      <dc:creator>embedded_eng_</dc:creator>
      <dc:date>2022-01-31T15:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55S16-EVK - Temperature sensor reads</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S16-EVK-Temperature-sensor-reads/m-p/1407831#M47809</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/185386"&gt;@embedded_eng_&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for reaching us in our community.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope you are well, I would like to ask, what did you change on the SDK example? and which SDK version you are using for the lpadc_temperature_measurement ? Because the conversion for temperature has to be ok.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will be here to help you, I really appreciate your reply. Please let me know if you have more concerns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards.&lt;BR /&gt;Pablo Avalos.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 03:57:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S16-EVK-Temperature-sensor-reads/m-p/1407831#M47809</guid>
      <dc:creator>PabloAvalos</dc:creator>
      <dc:date>2022-02-02T03:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55S16-EVK - Temperature sensor reads</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S16-EVK-Temperature-sensor-reads/m-p/1409538#M47834</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/192990"&gt;@PabloAvalos&lt;/a&gt;, thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found the problem, I had to use different parameters for the ADC command&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  const lpadc_conv_command_config_t config = {
    .sampleChannelMode = kLPADC_SampleChannelDiffBothSide,
    .channelNumber = 26,
    .chainedNextCommandNumber = 0,
    .enableAutoChannelIncrement = false,
    .loopCount = FSL_FEATURE_LPADC_TEMP_SENS_BUFFER_SIZE - 1U,
    .hardwareAverageMode = kLPADC_HardwareAverageCount128,
    .sampleTimeMode = kLPADC_SampleTimeADCK131,
    .hardwareCompareMode = kLPADC_HardwareCompareDisabled,
    .hardwareCompareValueHigh = 0UL,
    .hardwareCompareValueLow = 0UL,
    .conversionResolutionMode = kLPADC_ConversionResolutionHigh,
    .enableWaitTrigger = false
  };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I had to reset the FIFOs after an ADC read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 08:35:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S16-EVK-Temperature-sensor-reads/m-p/1409538#M47834</guid>
      <dc:creator>embedded_eng_</dc:creator>
      <dc:date>2022-02-07T08:35:00Z</dc:date>
    </item>
  </channel>
</rss>

