Inaccurate LPTMR

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
1,896件の閲覧回数
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,315件の閲覧回数
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,315件の閲覧回数
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,315件の閲覧回数
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,316件の閲覧回数
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,315件の閲覧回数
TobiasBystricky
Contributor III

Thanks man!! now its working perfect...

Best regards

Tobias

0 件の賞賛
返信