LPC55s69 ADC and internal temperature sensor do not work together

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

LPC55s69 ADC and internal temperature sensor do not work together

1,036 Views
rkulkarni
Contributor I

I am trying to run the internal ADC and the internal temperature sensor together in LPC55s69-EVK board. I am able to run both separately but when tried together, the temperature sensor gives very high values. I suspect there is some problem with ADC configuration when running both together. I am attaching the ADC initializations for both below. I am initializing the ADC then taking channel 0 value, then again initializing ADC for temperature sensor and then taking temperature values. Thank you for your help in advance.

For ADC:

  LPADC_DoResetConfig(ADC_LPADC_BASE);

  CLOCK_SetClkDiv(kCLOCK_DivAdcAsyncClk, 8U, true);
  CLOCK_AttachClk(kMAIN_CLK_to_ADC_CLK);

  /* Disable LDOGPADC power down */
  POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC);

  ANACTRL_Init(ANACTRL);
  ANACTRL_EnableVref1V(ANACTRL, true);

  LPADC_GetDefaultConfig(&mLpadcConfigStruct);
  mLpadcConfigStruct.enableAnalogPreliminary = true;

  mLpadcConfigStruct.referenceVoltageSource = ADC_LPADC_VREF_SOURCE;
  mLpadcConfigStruct.conversionAverageMode = kLPADC_ConversionAverage128;

  LPADC_Init(ADC_LPADC_BASE, &mLpadcConfigStruct);

  LPADC_SetOffsetValue(ADC_LPADC_BASE, ADC_LPADC_OFFSET_VALUE_A,
                       ADC_LPADC_OFFSET_VALUE_B);
  LPADC_DoAutoCalibration(ADC_LPADC_BASE);

  LPADC_GetDefaultConvCommandConfig(&mLpadcCommandConfigStruct);
  mLpadcCommandConfigStruct.channelNumber = ADC_LPADC_USER_CHANNEL;

  LPADC_SetConvCommandConfig(ADC_LPADC_BASE, ADC_LPADC_USER_CMDID,
                             &mLpadcCommandConfigStruct);

  /* Set trigger configuration. */
  LPADC_GetDefaultConvTriggerConfig(&mLpadcTriggerConfigStruct);
  mLpadcTriggerConfigStruct.targetCommandId = ADC_LPADC_USER_CMDID;
  mLpadcTriggerConfigStruct.enableHardwareTrigger = false;
  LPADC_SetConvTriggerConfig(
      ADC_LPADC_BASE, 0U,
      &mLpadcTriggerConfigStruct); /* Configurate the trigger0.*/
 
For temperature sensor:
LPADC_DoResetConfig(DEMO_LPADC_BASE);
   
    BOARD_BootClockPLL1_150M();
    CLOCK_AttachClk(kEXT_CLK_to_PLL0);  /*!< Switch PLL0CLKSEL to EXT_CLK */
    POWER_DisablePD(kPDRUNCFG_PD_PLL0); /* Ensure PLL is on  */
    POWER_DisablePD(kPDRUNCFG_PD_PLL0_SSCG);
    const pll_setup_t pll0Setup = {
        .pllctrl = SYSCON_PLL0CTRL_CLKEN_MASK | SYSCON_PLL0CTRL_SELI(19U) | SYSCON_PLL0CTRL_SELP(9U),
        .pllndec = SYSCON_PLL0NDEC_NDIV(1U),
        .pllpdec = SYSCON_PLL0PDEC_PDIV(16U),
        .pllsscg = {0x0U, (SYSCON_PLL0SSCG1_MDIV_EXT(32U) | SYSCON_PLL0SSCG1_SEL_EXT_MASK)},
        .pllRate = 16000000U,
        .flags   = PLL_SETUPFLAG_WAITLOCK};
    CLOCK_SetPLL0Freq(&pll0Setup);

    CLOCK_SetClkDiv(kCLOCK_DivAdcAsyncClk, 0U, true);  /*!< Reset ADCCLKDIV divider counter and halt it */
    CLOCK_SetClkDiv(kCLOCK_DivAdcAsyncClk, 4U, false); /*!< Set ADCCLKDIV divider to value 4 */

    CLOCK_AttachClk(kPLL0_to_ADC_CLK); /*!< Switch ADC_CLK to PLL0 */

    /* Disable LDOGPADC power down */
    POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC);
    /* Disable Temperature sensor power down. */
    POWER_DisablePD(kPDRUNCFG_PD_TEMPSENS);

    ANACTRL_Init(ANACTRL);
    ANACTRL_EnableVref1V(ANACTRL, true);
   
    LPADC_GetDefaultConfig(&lpadcConfigStruct);
    lpadcConfigStruct.enableAnalogPreliminary = true;
    lpadcConfigStruct.powerLevelMode          = kLPADC_PowerLevelAlt4;

    lpadcConfigStruct.referenceVoltageSource = DEMO_LPADC_VREF_SOURCE;
    lpadcConfigStruct.conversionAverageMode = kLPADC_ConversionAverage128;
    lpadcConfigStruct.FIFO0Watermark = FSL_FEATURE_LPADC_TEMP_SENS_BUFFER_SIZE - 1U;

    LPADC_Init(DEMO_LPADC_BASE, &lpadcConfigStruct);

    LPADC_DoResetFIFO0(DEMO_LPADC_BASE);
    LPADC_SetOffsetValue(DEMO_LPADC_BASE, DEMO_LPADC_OFFSET_VALUE_A, DEMO_LPADC_OFFSET_VALUE_B);
    LPADC_DoAutoCalibration(DEMO_LPADC_BASE);

    LPADC_GetDefaultConvCommandConfig(&g_LpadcCommandConfigStruct);
    g_LpadcCommandConfigStruct.channelNumber       = DEMO_LPADC_TEMP_SENS_CHANNEL;
    g_LpadcCommandConfigStruct.sampleChannelMode   = DEMO_LPADC_SAMPLE_CHANNEL_MODE;
    g_LpadcCommandConfigStruct.sampleTimeMode      = kLPADC_SampleTimeADCK131;
    g_LpadcCommandConfigStruct.hardwareAverageMode = kLPADC_HardwareAverageCount128;

    g_LpadcCommandConfigStruct.loopCount = FSL_FEATURE_LPADC_TEMP_SENS_BUFFER_SIZE - 1U;
    g_LpadcCommandConfigStruct.conversionResolutionMode = kLPADC_ConversionResolutionHigh;

    LPADC_SetConvCommandConfig(DEMO_LPADC_BASE, DEMO_LPADC_USER_CMDID, &g_LpadcCommandConfigStruct);

    /* Set trigger configuration. */
    LPADC_GetDefaultConvTriggerConfig(&lpadcTriggerConfigStruct);
    lpadcTriggerConfigStruct.targetCommandId = DEMO_LPADC_USER_CMDID;
    LPADC_SetConvTriggerConfig(DEMO_LPADC_BASE, 0U, &lpadcTriggerConfigStruct); /* Configurate the trigger0. */
Labels (2)
0 Kudos
Reply
2 Replies

1,024 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I see that you want to sample both ADC channel 0 and internal temperature sensor, for the case, I suggest you use one command ID and use analog channel chain to chain the ADC channel0 and temperature sensor.

I suggest you refer to the community:

https://community.nxp.com/t5/LPC-Microcontrollers-Knowledge/Multiple-ADC-channels-conversion-with-CT...

 

Hope it is helpful

BR

XiangJun Rong

0 Kudos
Reply

999 Views
rkulkarni
Contributor I
Okay will try this once, Thanks!
0 Kudos
Reply