LPTMR Get Counter Value

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

LPTMR Get Counter Value

Jump to solution
699 Views
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 Kudos
Reply
1 Solution
664 Views
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

 

View solution in original post

0 Kudos
Reply
2 Replies
665 Views
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 Kudos
Reply
642 Views
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 Kudos
Reply