Hi NXP team,
I am currently using an S32k144 processor with 80MHz system clock and XTAL clock of 8MHz. The step size of my model is 0.005. I am trying to use LPTMR Get Counter Value block in Simulink before and after my algorithm to determine how long would algorithm consume at each step size.
Is there any way I can convert the converter value I get from LPTMR Get Counter Value block to the unit of time in microseconds?
Below is a screenshot of my model for the reference.
Thanks for any help in advance.
Leo
解決済! 解決策の投稿を見る。
Hello @noobsplzwin,
The LPTMR counter value is incremented in ticks and the function you are mentioning returns that value into ticks. To convert the ticks value in seconds, you need to know the value of the timer counter frequency, and apply the following formula:
time_in_sec = (1 / lptmr_timer_counter_frequency ) * ticks_returned_by_LPTMR
But please pay attention to a couple of details. In time counter mode, the Prescaler Clock Select field configures the clock source for the LPTMR. You have multiple options, and first check in the generated code, the values are the following:
- SIRC DIV2 clock = 8MHz
- 1kHz LPO clock = 128KHz
- RTC clock = 32KHz
- PCC configured clock = 8MHz
Now, the LPTMR clock shall be used for applications that require low power mode, and the mentioned input clock sources shall remain active during low power mode active states of the MCU.
For your application, I would suggest using the profiler block, which has a 20MHz input source clock, so provides a better accuracy. If you place this block inside an atomic subsystem, it will automatically insert the instructions so that in the profiler buffer index selected inside the block, you will find the ticks count you are interested in.
Hope this helps,
Marius
Hello @noobsplzwin,
The LPTMR counter value is incremented in ticks and the function you are mentioning returns that value into ticks. To convert the ticks value in seconds, you need to know the value of the timer counter frequency, and apply the following formula:
time_in_sec = (1 / lptmr_timer_counter_frequency ) * ticks_returned_by_LPTMR
But please pay attention to a couple of details. In time counter mode, the Prescaler Clock Select field configures the clock source for the LPTMR. You have multiple options, and first check in the generated code, the values are the following:
- SIRC DIV2 clock = 8MHz
- 1kHz LPO clock = 128KHz
- RTC clock = 32KHz
- PCC configured clock = 8MHz
Now, the LPTMR clock shall be used for applications that require low power mode, and the mentioned input clock sources shall remain active during low power mode active states of the MCU.
For your application, I would suggest using the profiler block, which has a 20MHz input source clock, so provides a better accuracy. If you place this block inside an atomic subsystem, it will automatically insert the instructions so that in the profiler buffer index selected inside the block, you will find the ticks count you are interested in.
Hope this helps,
Marius
Hi Marius,
Thanks for the detailed response. Profile Function block looks like exactly what I need. Is it part of the S32k1 MBD toolbox? I am not able to find it under S32k1xx Core, System, Peripherals, and Utilities