Need to count 32-bit value using LPT(low power timer)

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Need to count 32-bit value using LPT(low power timer)

1,415件の閲覧回数
sujaigowda
Contributor II

Hi all, I'm using Kinetis controller and ihave a question for lpt(low power timer). I'm using LPT as counter(counter and compare registers are 16-bit wide) and i need to count 32 bit value instead of 16 bit. can i cascaded the LPT?

タグ(1)
7 返答(返信)

1,146件の閲覧回数
bendis
Contributor I

Or, If you have only one LPTMR avaliable, you can set prescaler to 65536, count the upper 16 bits and then disable prescaler and count the lower 16 bits.

0 件の賞賛

1,146件の閲覧回数
sujaigowda
Contributor II

Hi martin,

     I dint get your answer exactly. After i set prescaler, how to count? can you briefly tell us; it will be helpuful.

0 件の賞賛

1,146件の閲覧回数
bendis
Contributor I

Hi!

Let's say you have uint32_t count value. What you need to do is to split counting in two steps:

  1. First, you set prescaler in the PSR register to divide by 65536 and prescaler bypass PBYP to 0. Then you set the compare register CMR to (count >> 16) and start the timer.
  2. Second, when you get the timer interrupt, you disable prescaler by setting PBYP to 1 and set the compare register CMR to (count & 0xFFFF) and again start the timer and wait for the interrupt.

In the first step you configure LPTMR to run 65536 times slower to count (count & 0xFFFF0000) clock cycles. Then you disable prescaler to count the remaining time - the lower 16 bits of your count value.

1,146件の閲覧回数
sujaigowda
Contributor II

Thank you martin. its a helpful answer.

0 件の賞賛

1,146件の閲覧回数
Carlos_Musich
NXP Employee
NXP Employee

Hi Sujai,

It is possible. You can configure both timers, start one timer at any moment and then start the second timer inside the interrupts of the first timer. E.g.

int main(void)

{

 

    init_LPTMR0 ();

    init_LPTMR1 ();

    LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;   //Turn on LPT and start counting

    while(1)

    {

      

    }

    return 0;

}

void LPTimer0_IRQHandler(void)

{

         LPTMR1_CSR |= LPTMR_CSR_TEN_MASK;   //Turn on LPT and start counting

}

Best regards,

Carlos

Technical Support Engineer

1,146件の閲覧回数
sujaigowda
Contributor II

Hi Carlos,

     Thank you for your reply. Yeah i was using same method in a different approach. i was trying to cascade it in hardware. Now im using same method and is working.

thank you carlos.

0 件の賞賛

1,146件の閲覧回数
Carlos_Musich
NXP Employee
NXP Employee

Hi Sujai,

I am glad your problem was solved.

If you find our responses useful I encourage you to mark them as helpful or correct answer. This will help other members find the best answers as well.

Best regards,

Carlos

Technical Support Engineer

0 件の賞賛