Interrupt Timer

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

Interrupt Timer

915 Views
johanandrade
Contributor III

Hey support,

I'm trying to implement a timer interrupt to my Thread application. Would LPTMR be the easiest to use to accomplish the following? Or would something else be easier?

  • An event from one R41Z triggers a function to send a High signal to another R41Z with a motor wired to it. I'd like for this High signal to elapse about 30-35 seconds. After the time has elapsed it would then send the Low signal function to stop the motor.

Any pointers or available references would be helpful. Thanks!

Labels (2)
2 Replies

667 Views
ovidiu_usturoi
NXP Employee
NXP Employee

Hi johanandrade‌,

The easiest way is to use TimersManager module (see TimersManager.c, TimersMnager.h) files.

As API the following functions should be used:

   - TMR_AllocateTimer - to allocate the timer;

   - TMR_StartSingleShotTimer - to start the timer;

   - TMR_FreeTimer - to free the timer;

An example of usage is usually presented in each demo application. Please search in your project after  "mAppTimerId" or "tmrStartApp".

Regards,

Ovidiu

0 Kudos

667 Views
johanandrade
Contributor III

Thanks Ovi!

After analyzing the example, here's what I was able to get working. I tested it using an LED turning on for 10 seconds before turning off. Posting code for reference.

/*==================================================================================================
Private macros
==================================================================================================*/
.
.
.
#define gLedTimeout_c 10000 /* milliseconds */


/*==================================================================================================
Public global variables declarations
==================================================================================================*/
.
.
.
/* Led timer Id */
tmrTimerID_t mLedTimerId = gTmrInvalidTimerID_c;


/*==================================================================================================
Public functions
==================================================================================================*/
.
.
.

void APP_LightShellEventReceived(void)
{
if(isLedOn)
{
(void)NWKU_SendMsg(APP_SendExtLedOff, NULL, mpAppThreadMsgQueue);
isLedOn = FALSE;
}
else{
(void)NWKU_SendMsg(APP_SendExtLedOn, NULL, mpAppThreadMsgQueue);
isLedOn = TRUE;

if(mLedTimerId == gTmrInvalidTimerID_c)
{
mLedTimerId = TMR_AllocateTimer();
}

/* Validate Led timer Id */
if(mLedTimerId != gTmrInvalidTimerID_c)
{
/* Start the led timer. Wait gLedTimeout_c
to start countdown before turning off led. */
TMR_StartSingleShotTimer(mLedTimerId, gLedTimeout_c, APP_SendExtLedOff, NULL);
}
}