Timer Unit; SetPeriodTicks, what is it based on?

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

Timer Unit; SetPeriodTicks, what is it based on?

Jump to solution
1,296 Views
marknordstrand
Contributor III

The other day, I set up a TimerUnit with a period of 1ms.  In code I called SetPeriodTicks() with a value of 10000 and until recently it was responding in the OnCounteRestart event every 10 seconds.  Now it is responding every .2 ms.  It took a while, but I finally noticed that this is 10000 times the counter frequency.  Which of these should SetPeriodTicks() be using?  Rereading the description, I can see it being either way. 

Labels (1)
0 Kudos
1 Solution
1,029 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Mark,

I checked the code of SetPeriodTicks( ). It is changing the Load register of PIT module.

   PIT_LDVAL_REG(PeripheralBase,(ChannelIdx)) = \

     (uint32_t)(Value) \

This indicates that it should use input frequency and multiply it with the value passed to it.

It should not use the period. I am not sure why you observed it. You might have used something different. But since the code generation through this module will be same, thus it should always use the input frequency.

-Arpita

View solution in original post

0 Kudos
6 Replies
1,029 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Mark,

Which MCU you are working on? What is the code warrior version?

This information is required to check the respective PE bean.

-Arpita

0 Kudos
1,029 Views
marknordstrand
Contributor III

Should have included this, but CW version 10.4 with a mk20dn512vlq10.

0 Kudos
1,029 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Mark,

Which module are you using for setting timer? Are you using Processor Expert?

Can you share your code?

-Arpita

0 Kudos
1,029 Views
marknordstrand
Contributor III

Arpita,


Yes, using Processor Expert and using a TimeUnit_LDD with a PIT counter.  Period is 1ms.  Code is in a different state at the moment, so won't be much help.  Setting this test up was fairly straightforward:


In main() of ProcessorExpert.c call the timer's Init() and SetPeriodTicks() with a value of 10000.  In Timer1's OnCounterRestart() callback just print that the event happened (I also added info from the RTC for reference).  When first implemented it the callback reported every 10 seconds, which would be the period.  Currently, it responds as if uses the input frequency.  Which is the intended behavior, and any idea why it changed on me?


0 Kudos
1,030 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Mark,

I checked the code of SetPeriodTicks( ). It is changing the Load register of PIT module.

   PIT_LDVAL_REG(PeripheralBase,(ChannelIdx)) = \

     (uint32_t)(Value) \

This indicates that it should use input frequency and multiply it with the value passed to it.

It should not use the period. I am not sure why you observed it. You might have used something different. But since the code generation through this module will be same, thus it should always use the input frequency.

-Arpita

0 Kudos
1,028 Views
marknordstrand
Contributor III

Arpita,


Thanks for verifying that, it's consistent with current behavior.  Not sure what I did before.


0 Kudos