Timers on KW01Z

cancel
Showing results for 
Search instead for 
Did you mean: 

Timers on KW01Z

459 Views
Contributor II

I am building an app from the wireless UART bare metal app and am in need of getting access to a timer to time stamp interrupt events.  I have modified the Switch_Press_ISR in keyboard.c so that I get an event set whenever my circuit activates the input used by SW4 on the freedom board.  I can reliably detect these events and count them.  Now I need to time the duration between them.  My initial attempts have been to put a call to StackTimer_GetCounterValue() in Switch_Press_ISR.  This results in always getting the same nonzero value returned by StackTimer_GetCounterValue().  I then tried to use the SDK function HWTIMER_SYS_GetTicks(&variable) and I always get zero values.  I’m thinking there is more setup to use HWTIMER_SYS_GetTicks such as calls to HWTIMER_SYS_Init and HWTIMER_SYS_Start.  I need to understand what is happening with the StackTimer_GetCounterValue function from Wireless_UartApp.c or how to setup and properly call HWTIMER_SYS_Init of the SDK. 

Labels (1)
0 Kudos
7 Replies

67 Views
NXP Employee
NXP Employee

Hi Mark,

To get a timestamp in the ISR you should call first TMR_TimeStampInit  and then TMR_GetTimestamp.

Could you please confirm if your issue is solved by using that timer?

Best regards,

Luis Burgos.

0 Kudos

67 Views
NXP Employee
NXP Employee

Hi Mark,

It's not recommendable to modify the functions of connectivity framework, but understanding your issue let's do your implementation there.

I received your project files from Hy Mai, please let me try solve your issue of getting a timer working on Switch_press_ISR and I will back to you asap.

You can use the I2C drivers of the KSDK for the KL26 MCU wich it's compatible with KW01.

Best regards,

Luis Burgos.

0 Kudos

67 Views
Contributor II

I don't know how to attach the file I referenced above. Please let me know how to do that.

0 Kudos

67 Views
Contributor II

Is there some example code of I2C in the application?  I will be connecting a PCA9956 chip to the MKW01Z128.  I need to send commands to it and read registers back from it.

0 Kudos

67 Views
Contributor II

Attached is a little zip of the three files I have touched in the smac_wireless_wart_bm example code.  Rev1 is the files that are where I am trying to add reading of a processor time tick to determine frequency.  Remove “.Rev1” from the end of the file names and put them into a new IAR project of smac_wireless_wart_bm is you wish to compile your one version and run it on a freedom board.  The directory structure of the zip mirrors that of my IAR project where I am getting the files.

 

The Oscillloscope screen shot shows my issue where I am not getting a non-zero value when calling HWTIMER_SYS_GetTicks.  Notice that I get one short (purple – probe 3) pulse from one spin of 10240 in a while loop between LED4 on and LED4 off.  This is my signal that a SLIC edge from my circuit attached to SW4 (green – probe 4) of the freedom board detected the edge in the Switch_Press_ISR of keyboard.c.  Then I get a double long LED4 pulse showing that my first read from HWTIMER_SYS_GetTicks is zero followed by another double long pulse showing that my second read from HWTIMER_SYS_GetTicks is zero.  The last LED4 pulse shows that both the first and second read from HWTIMER_SYS_GetTicks are equal to eachother.

 

I need to get some way of reading a system tick timer that is always running so that I can detect frequency in the state machine I am writing as function HandleSLICdetection in Wireless_UartApp.c.  This could be a free running timer or one that I start in the Switch_Press_ISR function so I can have it time out when durations get too long.  I am also searching to find out what timers are NOT used by the example code because we would like to keep all the functionality of the example code and just insert our functions into smac_wireless_wart_bm.  The desire is to not have to rewrite all the wireless and serial UART functionality in a project from the ground up.

0 Kudos

67 Views
NXP Employee
NXP Employee

Hi Mark,

I suppose you are working with KW01 connectivity software (KSDK based), it's correct?

I recommend you to do all your described implementation in application layer (App.c file).

For SW pressing: You can create a callback function for the SW pressing, here an example:

/*Add the keyboard drivers in App.c*/

#include "Keyboard.h"

/*Declaration of push buttons callback function in App.c file*/

static void App_HandleKeys( key_event_t events );

/*Register push buttons callback function in App_init function in App.c*/

KBD_Init(App_HandleKeys);

/*Definition of push buttons callback function in App.c file*/

static void App_HandleKeys
  (
  key_event_t events  /*IN: Events from keyboard module */
  )
{

      if (events == gKBD_EventPB4_c) //
      {

         //code

       }

events = 0;

  }

For timers: Connectivity framework includes functions to work with KW01 timers, here an example:

/*Add the timers file in App.c*/

#include "TimersManager.h"

/*Add ID declaration of your timer in App.c*/

tmrTimerID_t MyFirstTimerID = gTmrInvalidTimerID_c;

/*Allocate your timer in App_init function in App.c*/

MyFirstTimerID = TMR_AllocateTimer();

/*Declaration of your timer callback in App.c*/

static void MyFirstTimerCallback (uint8_t MyParameter); 

/*Definition of your timer callback in App.c*/

static void MyFirstTimerCallback (uint8_t MyParameter)

{

  MyParameter=0;

  /*code*/

}

/*Start the single shot timer in App.c*/

TMR_StartSingleShotTimer(MyFirstTimerID , 1000, (pfTmrCallBack_t)MyFirstTimerCallback , (void*)MyParameter);  
   

Note: This example is using the single shot timer, but there are other types of timers that you can check in TimersManager.h... example: TMR_StartIntervalTimer, TMR_StartSecondTimer, TMR_StartTimer, TMR_StopTimer, etc.

Please let me know if this is useful for you.

Best regards,

Luis Burgos.

0 Kudos

67 Views
Contributor II

Thanks for the response.  I have been through all the keyboard stuff and need to respond faster than the keyboard event happens.  I built code using the keyboard event handler first and it worked only for SW4 button presses and not the fast pulses of my SLIC circuit connected to SW4.  Hence why I modified Switch_press_ISR.  Any kind of keyboard event I tried to make was ignored by the keyboard code due to the very short duration of the SLIC pulse I am applying with my circuit to the input used by SW4.  No I just need to get a sys tick value from the processor clock so I can track when the SLIC edge happened.  Hence my questions about HWTIMER_SYS_GetTicks and StackTimer_GetCounterValue.  Can you get a more in depth answer to my question below about these?

0 Kudos