How to use RT1052 ADC-ETC function to convert ADC1 and ADC2

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use RT1052 ADC-ETC function to convert ADC1 and ADC2

Jump to solution
521 Views
emmmmmmmmmmmmmm
Contributor III

I need to solve the ADC-ETC-DMA function in the project, use ADC-ETC to trigger the conversion of ADC1 and ADC2, and transfer the result through DMA. I searched the information on the Internet, and did not find an example of ETC triggering simultaneous conversion of two ADCs. Does anyone know?

Labels (1)
0 Kudos
1 Solution
442 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi,
After having a brief review of the code, maybe you can try using the below method to suspend the code until the DMA completes the transmit, then print the ADC result.

/* Wait DMA send finished */
while (Flag)
{
}


In further, I think the software flow is able to optimize, as the ADC-ETC can trigger a DMA request after ADC conversion finish, then use the two DMA channel to copy the ADC result to RAM area and the DMA support the link feature which allows you to start more than one transfer with a single request by defining a sequence of channels to be converted. And the DMA also supports the scatter/gather feature to update the TCD descriptor automatically.
Please give it a try.
Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

 

View solution in original post

0 Kudos
7 Replies
518 Views
mjbcswitzerland
Specialist V

Hi

To simultaneously trigger conversion on ADC1 and ADC2 you can set the SYNC_MODE bit in the corresponding ADC_EXT_TRIGn_CTRL register.

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or rapid product development requirements

For professionals searching for faster, problem-free Kinetis and i.MX RT 10xx developments the uTasker project holds the key: https://www.utasker.com/iMX/RT1050.html

498 Views
emmmmmmmmmmmmmm
Contributor III

Thanks for your answer, I have solved the problem of how to trigger ADC1 and ADC2 at the same time by ETC. Now I have another question, how should I add the DMA function, and how should I set up my TCD?

0 Kudos
490 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi,
I'm glad to hear that you had solved your original problem, regarding your further question, I'd like to suggest you refer to the DMA demos in the SDK library to add the DMA function.
Hope it helps.
Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
481 Views
emmmmmmmmmmmmmm
Contributor III

Thank you for your answer. When adding DMA function to the project, the result is different from what I expected.

I hope to trigger the ADC-ETC function within 1S, and then turn on the DMA transfer. In the DMA setting, I set up two channels to complete the transfer of ADC1 and ADC2 data respectively. When the conversion of ADC1 and ADC2 is completed, the DMA request is triggered.

This is my DMA code setting

void ADC1_TransferCreateHandleEDMA(void)
{
EDMA_PrepareTransfer(&ADC1_transferConfig,
(void *)0x403B0028,
sizeof(g_vusADC1ConvertedValue[0]),
g_vusADC1ConvertedValue,
sizeof(g_vusADC1ConvertedValue[0]),
sizeof(g_vusADC1ConvertedValue[0]),
6,
kEDMA_MemoryToMemory);
EDMA_SubmitTransfer(&g_ADC1EdmaHandle, &ADC1_transferConfig);
EDMA_StartTransfer(&g_ADC1EdmaHandle);
}
void ADC2_TransferCreateHandleEDMA(void)
{
EDMA_PrepareTransfer(&ADC2_transferConfig,
(void *)0x403B00C8,
sizeof(g_vusADC2ConvertedValue[0]),
g_vusADC2ConvertedValue,
sizeof(g_vusADC2ConvertedValue[0]),
sizeof(g_vusADC2ConvertedValue[0]),
4,
kEDMA_MemoryToMemory);
EDMA_SubmitTransfer(&g_ADC2EdmaHandle, &ADC2_transferConfig);
EDMA_StartTransfer(&g_ADC2EdmaHandle);
}
void ADC1_EDMACallback(edma_handle_t *handle, void *userData, bool transferDone, uint32_t tcds)
{
ADC1_TransferCreateHandleEDMA();
g_Transfr_flag |= 0X01;
}
void ADC2_EDMACallback(edma_handle_t *handle, void *userData, bool transferDone, uint32_t tcds)
{
ADC2_TransferCreateHandleEDMA();
g_Transfr_flag |= 0X02;
}
void DMA_Configuration()
{
edma_config_t config;
ADC_EnableDMA(ADC1, true);
/* Init DMAMUX */
DMAMUX_Init(DMAMUX);
/* Set channel for ADC1 */
DMAMUX_SetSource(DMAMUX, ADC1_CHANNEL0_DMA_CHANNEL, kDmaRequestMuxADC1);
DMAMUX_EnableChannel(DMAMUX, ADC1_CHANNEL0_DMA_CHANNEL);
/* Init the EDMA module */
EDMA_GetDefaultConfig(&config);
EDMA_Init(DMA0, &config);
EDMA_CreateHandle(&g_ADC1EdmaHandle, DMA0, ADC1_CHANNEL0_DMA_CHANNEL);
EDMA_SetCallback(&g_ADC1EdmaHandle, ADC1_EDMACallback, NULL);
ADC1_TransferCreateHandleEDMA();


ADC_EnableDMA(ADC2, true);
DMAMUX_SetSource(DMAMUX, ADC2_CHANNEL0_DMA_CHANNEL, kDmaRequestMuxADC2);
DMAMUX_EnableChannel(DMAMUX, ADC2_CHANNEL0_DMA_CHANNEL);
EDMA_CreateHandle(&g_ADC2EdmaHandle, DMA0, ADC2_CHANNEL0_DMA_CHANNEL);
EDMA_SetCallback(&g_ADC2EdmaHandle, ADC2_EDMACallback, NULL);
ADC2_TransferCreateHandleEDMA();
}

What I want is the result in the red box of the picture. Two DMA requests are triggered within 1S, but sometimes only one DMA is triggered. can you help me?

企业微信截图_1609825629784.png

0 Kudos
461 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi,
Thanks for your reply.
I was wondering if you can share more information about your question, such as the software flow, and the complete demo code, then it can help me to figure it out.
Looking forward to your reply.
Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

 

0 Kudos
456 Views
emmmmmmmmmmmmmm
Contributor III

I want to trigger the ETC function once at the interval of 1 second in the PIT timer. In ETC, I set the ADC1 and ADC2 synchronous triggers, and the ADC converted data is transferred to the array through DMA. I set DMA channel 0 for ADC1 data and DMA channel 1 for ADC2 data. The current phenomenon is that sometimes only 1 DMA channel request is responded within 1 second.The adc_etc_hardware_trigger_conv.c file is my complete code

Finally thank you for your reply.

0 Kudos
443 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi,
After having a brief review of the code, maybe you can try using the below method to suspend the code until the DMA completes the transmit, then print the ADC result.

/* Wait DMA send finished */
while (Flag)
{
}


In further, I think the software flow is able to optimize, as the ADC-ETC can trigger a DMA request after ADC conversion finish, then use the two DMA channel to copy the ADC result to RAM area and the DMA support the link feature which allows you to start more than one transfer with a single request by defining a sequence of channels to be converted. And the DMA also supports the scatter/gather feature to update the TCD descriptor automatically.
Please give it a try.
Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

 

View solution in original post

0 Kudos