My SysTick Handler remains within the loop

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

My SysTick Handler remains within the loop

1,181 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by A0087717 on Sat May 31 07:46:16 MST 2014
Hi,
I am currently doing a project with a couple of features using LPC1769. For one such feature, I would need to operate my servo motor at periodic intervals. Instead of runnning a delay, I have configured to use the SysTick function. As this function provides an interrupt in ms range, I have included a variable (count) within the SysTick Handler in order to stretch the time intervals beyond the ms range.

When executed, my program functions well (can access other features of the program) till the program enters the 'if' loop in the SysTick Handler for the first time. Once entered, only the servo is activated every 5 secs; all other features are disabled. The program doesn't exit the SysTick Handler.

My initialization of the SysTick feature in the main program is as follows:

SysTick -> CTRL = 7;    //enable counter and interrupt, use CPU clk
SysTick->LOAD = 999999;  //value to load 10ms


My code for the handler function:

void SysTick_Handler (void)
{
SYSTICK_ClearCounterFlag();    //clear at every 10ms
count++;                       //counter to tally number of interrupts
if (count == 500)              //loop accessed every 5s
{
count=0;              /counter reset back to 0.
lot1_rotate();        //servo arm in 'open' position
Timer0_us_Wait(2000000);//servo arm in same position for 2s
lot4_rotate();        //servo arm in 'closed' position
}
}

Any suggestion for the Handler to exit when the program executes the functions within the if loop?
Labels (1)
0 Kudos
4 Replies

948 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by A0087717 on Sat May 31 11:23:53 MST 2014
Thank you very much. I shall try those codes. Best regards.
0 Kudos

948 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat May 31 10:06:53 MST 2014

Quote: A0087717
Thank you very much for your suggestion. As I'm still quite new to LPC1769, I'm not too sure on the setting of the flag.



Just use a simple counter in SysTick, something like:

volatile uint32_t delay;//delay counter
volatile uint8_t  delay_end;//end of delay[color=#f00] flag[/color]

//SysTick Interrupt
void SysTick_Handler(void)
{
 if(delay)//delay
 {
  delay--;//dec delay
  if(delay == 0)//delay end
  {
   delay_end =1; 
  }
 }
}

In your main program, set your delay time:

delay = 500;


and wait until this flag is reached with
if(delay_end)
{ 
 delay_end =0;//reset flag
 ...do funny stuff here
 
}






0 Kudos

948 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by A0087717 on Sat May 31 09:42:13 MST 2014
Thank you very much for your suggestion. As I'm still quite new to LPC1769, I'm not too sure on the setting of the flag.

Is it like when the count reaches 500 in the SysTick handler, I clear a GPIO pin; and prior to this, I enable the GPIO pin to detect a falling edge to trigger an interrupt (EINT3).
0 Kudos

948 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat May 31 07:59:16 MST 2014
Would suggest to use a flag inside handler and do this things in your while(1) loop....

Things like:
Timer0_us_Wait(2000000); //servo arm in same position for 2s 


are not very helpul in a 10ms interrupt handler 
0 Kudos