Hi,
I work on model-based design with code generation on MATLAB / SIMULINK thanks to NXP Toolbox. I try to execute a program for motor vector control.
In my test, i verify the execution time of all functions that run at differente rates (1kHz / 5kHz / 25kHz / 50kHz).
To be sure of my mesures, i execute all the program on 1 function-call generator with fixed-step at 1kHz and i suppress all sample time on each task (each task is call by a function-call).
All ISR interrupt are disabled (PDB, ADC, etc...).
I obtain some results that are stranges...
Procedure :
i write in the generated c-code (mymodel.c) the following code :
*************************************************
PINS_DRV_ClearPins(PTA, 1UL<<8);
for(int i=0; i<10; i++)
{
asm("nop");
}
PINS_DRV_SetPins(PTA, 1UL<<8);
*************************************************
The results are :
*************************************************
For Loop Iteration Execution time (us)
10 0.54
100 13
1000 45
10000 367
*************************************************
So, calculation give the following results :
* 1000 nop -> 10000 nop : 1 nop instruction + 1 for loop = (367-45)/9000 = 35.8ns
* 100 nop -> 1000 nop : (45-13)/900 = 35.6ns
* 10 nop : 0.54us because there is the time commutation of GPIO so the results are matching
I verify assembler by disassembly the generated code (arm-none-eabi-objdump) :
: nop
: subs r3, #1
: bne.n
That's a good assembler code !
If we try to estimate 1 cycle instruction time, we have 3/35.6ns = 84MHz and not 112MHz...
So, i tried to modify the s32k_clock_init.c file :
By investigate on the NXP's forum community, i found that i need to modify the .hccrConfig settings by replacing the .src by SCG_SYSTEM_CLOCK_SRC_SYS_PLL by SCG_SYSTEM_CLOCK_SRC_FIRC.
But the execution time is worst...
So, my question is : how to ensure by code generation (in my model) that the microcontroler system clock is set at 112MHz ?
Maybe a link with the Power Management Controller block ?
Thanks in advance for your answer, i hope you will have an explanation on this strange behavior
PS : i can't send you a model for confidential reason.
Solved! Go to Solution.
Hi everyone, just to correct my explanation :
bne assembler take in reality 2 cycles so 4/35.6ns = 112MHz, it's a mistake, sorry, so the CPU has the good setting !
Hello
I want to ask you to explain more how to test the output clock in HSRUN mode because I have the same problem and the output frequency is not correct
Hi everyone, just to correct my explanation :
bne assembler take in reality 2 cycles so 4/35.6ns = 112MHz, it's a mistake, sorry, so the CPU has the good setting !