Time consumed for executing one simple function varies in a big range

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

Time consumed for executing one simple function varies in a big range

500 Views
longxing
Contributor III

A very simple function which reads conversion result of ADC is called in the highest priority ISR every 20us.The function is showed below:

void get_motor_curr(int16_t *motor_curr)
{
	uint16_t result = 0;

	result = ADC_ETC_GetADCConversionValue(ADC_ETC_PERIPHERAL,ADC_ETC_TC_0_TG,0);
	result &= 0x0FFF;

	motor_curr[0] = (int16_t)(result * 4.3 + 0.5) >> 1;
}

 Set one gpio high before calling above function and clear the gpio after return from it,then measure the time elapsed using oscilloscope.

adc.png

Picture above shows that the consumed time varies a lot,indeed,it can vary from 0.3us to more than 1us.

The function just reads conversion result of ADC,it won't wait for anything,also it is called in the highest priority ISR.I can't image any situation that CPU will consume little or more time than another .

The ISR runs from extern SDRAM,and SEMC works at 132MHz.CPU clock is 528MHz.MCU is MIMXRT1052.

This problem really bother me a lot.If anyone has any idea about this problem,please let me know.

Thanks in advance!

 

0 Kudos
3 Replies

470 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello
I hope you are well.

Are you calling the conversion function directly from the ISR? Or are you using a callback for the function? I suggest you this last method so the ISR remains as short as possible.
Please modify the BMCR register from SEMC to 0x00000081 to prevent the module from re-orders the queue.
Is this issue persistent if you execute the code from internal SRAM or external nor flash?

Best regards,
Omar

0 Kudos

451 Views
longxing
Contributor III

Hi,Omar

Modifying the BMCR register from SEMC to 0x00000081 can make the time cost stable,but it takes about 0x2cc clocks to execute the function.The clocks comsumed is viewed from DWT register.

0 Kudos

464 Views
longxing
Contributor III

Hi,Omar

First,Thanks for your response.

In the ISR i just read the ADC conversion result register direct and do not wait for ADC conversion completion.So,I think it should cost nothing.

If the code executes from external NOR FLASH or internal SRAM,the time comsumed by the function can be stable.But if executes from external NOR FLASH,the time comsumed by the function will be obviously longer。 Isn't executing from nor flash the suggested way by NXP for high performance?

By now,the BMCR register of SEMC is 0,which is recommended by  IMXRT1050RM.Any way,I will try your suggestion later.

0 Kudos