[MCX A153] Basics and Usage of the ADC Module (Japanese Blog) This article explains the basic usage of the ADC (Analog-to-Digital Converter) module installed in the MCX A153 . Starting with application examples using the ADC, it summarizes the main functions, block structure, and points to note when using it, and then introduces device initialization using SDK sample code and how to transfer ADC conversion results using DMA.
This article aims to help you understand the fundamentals required when using the MCX A153 ADC in your applications, enabling you to implement everything from initial setup for ADC conversion to efficient data transfer utilizing DMA.
table of contents
1. Common use cases in applications
1.1 Main Uses
1.2 Usage example
2. Main functions and block diagram of the MCX A153 ADC module
2.1 Overview
2.2 Main Features
2.3 Block Diagram
3. Points to note and restrictions
4. ADC Sample Code (Device Initialization)
4.1 Overview of Sample Code
4.2 Opening the SDK Sample Project
4.3 Macro Definitions
4.4 Device Initialization
5. Transfer of AD conversion values using MCX A153 DMA
5.1 Code related to ADC
5.2 DMA-related code
summary
1. Common use cases in applications
An ADC converts analog signals (continuously changing voltages) input from sensors, potentiometers, etc., into digital values (numerical values) that a microcontroller can use for calculations.
1.1 Main Uses
Converts the analog voltage value input from the potentiometer to a digital value.
A potentiometer is attached to the shaft of a servo motor, such as those used in radio-controlled vehicles, to detect the angle of rotation of the motor from the change in output.
Convert analog signals from various sensors into digital values.
It detects the tilt of an object by converting analog signals from an accelerometer. This can be applied to detecting the orientation of a smartphone, for example.
The ambient temperature is measured by converting the analog signal from the temperature sensor.
1.2 Usage Examples (These are examples illustrating the general concept, so details are omitted.)
Examples of potentiometer usage:
2. Main Functions and Block Diagram
2.1 Overview
The MCX A153 is equipped with a 16-bit analog-to-digital converter (ADC). An ADC is a circuit that converts analog voltages into digital values.
2.2 Main Features
Equipped with one successive approximation AD converter unit.
Supports 16-bit or 12-bit resolution and single-ended input (higher resolution allows for finer representation of input voltage).
Number of channels installed (varies depending on the package):
64-pin LQFP: 24 channels, 48-pin LQFP: 16 channels, 48-pin HVQFN: 18 channels, 32-pin HVQFN: 9 channels
Sampling rate (how many times per second the data can be converted)
16-bit mode: up to 3.2 Msps, 12-bit mode: up to 4 Msps
Sample time can be set.
Can operate in low-power mode of the microcontroller.
Supports four trigger sources (software or hardware triggers).
Seven command buffers enable scanning of consecutive channels.
Supports compare function (automatically compares smaller, larger, within range, outside range, save as match, etc.)
Equipped with eight FIFOs for conversion result data, featuring watermark and overflow detection functions.
Supports interrupts, DMA, and polling.
Calibration function
Built-in temperature sensor with dedicated input channel
2.3 Block Diagram
MCX A153 Reference Manual (MCXAP64M96FS3RM) Figure 165. Excerpt from ADC block diagram
Example of using SDK sample code (connecting a potentiometer)
3. MCX A153 ADC Module
This section explains important points and limitations to consider before using the MCX A153's ADC.
Speed reduction in 16-bit mode
The MCX A153's ADC supports two modes: 16-bit (ENOB16: 16-bit effective resolution) and 12-bit (ENOB12: 12-bit effective resolution). However, the 16-bit mode has a lower sampling rate than the 12-bit mode.
(Excerpt from MCX A153 DataSheet Table.34)
Timing of calibration execution
Calibration requests and execution must be performed during reset or power-on. Furthermore, the clock source and frequency must be configured before calibration can be performed.
Averaging of conversion results
The ADC module can average multiple results for the same channel before saving the conversion result. The hardware averaging function is enabled when the CMDHa[AVGS] bit field is set to a non-zero value. It can be used in any conversion mode and reduces the burden of calculating the average in software.
4. Sample code for AD conversion
4.1 Overview of Sample Code
When the main sequence is executed, device initialization is performed. Device initialization begins with setting the clock, configuring the external terminals, and selecting the peripherals to connect to the terminals. After that, the peripherals (ADC, UART) are initialized and interrupts are enabled. After the initialization process, a software trigger is set within the loop to start ADC conversion, and the AD conversion value and the number of conversions are displayed on the console.
For hardware, we will use the MCX A153 development board "FRDM-MCXA153".
4.2 Steps to open the ADC sample project in VS Code
4.2.1 Preparing VS Code and Extensions
Install VS Code.
Search for "MCUXpresso for VS Code" in the Extensions view (Ctrl+Shift+X) and install it.
The MCUXpresso icon will appear in the activity bar on the left. Click it to open the QUICKSTART PANEL.
4.2.2 Installing Dependent Tools
Run "Open MCUXpresso Installer" in the QUICKSTART PANEL.
Select and install the following tool.
Arm GNU Toolchain
CMake / Ninja
Python / West
Git
LinkServer (Debug probe for MCU-Link)
SDK-related tools
After completion, restart VS Code.
4.2.3Incorporating the SDK repository
Click "Import Repository" in the QUICKSTART PANEL.
Select "Remote" as the source for importing data.
Specify the destination folder. The path should be short and should not contain Japanese characters or spaces.
You can import the repository by checking "I agree" and pressing the Import button.
4.2.4 Importing Samples
In the QUICKSTART PANEL, click "Import Example from Repository".
Set it as follows:
You can import the project by clicking the Import button.
item
Set value
Repository
The SDK (frdm_mcxa153) imported in step 3
Toolchain
Arm GNU Toolchain
Board
frdmmcxa153 (FRDM-MCXA153)
Template
driver_examples → lpadc → interrupt(lpadc_interrupt)
Location
Project save location
Name
Optional (default is lpadc_interrupt)
4.3 Macro Definitions
This is the macro definition code for the ADC's functions (excerpted from lpadc\interrupt\app.h).
Please adjust the input channels, resolution settings, and reference voltage sources to match your actual circuit design and intended use.
Definitions
//(lpadc\interrupt\app.hから抜粋) /******************************************************************************/
#define DEMO_LPADC_BASE ADC0 //ADCのinstance、ベースアドレス、MCX A153は1個 ADCしかない
#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 //コマンドID
#define DEMO_LPADC_VREF_SOURCE kLPADC_ReferenceVoltageAlt3 //参考電圧ソース
#define DEMO_LPADC_DO_OFFSET_CALIBRATION true //オフセットキャリブレーションの利用可否
#define DEMO_LPADC_USE_HIGH_RESOLUTION true //高分解能の利用可否
Variables related to ADC
Variables
//(lpadc\interrupt\lpadc_interrupt.cから抜粋) 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 */
Defaulting of the ADC configuration structure (details can be found in fsl_lpadc.c), averaging of conversion results.
//(lpadc\interrupt\lpadc_interrupt.cから抜粋) LPADC_GetDefaultConfig(&mLpadcConfigStruct);
mLpadcConfigStruct.enableAnalogPreliminary = true; //ADCアナログ回路は事前に有効化され、起動遅延なしで変換を実行する準備
#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_ConversionAverage; //変換結果平均化設定、平均しない/2回の平均/4回の平均/8回の平均/16回の平均....1024回の平均化選択可能
#endif
4.4 Device Initialization
Initialization of clock division ratio
The CLOCK_SetClockDiv function handles the clock division settings used by the ADC peripheral.
//(lpadc\interrupt\hardware_init.cから抜粋) /* Attach peripheral clock */
CLOCK_SetClockDiv(kCLOCK_DivADC0, 1u);
div_name: Select a frequency divider defined by the enumeration.
value: division ratio
*The following code is the driver section starting with fsl_clock.c, and user modification is not recommended.
//(fsl_clock.cから抜粋) void CLOCK_SetClockDiv(clock_div_name_t div_name, uint32_t value)
{
volatile uint32_t *pDivCtrl = (volatile uint32_t *)(MRCC0_BASE + (uint32_t)div_name);
assert(div_name <= kCLOCK_DivMax);
/* Unlock clock configuration */
SYSCON->CLKUNLOCK &= ~SYSCON_CLKUNLOCK_UNLOCK_MASK;
/* halt and reset clock dividers */
*pDivCtrl = 0x3UL << 29U;
if (value == 0U) /*!< halt */
{
*pDivCtrl |= (1UL << 30U);
}
else
{
*pDivCtrl = (value - 1U);
}
/* Freeze clock configuration */
SYSCON->CLKUNLOCK |= SYSCON_CLKUNLOCK_UNLOCK_MASK;
}
Clock selection
CLOCK_AttachClk selects one of four clock sources to be used by the ADC peripheral.
The driver configures the connection by passing a value defined in the `clock_attach_id_t` structure as an argument to the `void CLOCK_AttachClk(clock_attach_id_t connection)` function.
//(fsl_clock.hから抜粋) kFRO12M_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 0U), /* Attach FRO12M to ADC0. */
kFRO_HF_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 1U), /* Attach FRO_HF to ADC0. */
kCLK_IN_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 3U), /* Attach CLK_IN to ADC0. */
kCLK_1M_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 5U), /* Attach CLK_1M to ADC0. */
kNONE_to_ADC0 = CLK_ATTACH_MUX(kCLOCK_SelADC0, 7U), /* Attach NONE to ADC0. */
//(lpadc\interrupt\hardware_init.cから抜粋) CLOCK_AttachClk(kFRO12M_to_ADC0);
The following functions are part of the driver section provided by the SDK, starting with fsl_clock.c, and it is not recommended that users modify them.
//(fsl_clock.hから抜粋) void CLOCK_AttachClk(clock_attach_id_t connection)
{
const uint32_t reg_offset = CLK_ATTACH_REG_OFFSET(connection);
const uint32_t clk_sel = CLK_ATTACH_CLK_SEL(connection);
if (kNONE_to_NONE != connection)
{
CLOCK_SetClockSelect((clock_select_name_t)reg_offset, clk_sel);
}
}
//(fsl_clock.hから抜粋) void CLOCK_SetClockSelect(clock_select_name_t sel_name, uint32_t value)
{
volatile uint32_t *pClkCtrl = (volatile uint32_t *)(MRCC0_BASE + (uint32_t)sel_name);
assert(sel_name <= kCLOCK_SelMax);
if (sel_name == kCLOCK_SelSCGSCS)
{
SCG0->RCCR = (SCG0->RCCR & ~(SCG_RCCR_SCS_MASK)) | SCG_RCCR_SCS(value);
while ((SCG0->CSR & SCG_CSR_SCS_MASK) != SCG_CSR_SCS(value))
{
}
}
else
{
/* Unlock clock configuration */
SYSCON->CLKUNLOCK &= ~SYSCON_CLKUNLOCK_UNLOCK_MASK;
*pClkCtrl = value;
/* Freeze clock configuration */
SYSCON->CLKUNLOCK |= SYSCON_CLKUNLOCK_UNLOCK_MASK;
}
}
Regarding the board initialization function
The clock will be initialized.
Pin initialization
The InitPins() function is called, and the pin_mux.c file is processed. The pin_mux.c file is used by NXP's MCUXPressoThis can be overridden using the Pin Config tool integrated into the IDE.
//(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitPins();
The BOARD_InitPins() function performs four operations.
Enable peripheral clock
Disable peripheral reset
External pin-to-pin and peripheral connection (MUX configuration) -> Parameter setting for the structure
Write 3 to the register
Initializing the boot clock
The MCX A153 supports Mid Drive Mode and Standard Drive Mode. These modes operate with VDD_CORE voltage levels of 1.0 V and 1.1 V, respectively, and with an rfo_hf clock of 48 MHz or 96 MHz. Switching modes requires external power supply and configuration of voltage-related registers such as the LDO.
//(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitBootClocks();
The clock is set using a register setting function that corresponds to the operating frequency.
//(fsl_clock.cから抜粋) void BOARD_InitBootClocks(void)
{
BOARD_BootClockFRO96M();
}
Initializing the debug port
//(lpadc\interrupt\hardware_init.cから抜粋) BOARD_InitDebugConsole();
//(board.cから抜粋) void BOARD_InitDebugConsole(void)
{
/* attach 12 MHz clock to LPUART0 (debug console) */
CLOCK_SetClockDiv(kCLOCK_DivLPUART0, 1u);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
RESET_PeripheralReset(BOARD_DEBUG_UART_RST);
DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE,
BOARD_DEBUG_UART_BAUDRATE,
BOARD_DEBUG_UART_TYPE,
BOARD_DEBUG_UART_CLK_FREQ);
}
Application initialization
ADC initialization is handled within the LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct); function. The LPADC_Init() function is a function in the driver section of fsl_lpadc.c.
DEMO_LPADC_BASE: 0x400A_F000 -> Starting address of the ADC
Define the structure table and configure the ADC.
typedef struct {} lpadc_config_t
name
attribute
explanation
lpadc_config_t
type
LPADC Configuration Parameter Information
enableInDozeMode
bool
Operation settings based on mode during ADC conversion
conversionAverageMode
lpadc_conversion_average_mode_t
Settings related to Auto Calibration
enableAnalogPreliminary
bool
ADC pre-startup settings
PowerUpDelay
uint32_t
Stabilization time of ADC circuit
referenceVoltageSource
lpadc_reference_voltage_source_t
Source of reference voltage
powerLevelMode
lpadc_power_level_mode_t
Power supply configuration selection
triggerPriorityPolicy
lpadc_trigger_priority_policy_t
How to process high-profitability triggers
EnableConvPause
bool
Setting the AD conversion execution interval.
convPauseDelay
uint32_t
Pause time during command sequence
FIFOWatermark
uint32_t
Threshold setting for the number of data points in FIFO
//(lpadc\interrupt\lpadc_interrupt.cから抜粋) LPADC_Init(DEMO_LPADC_BASE, &mLpadcConfigStruct);
//(fsl_lpadc.cから抜粋) void LPADC_Init(ADC_Type *base, const lpadc_config_t *config)
{
/* 省略 */
base->CTRL |= ADC_CTRL_CAL_AVGS(config->conversionAverageMode);
/* 省略 */
}
About ADC calibration
Before using an ADC, calibration is performed to correct for offset errors and other factors included in the conversion result, thereby improving the accuracy of the AD conversion.
The calibration process can be broadly divided into the following two stages:
Set the calibration mode and conditions.
Perform calibration and apply the correction values to the ADC.
In the default sample, ADC calibration is performed after LPADC_Init() is executed and before AD conversion begins. First, the offset calibration mode is set with LPADC_SetOffsetCalibrationMode() on the corresponding device. Then, if DEMO_LPADC_DO_OFFSET_CALIBRATION is enabled, LPADC_DoOffsetCalibration() is executed; otherwise, the offset value set in advance with LPADC_SetOffsetValue() is used.
Furthermore, if the corresponding function macro is enabled, LPADC_DoAutoCalibration() is executed after a delay of 1 µs or more. This performs calibration of gain errors and linearity errors. Each process is compiled only if the function macro supported by the device is enabled.
The following are the settings for the LPADC calibration mode.
//(lpadc\interrupt\lpadc_interrupt.cから抜粋) /* Request LPADC calibration. */
#if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE) && FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE
LPADC_SetOffsetCalibrationMode(DEMO_LPADC_BASE, DEMO_LPADC_OFFSET_CALIBRATION_MODE);
#endif /* FSL_FEATURE_LPADC_HAS_CTRL_CALOFSMODE */
Performing offset calibration
//(lpadc\interrupt\lpadc_interrupt.cから抜粋) #if defined(FSL_FEATURE_LPADC_HAS_CTRL_CALOFS) && \ FSL_FEATURE_LPADC_HAS_CTRL_CALOFS #if defined(DEMO_LPADC_DO_OFFSET_CALIBRATION) && \ DEMO_LPADC_DO_OFFSET_CALIBRATION L PADC_DoOffsetCalibration(DEMO_LPADC_BASE);
//キャリブレーションを実行しない場合 #else /* Update OFSTRIM register manually. */
5. MCX A153 DMA
Why use DMA transfer for ADC conversion?
When processing data acquired by an ADC solely in software, the CPU needs to monitor the completion of the ADC conversion, read the conversion results, and write them to memory. This is not a major problem for a single AD conversion, but when sampling continuously at regular intervals or when handling multiple input channels, this process occurs repeatedly. As a result, the CPU processing load increases, potentially reducing the time available for other application processing.
One way to solve this problem is to transfer the ADC conversion results using DMA (Direct Memory Access). Using DMA, the ADC conversion results can be automatically transferred to memory as soon as the ADC conversion is complete. In other words, since the process from acquiring the ADC conversion results to storing them in memory can be handled by hardware, the amount of data transfer processing performed by the CPU can be reduced, and the processing load on the software can be lowered.
For these reasons, configurations combining ADC and DMA are often used in applications requiring continuous AD conversion and high-speed data acquisition. This article will first explain the basic initialization method of the ADC, and then introduce how to transfer the ADC conversion result to memory using DMA with the MCX A153.
Overview of AD conversion value transfer using DMA
The data after AD conversion is stored in a buffer within the ADC peripheral. Instead of reading the data manually each time, the ADC may trigger DMA to transfer the data. For example, the program will be modified to perform AD conversion five times consecutively, then save the data to a RAM buffer via DMA, and display the average, minimum, and maximum values on the console.
Procedure for transferring AD conversion values using DMA
We will modify the ADC sample code to add DMA processing.
DMA activation is performed using a DMA Request signal from the ADC.
Using DMA, the ADC FIFO values (for 5 conversions) are copied to RAM, and an interrupt is notified to the CPU.
The CPU takes the average value within the main loop after the DMA transfer is complete and displays the min, max, and ave values to the console.
Precautions
To add DMA code, you need to add the DMA driver header file and source code to your project. The easiest way to do this is to create a sample DMA code (frdmmcxa153_edma3_memory_to_memory_transfer) from the MCUXpresso IDE and copy it. Simply copy the following files from the drivers directory.
fsl_edma_core.h
fsl_edma_soc.c
fsl_edma_soc.h
fsl_edma.c
fsl_edma.h
5.1 Code modifications and additions related to ADC
Code modification steps
The interrupt that occurs when ADC conversion is complete has been disabled.
Added ADC configuration.
Setting to perform AD conversion 5 times consecutively.
Enable DMA requests
Set the FIFO watermark to 4.
Added processing to obtain the average, minimum, and maximum values of the values transferred by DMA, and to output them to the console.
1. Disable interrupts when ADC conversion is complete.
Since the Interrupt Enable Register (IE) is enabled using the LPADC_EnableInterrupts() function and kLPADC_FIFOWatermarkInterruptEnable, we will comment out this line.
// LPADC_EnableInterrupts(DEMO_LPADC_BASE, kLPADC_FIFOWatermarkInterruptEnable);
2. Add ADC configuration
The ADC is configured to loop 5 times (= 5 AD conversions).
mLpadcCommandConfigStruct.loopCount = 4 //loopCount +1回の変換
Enable DMA requests
//178行目
LPADC_EnableFIFOWatermarkDMA(DEMO_LPADC_BASE, 1); // 1でDMA Requestがイネーブル
3. Set the number of Watermark levels in the FIFO to 4.
// 33行目
/* ++ ADCのマクロ */
#define FIFO0WatermarkLEVEL (4)
//108行目
mLpadcConfigStruct.FIFOWatermark = FIFO0WatermarkLEVEL;
4. Added processing to obtain the average, minimum, and maximum values of the values transferred by DMA, and console output.
uint32_t adc_values[5] = {0};
PRINTF("Please press any key to get user channel's ADC value.\r\n");
while(1)
{
GETCHAR();
EXAMPLE_DMA_BASEADDR->CH[0].CH_CSR = DMA_CH_CSR_ERQ(1);
EXAMPLE_DMA_BASEADDR->CH[0].TCD_DLAST_SGA = -0x14;
LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */
while (!g_Transfer_Done)
{
/* DMA転送終了割り込み待ち */
}
g_Transfer_Done = false;
uint16_t min=adc_values[0];
uint16_t max=adc_values[0];
uint32_t sum=0;
for(uint32_t i=0; i<5; i++)
{
if(max < (0x0000FFFF & adc_values[i]))
max = adc_values[i];
if(min > (0x0000FFFF & adc_values[i]))
min = adc_values[i];
sum += 0x0000FFFF & adc_values[i];
}
PRINTF("ADC Min: %d, Max: %d, ave: %d\r\n", min, max, sum/5);
for(size_t i=0; i<5; i++)
{
adc_values[i] = 0;
}
sum = 0;
}
5.2 Adding DMA-related code
Code Addition Policy
Include header files
Added DMA-related macros.
DMA configuration and initialization
DMA transfer configuration
DMA transfer completion interrupt handling
1. Include headers
// 10行目
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_lpadc.h"
/* ++ */
#include "fsl_edma.h" // DMAドライバヘッダファイルの追加
#include "fsl_clock.h"
#include "fsl_reset.h"
2. Add DMA-related macros.
// 32行目
#define EXAMPLE_DMA_BASEADDR DMA0
#define DEMO_DMA_CHANNEL_0 0U
#define APP_DMA_IRQ DMA_CH0_IRQn
#define APP_DMA_IRQ_HANDLER DMA_CH0_IRQHandler
3. DMA Configuration
// 197行目
edma_transfer_config_t transferConfig;
edma_config_t userConfig;
// 203行目
RESET_PeripheralReset(kDMA_RST_SHIFT_RSTn);
/* Configure EDMA channel for one shot transfer */
EDMA_GetDefaultConfig(&userConfig);
EDMA_Init(EXAMPLE_DMA_BASEADDR, &userConfig);
4. DMA transfer configuration
// 209行目
EDMA_PrepareTransfer(&transferConfig,
(void *)0x400AF300, // eDMA transfer source address.
sizeof(uint32_t), // eDMA transfer source address width(bytes)
(void *)adc_values, // eDMA transfer destination address
sizeof(&adc_values), // eDMA transfer destination address width(bytes)
sizeof(adc_values), // eDMA transfer bytes per channel request
sizeof(adc_values), // eDMA transfer bytes to be transferred
kEDMA_PeripheralToMemory // eDMA transfer type
);
EDMA_SetTransferConfig(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, &transferConfig, NULL);
EDMA_SetChannelMux(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kDma0RequestMuxAdc0FifoRequest);
EnableIRQ(APP_DMA_IRQ);
EDMA_EnableChannelInterrupts(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kEDMA_MajorInterruptEnable);
Before starting the software ADC with a software trigger, add EDMA_TriggerChannelStart() to trigger an interrupt on DMA channel 0. When the DMA interrupt flag is cleared, DMA-triggered interrupts are disabled, so this processing is added before the ADC's software trigger.
// 242行目
while(1)
{
GETCHAR();
EDMA_TriggerChannelStart(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0);
EXAMPLE_DMA_BASEADDR->CH[0].TCD_DLAST_SGA = -0x14;
LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, 1U); /* 1U is trigger0 mask. */
while (!g_Transfer_Done)
{
/* DMA転送終了割り込み待ち */
}
g_Transfer_Done = false;
5. DMA transfer completion interrupt handling
void APP_DMA_IRQ_HANDLER(void)
{
if ((EDMA_GetChannelStatusFlags(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0) & kEDMA_InterruptFlag) != 0U)
{
EDMA_ClearChannelStatusFlags(EXAMPLE_DMA_BASEADDR, DEMO_DMA_CHANNEL_0, kEDMA_InterruptFlag);
g_Transfer_Done = true;
}
}
summary:
This article explained the basic functions and points to note about the MCX A153 ADC, as well as the initialization and conversion process using the VS Code SDK's ADC sample project . Following the latter part of this article, you should be able to see configuration examples and code flows that will be useful in actual development, from initialization and conversion using the ADC sample to automatic transfer of conversion results using DMA. (It's easier to isolate problems if you first run the ADC sample and confirm its operation before adding DMA.)
=========================
We are currently unable to respond to comments left in the " Comment " section of this post .
We apologize for the inconvenience, but please refer to " Technical Questions to NXP - How to Contact Us( Japanese Blog) " when making inquiries.
(If you are already an NXP distributor or have a relationship with NXP, you may ask your representative directly.)
This article explains everything from the basics of the ADC (analog-to-digital converter) in the MCX A153 , to initialization using the MCUXpresso SDK, and even automatic transfer of conversion results using DMA. If you are using ADC or DMA for the first time, it is recommended to first review the overall picture in Chapters 1 and 2, and then proceed to the sample code in Chapter 4 and the DMA settings in Chapter 5 for easier understanding.
ADC: A function that converts analog signals, such as those from sensors, into digital values that can be handled by a microcontroller.
DMA: A function that transfers data between peripherals and memory without going through the CPU.
SDK: A development kit containing drivers and sample code necessary for software development.
(Reading time: 30 minutes) General Purpose Microcontrollers Introduction MCUXpresso IDE MCUXpresso SDK Japanese Blog
View full article