How to use LPTMR in K32 L2A MCU ?

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

How to use LPTMR in K32 L2A MCU ?

1,563件の閲覧回数
Jagir_Mehta1
Contributor II

Hello,

I am using K32L2A41VLL1A MCU.

I am trying to use LPTMR in an internal project in my company.

I have configured it to use as timer with default configuration, set time period, register & enable interrupt for timer overflow process, write high to a GPIO & then start timer.

In timer ISR i put Logic LOW on the same GPIO to identify High pulse duration using timer.

The issue i am facing is i have set time period as 15.000 sec but from logic analyser the shows Duration of high pulse is 15.031 sec as an addition of 31 mSec for 15.0 sec pulse.

 

Is there any way to make it accurate 15.00 sec pulse or reduce the offset by change of clock source for timer or any other configuration ?

 

#K32L2A41VLL1A #HW_Timer #LPTMR

0 件の賞賛
返信
5 返答(返信)

1,536件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,Jagir_Mehta1

Thank you for contacting us.

The LPTMR can use the LPO and external crystal, you can try using the external crystal for the LPTMR.

Joey_z_0-1744165587318.png

In addition, are you using the SDK demo to test the 15.000 sec? if not, If not, please ensure that the LPTMR ISR is not influenced by other ISRs.

Hope it can help you.

BR

Joey

 

0 件の賞賛
返信

1,527件の閲覧回数
Jagir_Mehta1
Contributor II

Hi Joey,

I have ported LPTMR SDK demo in my project & i have ensured that timer ISR is not enfluenced with any other ISRs.

Yet i have observed 31.67 ms  positive offset in the total time of 15.00 sec timer period.
Do i have any solution or steps to reduce this offset ?
This offset with LPTMR (LPO 1 KHz ) is accepted ?

 

タグ(2)
0 件の賞賛
返信

1,517件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,Jagir_Mehta1

Thank you for your reply.

I think you should cheek the value of counts.

set LPTMR_USEC_COUNT 1000000U, about 1s have the offset 0.5ms.

Joey_z_1-1744255108340.png

set LPTMR_USEC_COUNT 1005000U, the offset is lower.

Joey_z_0-1744255077743.png

In addition, I use the LPO to test it, but external crystal is less susceptible to outside influences, you can consider using it.

Hope it can help you.

BR

Joey

0 件の賞賛
返信

1,462件の閲覧回数
Jagir_Mehta1
Contributor II

Hi Joey,

Thanks for your replay with practical example of 1 sec LPTMR duration.
Can you please let me know if there is any mistake in my configuration of LPTMR as described below .?

Because i have tried with LPO clock & i was getting +2 ms offset(measured time 100200) for 1 sec(1000000U) timer duration.

My configuration:

static void startHwTimer(uint32_t pulseDuration)
{
lptmr_config_t lptmrConfig;

LPTMR_GetDefaultConfig(&lptmrConfig);

/* Initialize the LPTMR */
LPTMR_Init(LPTMR0, &lptmrConfig);

/* Set timer period. */
LPTMR_SetTimerPeriod(LPTMR0, (uint32_t)USEC_TO_COUNT(pulseDuration, CLOCK_GetFreq(kCLOCK_LpoClk)));
/* Enable timer interrupt */
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);

/* Enable at the NVIC */
EnableIRQ(LPTMR0_IRQn);

/* Start counting */
LPTMR_StartTimer(LPTMR0);
}

void LPTMR0_IRQHandler()
{
mwGpio_write(3, 6, LOW);
LPTMR_StopTimer(LPTMR0);
LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
}

0 件の賞賛
返信

1,431件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,Jagir_Mehta1

Thank you for your reply.

I think the issue is caused by your GPIO setting. You should firstly set GPIO level change after LPTMR_StartTimer(LPTMR0); . You can try it.

Hope it can help you.

BR

Joey

0 件の賞賛
返信