Analog Input/ADC (LPC55S06-EVK)

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

Analog Input/ADC (LPC55S06-EVK)

Jump to solution
1,478 Views
caden013
Contributor III

Hi all, 

I am trying to figure out how to accept analog input into my board (LPC55S06-EVK). Furthermore, I also want to use the ADC to convert this into data that I can use. However, I am lost on how to do so. Can I take in analog input independently from the ADC, or are these two intricately tied together?

In the MCUXpresso SDK API Reference Manual, which section should I be studying? Right now I just want to take in one analog input signal and convert this into digital data that I can evaluate in my program. 

 

Thanks in advance.

0 Kudos
1 Solution
1,440 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I am sorry, I mean the connector  J13 rather the J23 for the ADC0_0 channel, in detail, pls connect the Pin8 of J13 to VDDA or GND and check the result.

In the SDK package, we have an example as the following screenshot:

The example use the lpadc_interrupt.c, I do not know where the lpadc_temperature_measurement.c is

xiangjun_rong_0-1623035907944.png

Hope it can help you

BR

Xiang

View solution in original post

0 Kudos
5 Replies
1,471 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Caden,

First of all, I suggest you download SDK package for the LPC55S06-EVK board from the link:

https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-s...

 

You can follow up the following screenshot to load the ADC example.

xiangjun_rong_0-1622775865991.png

In the above example, it use the ADC0_0 channel(P0_23 pin), in other words, it sample P0_23 pin voltage of LPC55S06.

xiangjun_rong_1-1622776117877.png

 

From the above schematics of LPC55S05-EVK, you can see that the P0_23 is connected to pin8 or pin3 of J23 connector.

In conclusion, you can use a cable with hole end, and connect pin3 of J23 to GND or VDD or any other voltage and check the sample with the example lpadc

Hope it can help you

BR

XiangJun Rong

0 Kudos
1,465 Views
caden013
Contributor III

Looking through the schematic, I do not see a J23 anywhere in the document. Perhaps you meant to type J13, but either way the example project is not displaying the analog values from my input to A3 (pin3/P0_23). I understand that the demo example project (lpadc_temperature_measurement.c) uses the on-board temperature sensor, but I am wanting to take in analog voltage inputs and be able to use these values. 

0 Kudos
1,441 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I am sorry, I mean the connector  J13 rather the J23 for the ADC0_0 channel, in detail, pls connect the Pin8 of J13 to VDDA or GND and check the result.

In the SDK package, we have an example as the following screenshot:

The example use the lpadc_interrupt.c, I do not know where the lpadc_temperature_measurement.c is

xiangjun_rong_0-1623035907944.png

Hope it can help you

BR

Xiang

0 Kudos
1,435 Views
caden013
Contributor III

The following is the code that I am using (the lpadc_interrupt.c example project):

/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "fsl_debug_console.h"
#include "board.h"
#include "fsl_lpadc.h"

#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_inputmux.h"
#include "fsl_power.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define DEMO_LPADC_BASE ADC0
#define DEMO_LPADC_IRQn ADC0_IRQn
#define DEMO_LPADC_IRQ_HANDLER_FUNC ADC0_IRQHandler
#define DEMO_LPADC_USER_CHANNEL 0U
#define DEMO_LPADC_USER_CMDID 1U /* CMD1 */
#define DEMO_LPADC_VREF_SOURCE kLPADC_ReferenceVoltageAlt2
#define DEMO_LPADC_DO_OFFSET_CALIBRATION true
#define DEMO_LPADC_USE_HIGH_RESOLUTION true

/*******************************************************************************
* Prototypes
******************************************************************************/

/*******************************************************************************
* Variables
******************************************************************************/

volatile bool g_LpadcConversionCompletedFlag = false;
volatile uint32_t g_LpadcInterruptCounter = 0U;
lpadc_conv_result_t g_LpadcResultConfigStruct;
#if (defined(DEMO_LPADC_USE_HIGH_RESOLUTION) && DEMO_LPADC_USE_HIGH_RESOLUTION)
const uint32_t g_LpadcFullRange = 65536U;
const uint32_t g_LpadcResultShift = 0U;
#else
const uint32_t g_LpadcFullRange = 4096U;
const uint32_t g_LpadcResultShift = 3U;
#endif /* DEMO_LPADC_USE_HIGH_RESOLUTION */

/*******************************************************************************
* Code
******************************************************************************/
void DEMO_LPADC_IRQ_HANDLER_FUNC(void)
{
g_LpadcInterruptCounter++;
#if (defined(FSL_FEATURE_LPADC_FIFO_COUNT) && (FSL_FEATURE_LPADC_FIFO_COUNT == 2U))
if (LPADC_GetConvResult(DEMO_LPADC_BASE, &g_LpadcResultConfigStruct, 0U))
#else
if (LPADC_GetConvResult(DEMO_LPADC_BASE, &g_LpadcResultConfigStruct))
#endif /* FSL_FEATURE_LPADC_FIFO_COUNT */
{
g_LpadcConversionCompletedFlag = true;
}
SDK_ISR_EXIT_BARRIER;
}

/*!
* @brief Main function
*/
int main(void)
{
lpadc_config_t mLpadcConfigStruct;
lpadc_conv_trigger_config_t mLpadcTriggerConfigStruct;
lpadc_conv_command_config_t mLpadcCommandConfigStruct;

/* attach main clock divide to FLEXCOMM0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

BOARD_InitPins();
BOARD_BootClockFROHF96M();
BOARD_InitDebugConsole();

/* Set clock source for ADC0 */
CLOCK_SetClkDiv(kCLOCK_DivAdcAsyncClk, 2U, true);
CLOCK_AttachClk(kFRO_HF_to_ADC_CLK);

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

PRINTF("LPADC Interrupt Example\r\n");

LPADC_GetDefaultConfig(&mLpadcConfigStruct);
mLpadcConfigStruct.enableAnalogPreliminary = true;
#if defined(DEMO_LPADC_VREF_SOURCE)
mLpadcConfigStruct.referenceVoltageSource = DEMO_LPADC_VREF_SOURCE;
#endif /* DEMO_LPADC_VREF_SOURCE */
#if defined(FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS) && FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS
mLpadcConfigStruct.conversionAverageMode = kLPADC_ConversionAverage128;
#endif /* FSL_FEATURE_LPADC_HAS_CTRL_CAL_AVGS */
LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct);

#if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFS) && FSL_FEATURE_LPADC_HAS_CTRL_CALOFS
#if defined(FSL_FEATURE_LPADC_HAS_OFSTRIM) && FSL_FEATURE_LPADC_HAS_OFSTRIM
/* Request offset calibration. */
#if defined(DEMO_LPADC_DO_OFFSET_CALIBRATION) && DEMO_LPADC_DO_OFFSET_CALIBRATION
LPADC_DoOffsetCalibration(DEMO_LPADC_BASE);
#else
LPADC_SetOffsetValue(DEMO_LPADC_BASE, DEMO_LPADC_OFFSET_VALUE_A, DEMO_LPADC_OFFSET_VALUE_B);
#endif /* DEMO_LPADC_DO_OFFSET_CALIBRATION */
#endif /* FSL_FEATURE_LPADC_HAS_OFSTRIM */
/* Request gain calibration. */
LPADC_DoAutoCalibration(DEMO_LPADC_BASE);
#endif /* FSL_FEATURE_LPADC_HAS_CTRL_CALOFS */

#if (defined(FSL_FEATURE_LPADC_HAS_CFG_CALOFS) && FSL_FEATURE_LPADC_HAS_CFG_CALOFS)
/* Do auto calibration. */
LPADC_DoAutoCalibration(DEMO_LPADC_BASE);
#endif /* FSL_FEATURE_LPADC_HAS_CFG_CALOFS */

/* Set conversion CMD configuration. */
LPADC_GetDefaultConvCommandConfig(&mLpadcCommandConfigStruct);
mLpadcCommandConfigStruct.channelNumber = DEMO_LPADC_USER_CHANNEL;
#if defined(DEMO_LPADC_USE_HIGH_RESOLUTION) && DEMO_LPADC_USE_HIGH_RESOLUTION
mLpadcCommandConfigStruct.conversionResolutionMode = kLPADC_ConversionResolutionHigh;
#endif /* DEMO_LPADC_USE_HIGH_RESOLUTION */
LPADC_SetConvCommandConfig(DEMO_LPADC_BASE, DEMO_LPADC_USER_CMDID, &mLpadcCommandConfigStruct);

/* Set trigger configuration. */
LPADC_GetDefaultConvTriggerConfig(&mLpadcTriggerConfigStruct);
mLpadcTriggerConfigStruct.targetCommandId = DEMO_LPADC_USER_CMDID; /* CMD15 is executed. */
mLpadcTriggerConfigStruct.enableHardwareTrigger = false;
LPADC_SetConvTriggerConfig(DEMO_LPADC_BASE, 0U, &mLpadcTriggerConfigStruct); /* Configurate the trigger0. */

/* Enable the watermark interrupt. */
#if (defined(FSL_FEATURE_LPADC_FIFO_COUNT) && (FSL_FEATURE_LPADC_FIFO_COUNT == 2U))
LPADC_EnableInterrupts(DEMO_LPADC_BASE, kLPADC_FIFO0WatermarkInterruptEnable);
#else
LPADC_EnableInterrupts(DEMO_LPADC_BASE, kLPADC_FIFOWatermarkInterruptEnable);
#endif /* FSL_FEATURE_LPADC_FIFO_COUNT */
EnableIRQ(DEMO_LPADC_IRQn);

PRINTF("ADC Full Range: %d\r\n", g_LpadcFullRange);
#if defined(FSL_FEATURE_LPADC_HAS_CMDL_CSCALE) && FSL_FEATURE_LPADC_HAS_CMDL_CSCALE
if (kLPADC_SampleFullScale == mLpadcCommandConfigStruct.sampleScaleMode)
{
PRINTF("Full channel scale (Factor of 1).\r\n");
}
else if (kLPADC_SamplePartScale == mLpadcCommandConfigStruct.sampleScaleMode)
{
PRINTF("Divided input voltage signal. (Factor of 30/64).\r\n");
}
#endif

/* When the number of datawords stored in the ADC Result FIFO is greater
* than watermark value(0U), LPADC watermark interrupt would be triggered.
*/
PRINTF("Please press any key to get user channel's ADC value.\r\n");
while (1)
{
GETCHAR();
LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */
while (!g_LpadcConversionCompletedFlag)
{
}
PRINTF("ADC value: %d\r\nADC interrupt count: %d\r\n",
((g_LpadcResultConfigStruct.convValue) >> g_LpadcResultShift), g_LpadcInterruptCounter);
g_LpadcConversionCompletedFlag = false;
}
}

 

And this is the result that I receive (which is not the value of the analog signal): 

LPADC Inget user channel's ADC value.
LPADC Interrupt Example
ADC Full Range: 65536
Please press any key to get user channel's ADC value.

 

How do I need to edit this code to give me the values that I am wanting?

0 Kudos
1,423 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I am bust today, I will test it on the LPC5506-EVK board tomorrow.

BR

XiangJun Rong