Inaccurate LPTMR

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

Inaccurate LPTMR

跳至解决方案
1,916 次查看
TobiasBystricky
Contributor III

Hello,

I'm using the LPTMR of the K60. I configure it like that:

_lpt_install (0, 30 * 1000000, LPT_FLAG_CLOCK_SOURCE_ERCLK32K, 2, timer_wakeup_isr, TRUE))

and i expect that it will set an interrupt every 30 seconds.

But I got an interrupt every 32 second:

09-06-2013 03:28:18,

09-06-2013 03:28:50,

09-06-2013 03:29:22,

09-06-2013 03:29:54,

Now my question, what went wrong? I use the RTC as ERCLK32K.

Thanks for help,

Tobias

标签 (1)
0 项奖励
回复
1 解答
1,335 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi Tobias,

I think I have figured out what is wrong in your code.The line of code "lpt_ptr->CSR |= LPTMR_CSR_TFC_MASK; "should be corrected into "lpt_ptr->CSR &= (uint_32)~(uint_32)LPTMR_CSR_TFC_MASK;" 

Because you want interrupt could be generated when CNR  equals the CMR.However after TFC be set,CNR will be reset on overflow which means CNR will increase even equals to CMR.So you get:

(0xFFFF+1)*16*1/32.768kHz = 32 sec which the results had show. You can review the datasheet to check out.

Hope can help you.

Best Regards

Ping Zhou

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,335 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi Tobias,Would you send me the codes of _lpt_install then I could check out for you?

0 项奖励
回复
1,335 次查看
TobiasBystricky
Contributor III

Hi Ping,

thanks for your help.

Here's the function installing the timer:

static void install_timer_interrupt

    (

        void

    )

{

    LPM_REGISTRATION_STRUCT registration;

    uint_32                 dummy_handle;

 

    /* Install the timer */

    if (MQX_OK != _lpt_install (0, 30 * 1000000, LPT_FLAG_CLOCK_SOURCE_ERCLK32K, 2, timer_wakeup_isr, TRUE))

    {

        _io_printf ("\nError during installation of timer interrupt!\n");

        _task_block();

    }

    LPTMR_MemMapPtr lpt_ptr = (LPTMR_MemMapPtr)_bsp_get_lpt_base_address (0);

    lpt_ptr->CSR |= LPTMR_CSR_TFC_MASK;

 

    /* Stop the timer */

    _lpt_run (0, FALSE);

}

And this is the isr:

static void timer_wakeup_isr(pointer parameter){

     set_minute_signal();

     _lpt_clear_int ((uint_32)parameter);

}

Just sending a signal..

In the meantime i got the following information from support:

I run your code _lpt_install (0, 30 * 1000000, LPT_FLAG_CLOCK_SOURCE_ERCLK32K, 2, timer_wakeup_isr, TRUE); in TWR-K60N512 BSP MQX 4.0.1 and I get:

PSR = 0x1A means PRESCALE /16
PCS = Secondary External Ref Clk
CMR = 0xEFFF.

Now, assuming SIM_SOPT1[OSC32KSEL] selects 32.768 kHz RTC oscillator from XTAL32/EXTAL32 on board 32.768 kHz crystal, we get:

(0xEFFF+1)*16*1/32.768kHz = 30 sec so the computed values look just all right.

Thanks for your efford!

Tobias

0 项奖励
回复
1,336 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi Tobias,

I think I have figured out what is wrong in your code.The line of code "lpt_ptr->CSR |= LPTMR_CSR_TFC_MASK; "should be corrected into "lpt_ptr->CSR &= (uint_32)~(uint_32)LPTMR_CSR_TFC_MASK;" 

Because you want interrupt could be generated when CNR  equals the CMR.However after TFC be set,CNR will be reset on overflow which means CNR will increase even equals to CMR.So you get:

(0xFFFF+1)*16*1/32.768kHz = 32 sec which the results had show. You can review the datasheet to check out.

Hope can help you.

Best Regards

Ping Zhou

0 项奖励
回复
1,335 次查看
TobiasBystricky
Contributor III

Thanks man!! now its working perfect...

Best regards

Tobias

0 项奖励
回复