LPTMR Get Counter Value

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

LPTMR Get Counter Value

跳至解决方案
1,289 次查看
noobsplzwin
Contributor III

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.

noobsplzwin_0-1710343399772.png

 

Thanks for any help in advance.

Leo

 

0 项奖励
回复
1 解答
1,254 次查看
mariuslucianand
NXP Employee
NXP Employee

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 

mariuslucianand_0-1710439859303.png

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.

mariuslucianand_1-1710442325181.png

Hope this helps,

Marius

 

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,255 次查看
mariuslucianand
NXP Employee
NXP Employee

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 

mariuslucianand_0-1710439859303.png

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.

mariuslucianand_1-1710442325181.png

Hope this helps,

Marius

 

0 项奖励
回复
1,232 次查看
noobsplzwin
Contributor III

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

noobsplzwin_0-1710689793467.png

 

 

0 项奖励
回复