ADC Configuration

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

ADC Configuration

841 次查看
SasiKumar_Vengam
Contributor II

Hi,

We are trying to configure PTE16(ADC0) pin in the S32K312 MCU using S32 DS 3.5. We need to read the voltage level on that pin and need to control the pin accordingly. For your reference, find the details in the below image.

SasiKumar_Vengam_0-1732719001998.pngSasiKumar_Vengam_1-1732719019049.png

SasiKumar_Vengam_2-1732719065514.png

We configured this using an example, they have used interrupt. But we prefer to configure without using the ISR function.

Any simple implementation of ADC without ISR would help.

Thanks.

标记 (1)
0 项奖励
回复
2 回复数

793 次查看
_Leo_
NXP TechSupport
NXP TechSupport

Hi,

Thank you so much for your interest in our products and for using our community.

You could refer to the following S32K Knowledge Base post:

[RTD400 LLD]K344 ADC SW+HW trigger

Hope it helps you.

Have a nice day!

0 项奖励
回复

829 次查看
SasiKumar_Vengam
Contributor II
For your reference, The main code used is:
/**************************************************** ADC sample code **************************************************************/


/* Get ADC max value from the resolution */
if (AdcHwUnit_0.AdcResolution == ADC_SAR_IP_RESOLUTION_8)
adcMax = (uint16_t) (1 << 8);
else if (AdcHwUnit_0.AdcResolution == ADC_SAR_IP_RESOLUTION_10)
adcMax = (uint16_t) (1 << 10);
else if (AdcHwUnit_0.AdcResolution == ADC_SAR_IP_RESOLUTION_12)
adcMax = (uint16_t) (1 << 12);
else if (AdcHwUnit_0.AdcResolution == ADC_SAR_IP_RESOLUTION_14)
adcMax = (uint16_t) (1 << 14);
else
adcMax = (uint16_t) (1 << 14);

status = (StatusType) Adc_Sar_Ip_Init(ADCHWUNIT_0_INSTANCE, &AdcHwUnit_0);
while (status != E_OK);

/* Call Calibration function multiple times, to mitigate instability of board source */
for(Index = 0; Index <= 5; Index++)
{
status = (StatusType) Adc_Sar_Ip_DoCalibration(ADCHWUNIT_0_INSTANCE);
if(status == E_OK)
{
break;
}
}
Adc_Sar_Ip_EnableNotifications(ADCHWUNIT_0_INSTANCE, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN | ADC_SAR_IP_NOTIF_FLAG_INJECTED_ENDCHAIN);

/* Start a SW triggered normal conversion on ADC_SAR */
Adc_Sar_Ip_StartConversion(ADCHWUNIT_0_INSTANCE, ADC_SAR_IP_CONV_CHAIN_NORMAL);
/* Wait for the notification to be triggered and read the data */
while (notif_triggered != TRUE)
{
__asm volatile ("nop");
}
notif_triggered = FALSE;


while(1)
{
//notif_triggered = TRUE;
data_bandgap = Adc_Sar_Ip_GetConvData(ADCHWUNIT_0_INSTANCE, ADC_SAR_USED_CH_BANDGAP);
data_POT_0 = Adc_Sar_Ip_GetConvData(ADCHWUNIT_0_INSTANCE, ADC_SAR_USED_CH_POT_0);

/* Process the result to get the value in volts */
data_bandgap_volt = ((float) data_bandgap / adcMax) * (ADC_VREFH - ADC_VREFL);
data_POT_0_volt = ((float) data_POT_0 / adcMax) * (ADC_VREFH - ADC_VREFL);
//
}
0 项奖励
回复