RIT priority over 'if' block

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by aenglot on Wed Nov 28 13:13:59 MST 2012
Hi sorry if this question is annoying, hopefully it has a simple and easy solution.

so i have a switch hooked up to my LPC1769 at one of the GPIO pins, and i want my program to print a timestamp every time the swith is pressed. i want millisecond resolution so i'm using the RIT for milliseconds, and the RTC for the minutes and seconds. the problem i'm having is that if i keep the switch pressed down, the RTC values update (great!), but the RIT value doesn't (not so great). i'm assuming the 'if' statement is overriding the RIT interrupt handler. is there a way to give the RIT priority over the if statement?

the code looks something like this (initialization of RTC and RIT were copied from the examples unaltered):

while (1)
   current_time = RTCGetTime();

   if ( rit_timer_counter >= 100 )   // 1s
      rit_timer_counter = 0;

   if(LPC_GPIO2->FIOPIN & SWITCH)        //get pin
      printf( "time: %d:%d:%d \n", i,
      current_time.RTC_Min, current_time.RTC_Sec, rit_timer_counter);