MPC5748G ADC Interrupt

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

MPC5748G ADC Interrupt

跳至解决方案
1,748 次查看
joãopaulo
Contributor III

Hello,

I'd like an example project or a document that shows how to read precision adc channels in scan mode and 

when a conversion finishes it calls an interrupt routine using processor expert.

Thanks in advance

Regards

João Paulo

标签 (1)
1 解答
1,635 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

lines from the attached file

void ADC1_EOC_IRQHandler(void)
{
uint32_t len = ADC_DRV_GetConvResultsToArray(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL, &result, 1u);
DEV_ASSERT(len == 1u); /* only one value should be read from hardware registers */
(void)len;
ADC_DRV_ClearStatusFlags(INST_ADCONV1, ADC_FLAG_NORMAL_ENDCHAIN);
if (result > ADC_THRESHOLD)
{
PINS_DRV_ClearPins(LED_PORT, (1 << LED));
}
else
{
PINS_DRV_SetPins(LED_PORT, (1 << LED));
}
}
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/
/* Initialize and configure pins */
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/* Initialize clocks */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
/* Initialize ADC */
ADC_DRV_Reset(INST_ADCONV1);
ADC_DRV_DoCalibration(INST_ADCONV1);
ADC_DRV_ConfigConverter(INST_ADCONV1,&adConv1_ConvCfg0);
ADC_DRV_EnableChannel(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL, ADC_CHAN_NUM);

ADC_DRV_EnableInterrupts(INST_ADCONV1,ADC_FLAG_NORMAL_ENDCHAIN);
INT_SYS_SetPriority(ADC1_EOC_IRQn,1);
INT_SYS_EnableIRQ(ADC1_EOC_IRQn);

ADC_DRV_StartConversion(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL);
/* Start a loop to read converted values and blink an LED */
while(1)
{

}

BR, Petr

在原帖中查看解决方案

5 回复数
1,635 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

you can modify the "adc_swtrigger_mpc5748g" demo example available in the S32 Design Studio.

Change the conversion mode in ADC component

pastedImage_1.png

and refer to attached main.c.

Hope it helps.

BR, Petr

0 项奖励
回复
1,635 次查看
joãopaulo
Contributor III

Hello,

This demo doesn't uses interrupts.. it holds the software on a while until the conversion finishes, is it possible to have an interrupt routine that is called when the adc conversion is completed?

If I enable the chain configuration 

pastedImage_1.png

do I still need to call 

ADC_DRV_EnableChannel(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL, ADC_CHAN_NUM); ?

whant changes if I initialize clocks with these code lines 

CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

or with this one

CLOCK_DRV_Init(clockMan1_InitConfig0); ?

considering the demo project.

The mcu clock is set to 160MHz, isn't it?

On converter configuration tab, if I set the Clock Input to Input clock is Bus clock.

Which frequency is it? 160MHz or 80 MHz?

When I use ADC_DRV_DoCalibration(INST_ADCONV1); do this function automatically changes the adc clock to 40MHz and after the calibration changes back to the clock that was set before?

On converter configuration tab, the higher the sample duration the higher the precision of the measurement?

Thanks,

Regards

João Paulo

0 项奖励
回复
1,635 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, that example does not use interrupt, but can be modified to have it. Did you refer to the code I attached? Probably not.

If you enable chain configuration then ADC_DRV_EnableChannel is not needed but you should call ADC_DRV_ChainConfig.

Not sure about clock config. 

System clock is set to 160MHz, the ADC clock source is FS80 (80MHz). The ADC can reduce the source clock to generate a 40 MHz clock, using MCR[ADCLKSEL] bit.

ADC_DRV_DoCalibration save MCR, clears MCR[ADCLKSEL] and finally restore MCR, so frequency during calibration is 40MHz.

Sample duration specify how long the sample capacitor is charged from the source, so it affects precision but also other aspects influence this (input signal, source resistance, filters, etc).

BR, Petr 

1,635 次查看
joãopaulo
Contributor III

Hello,

I refered to "adc_swtrigger_mpc5748g" demo example. 

Could you tell me what functions/routines should I use to use add interrupt feature?

Thanks

0 项奖励
回复
1,636 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

lines from the attached file

void ADC1_EOC_IRQHandler(void)
{
uint32_t len = ADC_DRV_GetConvResultsToArray(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL, &result, 1u);
DEV_ASSERT(len == 1u); /* only one value should be read from hardware registers */
(void)len;
ADC_DRV_ClearStatusFlags(INST_ADCONV1, ADC_FLAG_NORMAL_ENDCHAIN);
if (result > ADC_THRESHOLD)
{
PINS_DRV_ClearPins(LED_PORT, (1 << LED));
}
else
{
PINS_DRV_SetPins(LED_PORT, (1 << LED));
}
}
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/
/* Initialize and configure pins */
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/* Initialize clocks */
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
/* Initialize ADC */
ADC_DRV_Reset(INST_ADCONV1);
ADC_DRV_DoCalibration(INST_ADCONV1);
ADC_DRV_ConfigConverter(INST_ADCONV1,&adConv1_ConvCfg0);
ADC_DRV_EnableChannel(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL, ADC_CHAN_NUM);

ADC_DRV_EnableInterrupts(INST_ADCONV1,ADC_FLAG_NORMAL_ENDCHAIN);
INT_SYS_SetPriority(ADC1_EOC_IRQn,1);
INT_SYS_EnableIRQ(ADC1_EOC_IRQn);

ADC_DRV_StartConversion(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL);
/* Start a loop to read converted values and blink an LED */
while(1)
{

}

BR, Petr