MCXA156VLL ADC mulit channel read with DMA

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

MCXA156VLL ADC mulit channel read with DMA

Jump to solution
1,207 Views
yaowei
Contributor II

Hi,

I am using the FRDMMCXA156 board and referring to the SDK (25.09.00) example lpadc_edma.
 
The example only shows how to read one ADC channel using LPTMR and DMA.
 
However, I need to read 7 ADC channels, and the trigger ID only 0 to 3. How can I perform multi-channel ADC read with DMA?
Labels (2)
Tags (2)
0 Kudos
Reply
1 Solution
1,170 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @yaowei 

You can use a single trigger source to collect multiple channels.

You can concatenate multiple sampling commands under a trigger source, allowing the ADC to automatically sample 7 channels in sequence after triggering.

The chainedNextCommandNumber field allows the ADC to automatically execute the next command after completing a sample.

BR

Harry

View solution in original post

0 Kudos
Reply
4 Replies
1,105 Views
yaowei
Contributor II

Hi @Harry_Zhang

Thank you very much for your reply. I was able to achieve my goal using chainedNextCommandNumber, but I still have a few questions.

I'm using LPTIMER to trigger both ADC0 and ADC1, and I'm transferring the ADC data using DMA0 Channel 0 and Channel 1. The reason I use two DMA channels is because lpadcDmaChnlConfig.channelRequestSource can only be set to either kDma0RequestMuxAdc1FifoRequest or kDma0RequestMuxAdc0FifoRequest.

In this case, is it possible to use only one DMA channel to handle both ADCs?



Thanks

0 Kudos
Reply
458 Views
346500452
Contributor III

hi,


   I noticed that DMA has a loop function and channel link. 

   Could you please tell me how you implemented this function?

Thank Y

0 Kudos
Reply
442 Views
yaowei
Contributor II

I use the DMA to Trigger ADC,
DMA CH0 -> ADC0 CH0 CH1 CH4
DMA CH1 -> ADC0 CH8 CH9 CH12 CH13

Here is part of my code.

/* Set trigger configuration. */
LPADC_GetDefaultConvTriggerConfig(&lpadcTriggerConfig);
lpadcTriggerConfig.targetCommandId = chainedCommandList[0];
lpadcTriggerConfig.enableHardwareTrigger = TRUE;
LPADC_SetConvTriggerConfig(halAdcConfig->base, (eHAL_TRIGGER_ID)triId, &lpadcTriggerConfig);

 

 

/*==========================
* ADC0 with DMA0 channel0
*==========================*/

/* Configure DMA channel for ADC1 FIFO transfer */
channel = eHAL_DMA_CHANNEL0;
irq = DMA_CH0_IRQn;
/* Cehck DMA channel is not Initialized */
ASSERT(!HAL_DMA_IsChannelInitialized(eHAL_DMA0, channel));

/* Set EDMA channel configuration parameters */
lpadcDmaChnlConfig.channelDataSignExtensionBitPosition = 0U;
lpadcDmaChnlConfig.channelPreemptionConfig.enableChannelPreemption = FALSE;
lpadcDmaChnlConfig.channelPreemptionConfig.enablePreemptAbility = TRUE;
lpadcDmaChnlConfig.channelRequestSource = kDma0RequestMuxAdc1FifoRequest;
lpadcDmaChnlConfig.protectionLevel = kEDMA_ChannelProtectionLevelUser;

/* Configure EDMA channel for one shot transfer */
edma_config_t userConfig;
/*
* config.enableContinuousLinkMode = false;
* config.enableHaltOnError = true;
* config.enableRoundRobinArbitration = false;
* config.enableDebugMode = false;
*/
EDMA_GetDefaultConfig(&userConfig);
EDMA_Init(base, &userConfig);

/* Set source address to ADC1 FIFO register */
srcAddr = (UINT32 *)&(s_adcConfig[eHAL_ADC1].base->RESFIFO);
destAddr = (UINT32 *)adcRawValue;

/* Prepare transfer configuration for one-shot peripheral-to-memory transfer */
EDMA_PrepareTransfer(&transferConfig,
srcAddr , sizeof(UINT32),
&destAddr[ADC1_DMA_DEST_START], sizeof(destAddr[0]),
sizeof(destAddr[0]),
sizeof(UINT32) * ADC1_DMA_DEST_LENGTH,
kEDMA_PeripheralToMemory);

/* Used to change the destination address to the original value */
transferConfig.dstMajorLoopOffset = (INT32)((-1) * sizeof(UINT32) * ADC1_DMA_DEST_LENGTH);

0 Kudos
Reply
1,171 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @yaowei 

You can use a single trigger source to collect multiple channels.

You can concatenate multiple sampling commands under a trigger source, allowing the ADC to automatically sample 7 channels in sequence after triggering.

The chainedNextCommandNumber field allows the ADC to automatically execute the next command after completing a sample.

BR

Harry

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2199636%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EMCXA156VLL%20ADC%20mulit%20channel%20read%20with%20DMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2199636%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CDIV%3E%3CSPAN%3EI%20%3C%2FSPAN%3E%3CSPAN%3Eam%20%3C%2FSPAN%3E%3CSPAN%3Eusing%20%3C%2FSPAN%3E%3CSPAN%3Ethe%20%3C%2FSPAN%3E%3CSPAN%3EFRDMMCXA156%20%3C%2FSPAN%3E%3CSPAN%3Eboard%20%3C%2FSPAN%3E%3CSPAN%3Eand%20%3C%2FSPAN%3E%3CSPAN%3Ereferring%20%3C%2FSPAN%3E%3CSPAN%3Eto%20%3C%2FSPAN%3E%3CSPAN%3Ethe%20%3C%2FSPAN%3E%3CSPAN%3ESDK%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E(25.09.00)%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Eexample%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Elpadc_edma.%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EThe%20%3C%2FSPAN%3E%3CSPAN%3Eexample%20%3C%2FSPAN%3E%3CSPAN%3Eonly%20%3C%2FSPAN%3E%3CSPAN%3Eshows%20%3C%2FSPAN%3E%3CSPAN%3Ehow%20%3C%2FSPAN%3E%3CSPAN%3Eto%20%3C%2FSPAN%3E%3CSPAN%3Eread%20%3C%2FSPAN%3E%3CSPAN%3Eone%20%3C%2FSPAN%3E%3CSPAN%3EADC%20%3C%2FSPAN%3E%3CSPAN%3Echannel%20%3C%2FSPAN%3E%3CSPAN%3Eusing%20%3C%2FSPAN%3E%3CSPAN%3ELPTMR%20%3C%2FSPAN%3E%3CSPAN%3Eand%20%3C%2FSPAN%3E%3CSPAN%3EDMA.%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EHowever%2C%20%3C%2FSPAN%3E%3CSPAN%3EI%20%3C%2FSPAN%3E%3CSPAN%3Eneed%20%3C%2FSPAN%3E%3CSPAN%3Eto%20%3C%2FSPAN%3E%3CSPAN%3Eread%20%3C%2FSPAN%3E%3CSPAN%3E7%20%3C%2FSPAN%3E%3CSPAN%3EADC%20%3C%2FSPAN%3E%3CSPAN%3Echannels%2C%20%3C%2FSPAN%3E%3CSPAN%3Eand%20%3C%2FSPAN%3E%3CSPAN%3Ethe%20%3C%2FSPAN%3E%3CSPAN%3Etrigger%20%3C%2FSPAN%3E%3CSPAN%3EID%20only%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E0%20%3C%2FSPAN%3E%3CSPAN%3Eto%20%3C%2FSPAN%3E%3CSPAN%3E3.%20%3C%2FSPAN%3E%3CSPAN%3EHow%20%3C%2FSPAN%3E%3CSPAN%3Ecan%20%3C%2FSPAN%3E%3CSPAN%3EI%20%3C%2FSPAN%3E%3CSPAN%3Eperform%20%3C%2FSPAN%3E%3CSPAN%3Emulti-%3C%2FSPAN%3E%3CSPAN%3Echannel%20%3C%2FSPAN%3E%3CSPAN%3EADC%20%3C%2FSPAN%3E%3CSPAN%3Eread%20%3C%2FSPAN%3E%3CSPAN%3Ewith%20%3C%2FSPAN%3E%3CSPAN%3EDMA%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2199636%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EAnalog(ADC%7CCMP%7CDAC%7COpAmps)%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMCXA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2201611%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MCXA156VLL%20ADC%20mulit%20channel%20read%20with%20DMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2201611%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CSPAN%3EHi%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F229957%22%20target%3D%22_blank%22%3E%40Harry_Zhang%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EThank%20you%20very%20much%20for%20your%20reply.%20I%20was%20able%20to%20achieve%20my%20goal%20using%20%3CSTRONG%3EchainedNextCommandNumber%3C%2FSTRONG%3E%2C%20but%20I%20still%20have%20a%20few%20questions.%3C%2FP%3E%3CP%3EI'm%20using%20LPTIMER%20to%20trigger%20both%20ADC0%20and%20ADC1%2C%20and%20I'm%20transferring%20the%20ADC%20data%20using%20DMA0%20Channel%200%20and%20Channel%201.%20The%20reason%20I%20use%20two%20DMA%20channels%20is%20because%20%3CSTRONG%3ElpadcDmaChnlConfig%3C%2FSTRONG%3E.%3CSTRONG%3EchannelRequestSource%3C%2FSTRONG%3E%20can%20only%20be%20set%20to%20either%20%3CSTRONG%3EkDma0RequestMuxAdc1FifoRequest%3C%2FSTRONG%3E%20or%20%3CSTRONG%3EkDma0RequestMuxAdc0FifoRequest%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3EIn%20this%20case%2C%20is%20it%20possible%20to%20use%20only%20one%20DMA%20channel%20to%20handle%20both%20ADCs%3F%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2199983%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MCXA156VLL%20ADC%20mulit%20channel%20read%20with%20DMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2199983%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F256581%22%20target%3D%22_blank%22%3E%40yaowei%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20a%20single%20trigger%20source%20to%20collect%20multiple%20channels.%3C%2FP%3E%0A%3CP%3EYou%20can%20concatenate%20multiple%20sampling%20commands%20under%20a%20trigger%20source%2C%20allowing%20the%20ADC%20to%20automatically%20sample%207%20channels%20in%20sequence%20after%20triggering.%3C%2FP%3E%0A%3CP%3EThe%20%3CSTRONG%3EchainedNextCommandNumber%3C%2FSTRONG%3E%20field%20allows%20the%20ADC%20to%20automatically%20execute%20the%20next%20command%20after%20completing%20a%20sample.%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EHarry%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2290749%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MCXA156VLL%20ADC%20mulit%20channel%20read%20with%20DMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2290749%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20use%20the%20DMA%20to%20Trigger%20ADC%2C%3CBR%20%2F%3EDMA%20CH0%20-%26gt%3B%20ADC0%20CH0%20CH1%20CH4%3CBR%20%2F%3EDMA%20CH1%20-%26gt%3B%20ADC0%20CH8%20CH9%20CH12%20CH13%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EHere%20is%20part%20of%20my%20code.%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%3E%3CSPAN%3E%2F*%20Set%20trigger%20configuration.%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ELPADC_GetDefaultConvTriggerConfig(%26amp%3BlpadcTriggerConfig)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ElpadcTriggerConfig.targetCommandId%20%3D%20chainedCommandList%5B0%5D%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ElpadcTriggerConfig.enableHardwareTrigger%20%3D%20TRUE%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ELPADC_SetConvTriggerConfig(halAdcConfig-%26gt%3Bbase%2C%20(eHAL_TRIGGER_ID)triId%2C%20%26amp%3BlpadcTriggerConfig)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CP%3E%2F*%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3CBR%20%2F%3E*%20ADC0%20with%20DMA0%20channel0%3CBR%20%2F%3E*%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D*%2F%3C%2FP%3E%3CP%3E%2F*%20Configure%20DMA%20channel%20for%20ADC1%20FIFO%20transfer%20*%2F%3CBR%20%2F%3Echannel%20%3D%20eHAL_DMA_CHANNEL0%3B%3CBR%20%2F%3Eirq%20%3D%20DMA_CH0_IRQn%3B%3CBR%20%2F%3E%2F*%20Cehck%20DMA%20channel%20is%20not%20Initialized%20*%2F%3CBR%20%2F%3EASSERT(!HAL_DMA_IsChannelInitialized(eHAL_DMA0%2C%20channel))%3B%3C%2FP%3E%3CP%3E%2F*%20Set%20EDMA%20channel%20configuration%20parameters%20*%2F%3CBR%20%2F%3ElpadcDmaChnlConfig.channelDataSignExtensionBitPosition%20%3D%200U%3B%3CBR%20%2F%3ElpadcDmaChnlConfig.channelPreemptionConfig.enableChannelPreemption%20%3D%20FALSE%3B%3CBR%20%2F%3ElpadcDmaChnlConfig.channelPreemptionConfig.enablePreemptAbility%20%3D%20TRUE%3B%3CBR%20%2F%3ElpadcDmaChnlConfig.channelRequestSource%20%3D%20kDma0RequestMuxAdc1FifoRequest%3B%3CBR%20%2F%3ElpadcDmaChnlConfig.protectionLevel%20%3D%20kEDMA_ChannelProtectionLevelUser%3B%3C%2FP%3E%3CP%3E%2F*%20Configure%20EDMA%20channel%20for%20one%20shot%20transfer%20*%2F%3CBR%20%2F%3Eedma_config_t%20userConfig%3B%3CBR%20%2F%3E%2F*%3CBR%20%2F%3E*%20config.enableContinuousLinkMode%20%3D%20false%3B%3CBR%20%2F%3E*%20config.enableHaltOnError%20%3D%20true%3B%3CBR%20%2F%3E*%20config.enableRoundRobinArbitration%20%3D%20false%3B%3CBR%20%2F%3E*%20config.enableDebugMode%20%3D%20false%3B%3CBR%20%2F%3E*%2F%3CBR%20%2F%3EEDMA_GetDefaultConfig(%26amp%3BuserConfig)%3B%3CBR%20%2F%3EEDMA_Init(base%2C%20%26amp%3BuserConfig)%3B%3C%2FP%3E%3CP%3E%2F*%20Set%20source%20address%20to%20ADC1%20FIFO%20register%20*%2F%3CBR%20%2F%3EsrcAddr%20%3D%20(UINT32%20*)%26amp%3B(s_adcConfig%5BeHAL_ADC1%5D.base-%26gt%3BRESFIFO)%3B%3CBR%20%2F%3EdestAddr%20%3D%20(UINT32%20*)adcRawValue%3B%3C%2FP%3E%3CP%3E%2F*%20Prepare%20transfer%20configuration%20for%20one-shot%20peripheral-to-memory%20transfer%20*%2F%3CBR%20%2F%3EEDMA_PrepareTransfer(%26amp%3BtransferConfig%2C%3CBR%20%2F%3EsrcAddr%20%2C%20sizeof(UINT32)%2C%3CBR%20%2F%3E%26amp%3BdestAddr%5BADC1_DMA_DEST_START%5D%2C%20sizeof(destAddr%5B0%5D)%2C%3CBR%20%2F%3Esizeof(destAddr%5B0%5D)%2C%3CBR%20%2F%3Esizeof(UINT32)%20*%20ADC1_DMA_DEST_LENGTH%2C%3CBR%20%2F%3EkEDMA_PeripheralToMemory)%3B%3C%2FP%3E%3CP%3E%2F*%20Used%20to%20change%20the%20destination%20address%20to%20the%20original%20value%20*%2F%3CBR%20%2F%3EtransferConfig.dstMajorLoopOffset%20%3D%20(INT32)((-1)%20*%20sizeof(UINT32)%20*%20ADC1_DMA_DEST_LENGTH)%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2290706%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MCXA156VLL%20ADC%20mulit%20channel%20read%20with%20DMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2290706%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3Ehi%EF%BC%8C%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3BI%20noticed%20that%20DMA%20has%20a%20loop%20function%20and%20channel%20link.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3BCould%20you%20please%20tell%20me%20how%20you%20implemented%20this%20function%3F%3C%2FP%3E%3CP%3EThank%20Y%3C%2FP%3E%3C%2FLINGO-BODY%3E