perform us wait using lptmr driver

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

perform us wait using lptmr driver

169 Views
elb1
Contributor III

Hello i am using lptmr project example from sdk (lptmr_periodic_interrupt) for s32k142, and i want to use for freertos project.
i am not using interrupts which means i don't want it to go to the interrupt once the configured value has past.
What i want is to perform a microsecond delay, how can i do that using the functions that are in lptmr_driver.c file ?

0 Kudos
Reply
2 Replies

152 Views
elb1
Contributor III
i added this function:
 
void LPTMR_DRV_DelayUs()
{
    LPTMR_DRV_StartCounter(INST_LPTMR1);
 
    while (!(LPTMR_DRV_GetCompareFlag(INST_LPTMR1)));
 
    LPTMR_DRV_ClearCompareFlag(INST_LPTMR1);
 
    LPTMR_DRV_StopCounter(INST_LPTMR1);
}
 
so when i first initilize the driver i do this:
 
    lptmr_config_t lpTmr1_config0 =
    {
        .workMode = LPTMR_WORKMODE_TIMER,
        .dmaRequest = false,
        .interruptEnable = false,
        .freeRun = false,
        .compareValue = 100,
        .counterUnits = LPTMR_COUNTER_UNITS_MICROSECONDS,
        .clockSelect = LPTMR_CLOCKSOURCE_SIRCDIV2,
        .prescaler = LPTMR_PRESCALE_2,
        .bypassPrescaler = false,
        .pinSelect = LPTMR_PINSELECT_TRGMUX,
        .pinPolarity = LPTMR_PINPOLARITY_RISING,
    };
    LPTMR_DRV_Init(INST_LPTMR1, &lpTmr1_config0, false);
 
And then during the task running i do this:
 
        (void)gpio_write(&gpio, false);
        LPTMR_DRV_DelayUs();
        (void)gpio_write(&gpio, true);
        LPTMR_DRV_DelayUs();
 
I was supposed to get 100us delay between the gpio toggling, but instead i get 108us, and the 8 will always be there (ex. if i configure the timer for 50us i will get 58us etc)
0 Kudos
Reply

129 Views
_Leo_
NXP TechSupport
NXP TechSupport

Thank you so much for your interest in our products and for using our community.

I noticed that you have another similar case, so I will follow up on this last one that I mention.

Have a nice day!

0 Kudos
Reply