How to Properly Check ADC Conversion Completion on S32K3 SAR ADC

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to Properly Check ADC Conversion Completion on S32K3 SAR ADC

243 次查看
varunpenumudi
Contributor I

 

Hi, I am working with the SAR ADC on the S32K3 series microcontroller with ADC_Sar_Ip Library, I am going for non autosar based codes. I want to read a value from a specific ADC channel, and here’s the code snippet I have written so far:

uint16_t ADC_Get_Value(uint32 adc_Instance_u32,uint32 channel_Idx_u32) {
uint16_t data;

Adc_Sar_Ip_StartConversion(adc_Instance_u32, ADC_SAR_IP_CONV_CHAIN_NORMAL);
while (Adc_Sar_Ip_GetStatusFlags(adc_Instance_u32) != 35);
data = Adc_Sar_Ip_GetConvData(adc_Instance_u32, channel_Idx_u32);

return data;
}

I noticed that the NXP SAR ADC IP driver provides an API to start conversion (Adc_Sar_Ip_StartConversion), but I could not find an API specifically for checking the end of conversion.

Experimentally, I observed that the status flags returned by Adc_Sar_Ip_GetStatusFlags reach 32 when the conversion is complete, so I used this value in my while loop. Using this method works for me, but I am unsure if this is the correct or recommended way to detect conversion completion.

My questions are:

  1. Is there an official API in the S32K3 SAR ADC driver to check for end-of-conversion?

  2. Why does polling Adc_Sar_Ip_GetStatusFlags until the value becomes 32 work? Is this behavior guaranteed, or is it dependent on the current driver version?

  3. If there is no API, what is the recommended way to handle ADC conversion completion: polling the status flags, using interrupts, or adding delays?

0 项奖励
回复
1 回复

148 次查看
_Leo_
NXP TechSupport
NXP TechSupport

Thank you for your interest in our products and for contributing to our community.

Your approach seems correct.

But the BCTU triggering scheme is the default and suggested hardware trigger method for the ADC.

Said that you could refer to the following community post:

S32M27x/S32K3 – eMIOS/BTCU/ADC/DMA – [RTD600] -> https://community.nxp.com/t5/S32M-Knowledge-Base/S32M27x-S32K3-eMIOS-BTCU-ADC-DMA-RTD600/ta-p/215554...

In such example, the he GPIO4 is toggled in BCTU Watermark Notification, which happens every time the number of active entries in FIFO exceeds the watermark level, and therefore the data is available for reading.

Another way is using the "List last conversion notification" in Bctu_Ip driver, or if not using the BCTU, you can use the end of conversions notifications. But there is no example for this modes.

I hope this information is helpful.

0 项奖励
回复