<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: My SysTick Handler remains within the loop  in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521253#M4091</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by A0087717 on Sat May 31 09:42:13 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 17:48:29 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T17:48:29Z</dc:date>
    <item>
      <title>My SysTick Handler remains within the loop</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521251#M4089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by A0087717 on Sat May 31 07:46:16 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My initialization of the SysTick feature in the main program is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SysTick -&amp;gt; CTRL = 7;&amp;nbsp;&amp;nbsp;&amp;nbsp; //enable counter and interrupt, use CPU clk &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SysTick-&amp;gt;LOAD = 999999;&amp;nbsp; //value to load 10ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code for the handler function: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;void SysTick_Handler (void)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SYSTICK_ClearCounterFlag();&amp;nbsp;&amp;nbsp;&amp;nbsp; //clear at every 10ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;count++;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //counter to tally number of interrupts&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if (count == 500)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //loop accessed every 5s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;count=0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /counter reset back to 0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lot1_rotate();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //servo arm in 'open' position&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Timer0_us_Wait(2000000);//servo arm in same position for 2s &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lot4_rotate();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //servo arm in 'closed' position&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestion for the Handler to exit when the program executes the functions within the if loop?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:48:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521251#M4089</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: My SysTick Handler remains within the loop</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521252#M4090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by R2D2 on Sat May 31 07:59:16 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Would suggest to use a flag inside handler and do this things in your while(1) loop....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Things like: &lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
Timer0_us_Wait(2000000); //servo arm in same position for 2s &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;are not very helpul in a 10ms interrupt handler&amp;nbsp; &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:48:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521252#M4090</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: My SysTick Handler remains within the loop</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521253#M4091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by A0087717 on Sat May 31 09:42:13 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:48:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521253#M4091</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: My SysTick Handler remains within the loop</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521254#M4092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by R2D2 on Sat May 31 10:06:53 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: A0087717&lt;/STRONG&gt;&lt;BR /&gt;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.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just use a simple counter in SysTick, something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;volatile uint32_t delay;//delay counter
volatile uint8_t&amp;nbsp; delay_end;//end of delay[color=#f00] flag[/color]

//SysTick Interrupt
void SysTick_Handler(void)
{
 if(delay)//delay
 {
&amp;nbsp; delay--;//dec delay
&amp;nbsp; if(delay == 0)//delay end
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; delay_end =1; 
&amp;nbsp; }
 }
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;In your main program, set your delay time: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;delay = 500;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and wait until this flag is reached with&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
if(delay_end)
{ 
 delay_end =0;//reset flag
 ...do funny stuff here
 
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:48:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521254#M4092</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: My SysTick Handler remains within the loop</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521255#M4093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by A0087717 on Sat May 31 11:23:53 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much. I shall try those codes. Best regards.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:48:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/My-SysTick-Handler-remains-within-the-loop/m-p/521255#M4093</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:48:30Z</dc:date>
    </item>
  </channel>
</rss>

