RIT priority over 'if' block

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

RIT priority over 'if' block

673 Views
lpcware
NXP Employee
NXP Employee
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);
}
0 Kudos
Reply
2 Replies

663 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by aenglot on Wed Nov 28 16:02:03 MST 2012
sounds good. thanks!
0 Kudos
Reply

663 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Nov 28 13:49:26 MST 2012

Quote: aenglot
Hi sorry if this question is annoying, hopefully it has a simple and easy solution.



Yes :)

#1 Add a flag to read a new pressed button. Reset this flag if your button is released again. So you printf only one time and not as long as your button is pressed ;)

#2 Move your RIT stuff (rit_timer_counter >= 100...) into your RIT interrupt handler. So your slow printf isn't delaying it :eek:
0 Kudos
Reply