<?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: Trouble in understanding function inside library in LPCXpresso IDE</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526815#M136</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 Sun Apr 05 11:44:49 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Or at least drop a few hints :)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A capture timer is a timer which has a special cature input to trigger an interrupt. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In your case: a rising or falling edge is triggering an interrupt. Meanwhile the timer is running and counting the time between this interrupts. This time is stored in a special register, the capture register.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So this approch can measure the full period of your sensor output. The interrupt is triggered every 3ms and delivering the period time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you now want to read the temperature you can just use the last period time and calculate the temperature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No delay&amp;nbsp; :) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That should be doable with about 12 lines of code&amp;nbsp; :O &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to find a capture sample here at the moment and I think I can post an example in a few minutes&amp;nbsp; 8-) &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jun 2016 00:11:47 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-16T00:11:47Z</dc:date>
    <item>
      <title>Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526800#M121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sat Apr 04 09:02:33 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi , &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm doing a school project where I am required to use a temperature sensor to printf out the current temperature detected by the sensor. The problem is that the function takes too long , causing an inevitable delay. I wanted to try to edit the function inside the library but I'm not able to understand the code. Was hoping to get some help here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The function in the library is as follows : &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;
int32_t temp_read (void)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t state = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t t1 = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; uint32_t t2 = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int i = 0;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /*
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * T(C) = ( period (us) / scalar ) - 273.15 K
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * 10T(C) = (period (us) / scalar_div10) - 2731 K
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */

&amp;nbsp;&amp;nbsp;&amp;nbsp; state = GET_TEMP_STATE;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /* get next state change before measuring time */
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(GET_TEMP_STATE == state);
&amp;nbsp;&amp;nbsp;&amp;nbsp; state = !state;

&amp;nbsp;&amp;nbsp;&amp;nbsp; t1 = getTicks();

&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i = 0; i &amp;lt; NUM_HALF_PERIODS; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(GET_TEMP_STATE == state);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; state = !state;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; t2 = getTicks();
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (t2 &amp;gt; t1) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2 = t2-t1;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; else {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2 = (0xFFFFFFFF - t1 + 1) + t2;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }


&amp;nbsp;&amp;nbsp;&amp;nbsp; return ( (2*1000*t2) / (NUM_HALF_PERIODS*TEMP_SCALAR_DIV10) - 2731 );
}
&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;These are the definitions : &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;
#define TEMP_TS1 0
#define TEMP_TS0 0

#if TEMP_TS1 == 0 &amp;amp;&amp;amp; TEMP_TS0 == 0
#define TEMP_SCALAR_DIV10 1
#define NUM_HALF_PERIODS 340
#elif TEMP_TS1 == 0 &amp;amp;&amp;amp; TEMP_TS0 == 1
#define TEMP_SCALAR_DIV10 4
#define NUM_HALF_PERIODS 100
#elif TEMP_TS1 == 1 &amp;amp;&amp;amp; TEMP_TS0 == 0
#define TEMP_SCALAR_DIV10 16
#define NUM_HALF_PERIODS 32
#elif TEMP_TS1 == 1 &amp;amp;&amp;amp; TEMP_TS0 == 1
#define TEMP_SCALAR_DIV10 64
#define NUM_HALF_PERIODS 10
#endif


#define P0_6_STATE ((GPIO_ReadValue(0) &amp;amp; (1 &amp;lt;&amp;lt; 6)) != 0)
#define P0_2_STATE ((GPIO_ReadValue(0) &amp;amp; (1 &amp;lt;&amp;lt; 2)) != 0)


#ifdef TEMP_USE_P0_6
#define&amp;nbsp;&amp;nbsp;&amp;nbsp; GET_TEMP_STATE P0_6_STATE
#else
#define&amp;nbsp;&amp;nbsp;&amp;nbsp; GET_TEMP_STATE P0_2_STATE
#endif

&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note that the library does contain other functions as well , so not all the defined terms will be used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;I have also looked at the datasheet ( &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fdatasheets.maximintegrated.com%2Fen%2Fds%2FMAX6576-MAX6577.pdf" rel="nofollow noopener noreferrer" target="_blank"&gt;http://datasheets.maximintegrated.com/en/ds/MAX6576-MAX6577.pdf&lt;/A&gt;&lt;SPAN&gt; ) of the temperature sensor , the general descriptions of how it works is :&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Figure 3 shows a quick-look application circuit for the&lt;BR /&gt;MAX6576 using a universal counter measuring period.&lt;BR /&gt;TS1 and TS0 are both tied to ground to select a scalar&lt;BR /&gt;multiplier of 10μs/°K. The MAX6576 converts the ambient&lt;BR /&gt;temperature into a square wave with a period that is&lt;BR /&gt;10 times the absolute temperature of the device in μs.&lt;BR /&gt;At room temperature, the universal counter will display&lt;BR /&gt;approximately 2980μs&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I understand the code up to the line "&amp;nbsp;&amp;nbsp; state = GET_TEMP_STATE; " , I'm lost after that point.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you and sorry for the trouble.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526800#M121</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526801#M122</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 Apr 04 10:22:38 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;I understand the code up to the line "&amp;nbsp;&amp;nbsp; state = GET_TEMP_STATE; " , I'm lost after that point.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then it's time to start the debugger and investigate&amp;nbsp; :) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Obviously this code is measuring a pulse time from the sensor...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;First of all find out how this pulse time is measured...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;BTW: Instead using an external interrupt &amp;amp; timer you can use a capture timer&amp;nbsp; :O &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sample: #9 of&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.lpcware.com%2Fcontent%2Fforum%2Flpc1769-capture-timer" rel="nofollow" target="_blank"&gt;http://www.lpcware.com/content/forum/lpc1769-capture-timer&lt;/A&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526801#M122</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526802#M123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 01:51:29 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;I understand the code up to the line "&amp;nbsp;&amp;nbsp; state = GET_TEMP_STATE; " , I'm lost after that point.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then it's time to start the debugger and investigate&amp;nbsp; :) &lt;BR /&gt;&lt;BR /&gt;Obviously this code is measuring a pulse time from the sensor...&lt;BR /&gt;&lt;BR /&gt;First of all find out how this pulse time is measured...&lt;BR /&gt;&lt;BR /&gt;BTW: Instead using an external interrupt &amp;amp; timer you can use a capture timer&amp;nbsp; :O &lt;BR /&gt;&lt;BR /&gt;Sample: #9 of&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.lpcware.com%2Fcontent%2Fforum%2Flpc1769-capture-timer" rel="nofollow" target="_blank"&gt;http://www.lpcware.com/content/forum/lpc1769-capture-timer&lt;/A&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok I've gone ahead and disected the code. I'm able to roughly get an idea of what the code is doing , it's just measuring changes in the state of the pin , when the state of the pin goes from 0 to 1 and back to 0 again , that is one pulse , or in other words half a period of a 50% duty cycle square waveform. I can also see that what causes the delay is probably the for loop that loops until NUM_HALF_PERIODS is reached. I'm still slightly unclear about this segment of the code , my guess on this segment is that it's take the average of a large sample size of many pulse times( or half periods ) to get a good estimate of the value. But why is the NUM_HALF_PERIODS defined as 320 ? Is there a reason why it should be set at this value? or is it just to get a large enough sample size. I can see under the initial definitions also that when the scalar multiplier is increased , the NUM_HALF_PERIODS defined is reduce to a smaller number. Not sure why this is so , or if there's a relation between the 2 that I'm not seeing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526802#M123</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526803#M124</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 Sun Apr 05 04:29:07 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the author of this code was trying to get a temperature value from his measured pulse time. Probably he was just changing&amp;nbsp; NUM_HALF_PERIODS until the temperature value was halfway correct&amp;nbsp; :O &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;And probably his time base (ticks) had also a different frequency...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, there are several options to measure a pulse with LPC1769. Of course it's not very elegant to wait until a half period is measured (in this case &amp;gt; 3ms) as in your sample&amp;nbsp; :(( &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A better way is to use a capture timer which is generating an interrupt&amp;nbsp; :) &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526803#M124</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526804#M125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 07:17:54 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;I think the author of this code was trying to get a temperature value from his measured pulse time. Probably he was just changing&amp;nbsp; NUM_HALF_PERIODS until the temperature value was halfway correct&amp;nbsp; :O &lt;BR /&gt;And probably his time base (ticks) had also a different frequency...&lt;BR /&gt;&lt;BR /&gt;Anyway, there are several options to measure a pulse with LPC1769. Of course it's not very elegant to wait until a half period is measured (in this case &amp;gt; 3ms) as in your sample&amp;nbsp; :(( &lt;BR /&gt;&lt;BR /&gt;A better way is to use a capture timer which is generating an interrupt&amp;nbsp; :)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm still unclear , NUM_HALF_PERIODS doesn't seem to be changing , assuming that pins TS0 and TS1 are fixed connections. I'm still unsure what the for loop is doing. The time base is set to 1milisecond. So my guess is that the for loop estimates the time taken for 340 half periods , and takes the average multiplied by 2 to get the best estimate for 1 period.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also , I've tried looking through the user guide for a capture timer but couldn't find anything.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526804#M125</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526805#M126</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 Sun Apr 05 07:38:47 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;I'm still unclear , NUM_HALF_PERIODS doesn't seem to be changing , assuming that pins TS0 and TS1 are fixed connections. I'm still unsure what the for loop is doing. The time base is set to 1milisecond. So my guess is that the for loop estimates the time taken for 340 half periods , and takes the average multiplied by 2 to get the best estimate for 1 period.&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't know, what 'getTicks()' is doing in detail, but probably it's reading a counter&amp;nbsp; :quest: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If that counter is counting 1ms ticks, it's of course far too slow&amp;nbsp; :(( &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your sensor is generating a pulse around 3000 µs, with 10us/°K. So your timer should count with a time base of 1µs or 10µs&amp;nbsp; ;-) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Also , I've tried looking through the user guide for a capture timer but couldn't find anything.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;User manual:&lt;/SPAN&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;21.6.9 Capture Registers (CR0 - CR1)...&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;Sample: #9 of &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.lpcware.com%2Fcontent%2Fforum%2Flpc1769-capture-timer" rel="nofollow" target="_blank"&gt;http://www.lpcware.com/content/forum/lpc1769-capture-timer&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;should show, how Capture is working...&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526805#M126</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526806#M127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 07:51:37 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;I'm still unclear , NUM_HALF_PERIODS doesn't seem to be changing , assuming that pins TS0 and TS1 are fixed connections. I'm still unsure what the for loop is doing. The time base is set to 1milisecond. So my guess is that the for loop estimates the time taken for 340 half periods , and takes the average multiplied by 2 to get the best estimate for 1 period.&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;I don't know, what 'getTicks()' is doing in detail, but probably it's reading a counter&amp;nbsp; :quest: &lt;BR /&gt;&lt;BR /&gt;If that counter is counting 1ms ticks, it's of course far too slow&amp;nbsp; :(( &lt;BR /&gt;&lt;BR /&gt;Your sensor is generating a pulse around 3000 µs, with 10us/°K. So your timer should count with a time base of 1µs or 10µs&amp;nbsp; ;-) &lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Also , I've tried looking through the user guide for a capture timer but couldn't find anything.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;User manual:&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;21.6.9 Capture Registers (CR0 - CR1)...&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sample: #9 of &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.lpcware.com%2Fcontent%2Fforum%2Flpc1769-capture-timer" rel="nofollow" target="_blank"&gt;http://www.lpcware.com/content/forum/lpc1769-capture-timer&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;should show, how Capture is working...&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;getTicks() is just returning the value of a counter that increments every 1ms. Btw how did you know that my sensor is generating a pulse of 3000 µs? Also , will speeding up the clock cause the reading to be more inaccurate ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526806#M127</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526807#M128</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 Sun Apr 05 08:06:51 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;getTicks() is just returning the value of a counter that increments every 1ms.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; :D &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And do you think that's fast enough for your sensor output?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Btw how did you know that my sensor is generating a pulse of 3000 µs? Also , will speeding up the clock cause the reading to be more inaccurate ?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sensor datasheet is talking about output of 10*T in µs (TS1=0, TS0=0)&amp;nbsp; :O &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So at 0°C that should be 273°K * 10µs/°K = 2730 µs, right&amp;nbsp; :quest: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure what you are trying to measure, but with a 1ms counter your resolution isn't very high...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526807#M128</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526808#M129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 08:17:07 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;getTicks() is just returning the value of a counter that increments every 1ms.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt; :D &lt;BR /&gt;&lt;BR /&gt;And do you think that's fast enough for your sensor output?&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Btw how did you know that my sensor is generating a pulse of 3000 µs? Also , will speeding up the clock cause the reading to be more inaccurate ?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;Sensor datasheet is talking about output of 10*T in µs (TS1=0, TS0=0)&amp;nbsp; :O &lt;BR /&gt;&lt;BR /&gt;So at 0°C that should be 273°K * 10µs/°K = 2730 µs, right&amp;nbsp; :quest: &lt;BR /&gt;&lt;BR /&gt;Not sure what you are trying to measure, but with a 1ms counter your resolution isn't very high...&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;10*T in µs (TS1=0, TS0=0)&lt;/SPAN&gt;&lt;HR /&gt;&lt;SPAN&gt; What is T referring to here?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;So at 0°C that should be 273°K * 10µs/°K = 2730 µs&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this part , so at higher temperatures there will be a longer period which means a longer delay?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also , the final result returns 10 times the value of the temp , by is the returned value multiplied by another 100 in the function ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526808#M129</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526809#M130</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 Sun Apr 05 08:34:12 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;I get this part , so at higher temperatures there will be a longer period which means a longer delay?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At 30°C = 303°K that's 3030µs, just 300µs longer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The delay is caused because you wait until a new half period is starting before you measure it&amp;nbsp; :O &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So you have a delay somewhere between a half period and a full period&amp;nbsp; |( &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Therefore capture timers are used to measure times in interrupts without waiting for something...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Also , the final result returns 10 times the value of the temp , by is the returned value multiplied by another 100 in the function ?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I dont know what the author of this code is trying to do there...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Usually I'm writing my own code and using the features of the chip&amp;nbsp; :) &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526809#M130</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526810#M131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 08:43:47 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;I get this part , so at higher temperatures there will be a longer period which means a longer delay?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;At 30°C = 303°K that's 3030µs, just 300µs longer.&lt;BR /&gt;&lt;BR /&gt;The delay is caused because you wait until a new half period is starting before you measure it&amp;nbsp; :O &lt;BR /&gt;&lt;BR /&gt;So you have a delay somewhere between a half period and a full period&amp;nbsp; |( &lt;BR /&gt;&lt;BR /&gt;Therefore capture timers are used to measure times in interrupts without waiting for something...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Also , the final result returns 10 times the value of the temp , by is the returned value multiplied by another 100 in the function ?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;I dont know what the author of this code is trying to do there...&lt;BR /&gt;Usually I'm writing my own code and using the features of the chip&amp;nbsp; :)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help so far. I feel like I'm very close to optimizing the code. Just one last question. How does the function depend on how long it takes to increment my counter? I'm unable to see any dependance on it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526810#M131</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526811#M132</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 Sun Apr 05 09:09:15 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Thanks for your help so far. I feel like I'm very close to optimizing the code. Just one last question. How does the function depend on how long it takes to increment my counter? I'm unable to see any dependance on it.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How does your counter work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your time base is 1µs, your counter must be fast enough to count.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your main clock is 100Mhz, there are 100 cycles to execute code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That's not much if you try to use SysTick and an interrupt handler for every 1µs :(( &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So you have to use a faster counter&amp;nbsp; :) &lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526811#M132</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526812#M133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 11:04:17 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Thanks for your help so far. I feel like I'm very close to optimizing the code. Just one last question. How does the function depend on how long it takes to increment my counter? I'm unable to see any dependance on it.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;How does your counter work?&lt;BR /&gt;&lt;BR /&gt;If your time base is 1µs, your counter must be fast enough to count.&lt;BR /&gt;&lt;BR /&gt;If your main clock is 100Mhz, there are 100 cycles to execute code.&lt;BR /&gt;That's not much if you try to use SysTick and an interrupt handler for every 1µs :(( &lt;BR /&gt;&lt;BR /&gt;So you have to use a faster counter&amp;nbsp; :)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For my code, my main clock is 100MHz. But I've divided it by 1000 to make it such that it enters the systick handler every 1ms. The systick handler just increments a global variable msTicks. The geticks() function defined inside the temp_read() function just retrieves the current value of msTicks. So if I were to use a faster counter I could always divide my main clock by 1000*1000 to make the code enter the systick handler every 1µs. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I'm trying to figure out now is exactly which line of code in the temp_read() function depends on the systick timer that I've set. t1=geticks(); just retrieves the value of msTicks. I've also observed that it's mainly the for loop that causes the long delay , I've observed it to be out 500ms. So reducing that delay will ultimately make the function process faster.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526812#M133</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526813#M134</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 Sun Apr 05 11:25:21 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;For my code, my main clock is 100MHz. But I've divided it by 1000 to make it such that it enters the systick handler every 1ms. The systick handler just increments a global variable msTicks.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And that's the weakness (or at least one weakness) of your code&amp;nbsp; :( &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are triggering an interrupt with 1MHz your chip is busy with jumping to that interrupt handler, executing this handler and returning&amp;nbsp; :(( &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Therefore it's not useful to use this mechanism for fast counting&amp;nbsp; :O &lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526813#M134</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526814#M135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 11:29:18 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;For my code, my main clock is 100MHz. But I've divided it by 1000 to make it such that it enters the systick handler every 1ms. The systick handler just increments a global variable msTicks.&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;And that's the weakness (or at least one weakness) of your code&amp;nbsp; :( &lt;BR /&gt;&lt;BR /&gt;If you are triggering an interrupt with 1MHz your chip is busy with jumping to that interrupt handler, executing this handler and returning&amp;nbsp; :(( &lt;BR /&gt;&lt;BR /&gt;Therefore it's not useful to use this mechanism for fast counting&amp;nbsp; :O&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dang , my entire code is written based on that logic. I think it would be too late to change it now. So I guess to only way to reduce the delay of temp_read(); would be to use capture timers? Is it possible for you to give me a brief explanation of what capture timers are and why they would be better for the temp_read() function? Or at least drop a few hints :)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526814#M135</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526815#M136</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 Sun Apr 05 11:44:49 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Or at least drop a few hints :)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A capture timer is a timer which has a special cature input to trigger an interrupt. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In your case: a rising or falling edge is triggering an interrupt. Meanwhile the timer is running and counting the time between this interrupts. This time is stored in a special register, the capture register.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So this approch can measure the full period of your sensor output. The interrupt is triggered every 3ms and delivering the period time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you now want to read the temperature you can just use the last period time and calculate the temperature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No delay&amp;nbsp; :) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That should be doable with about 12 lines of code&amp;nbsp; :O &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to find a capture sample here at the moment and I think I can post an example in a few minutes&amp;nbsp; 8-) &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526815#M136</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526816#M137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 11:57:24 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Or at least drop a few hints :)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;A capture timer is a timer which has a special cature input to trigger an interrupt. &lt;BR /&gt;&lt;BR /&gt;In your case: a rising or falling edge is triggering an interrupt. Meanwhile the timer is running and counting the time between this interrupts. This time is stored in a special register, the capture register.&lt;BR /&gt;&lt;BR /&gt;So this approch can measure the full period of your sensor output. The interrupt is triggered every 3ms and delivering the period time.&lt;BR /&gt;&lt;BR /&gt;If you now want to read the temperature you can just use the last period time and calculate the temperature.&lt;BR /&gt;&lt;BR /&gt;No delay&amp;nbsp; :) &lt;BR /&gt;&lt;BR /&gt;That should be doable with about 12 lines of code&amp;nbsp; :O &lt;BR /&gt;&lt;BR /&gt;I'm trying to find a capture sample here at the moment and I think I can post an example in a few minutes&amp;nbsp; 8-)&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I get what you mean. So this timer counts the period between interrupts concurrently with the program , as such , there is no need for the code to get stuck in a for loop , resulting in no delay. So to code this, all I would have to do is program the interrupt to occur whenever there is a state change. Then inside the interrupt handler I'll just get the current value of the timer. So subtracting the 2 different times at 2 different intervals gives me the period exactly , thus giving me the exact period time of 3ms. Am I on the right track ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526816#M137</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526817#M138</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 Sun Apr 05 12:03:13 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Am I on the right track ?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, and if you reset the timer inside the interrupt handler, capture register is storing the period time&amp;nbsp; :) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No subtraction required&amp;nbsp; :O &lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526817#M138</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526818#M139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by mngeowcy on Sun Apr 05 12:08:05 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: mngeowcy&lt;/STRONG&gt;&lt;BR /&gt;Am I on the right track ?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yes, and if you reset the timer inside the interrupt handler, capture register is storing the period time&amp;nbsp; :) &lt;BR /&gt;&lt;BR /&gt;No subtraction required&amp;nbsp; :O&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks alot! I'll go check it out after class tmr. You've really helped me a great deal.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526818#M139</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble in understanding function inside library</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526819#M140</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 Sun Apr 05 12:14:49 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;[u]&lt;/SPAN&gt;&lt;STRONG&gt;Part 1:&lt;/STRONG&gt;&lt;SPAN&gt;[/u]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This function is setting P1.26 as capture input. Timer 0 is runnung with default speed (100MHz / 4), so a prescaler of 25 is generating a time base of 1µs. A rising edge is triggering Timer0 interrupt....&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;//init CAP0.0 / P1.26 to capture with 1µs
void init_Capture(void)
{
 LPC_PINCON-&amp;gt;PINSEL3 |= (3&amp;lt;&amp;lt;20);&amp;nbsp;&amp;nbsp;&amp;nbsp; //Setup P1.26 as CAP0.0
 LPC_TIM0-&amp;gt;PR = (25-1);//1 µs at 100MHz/4
//Note: reset values of timer registers are 0, so setting them isn't necessary
 LPC_TIM0-&amp;gt;CCR =((1&amp;lt;&amp;lt;0)|(1&amp;lt;&amp;lt;2));&amp;nbsp;&amp;nbsp; //capture rising edge with interrupt
 LPC_TIM0-&amp;gt;TCR = 1;&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; //start timer
 NVIC_EnableIRQ(TIMER0_IRQn);
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately P2.5 is no capture input, so you have to connect P1.26 to your sensor output...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:11:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Trouble-in-understanding-function-inside-library/m-p/526819#M140</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:11:50Z</dc:date>
    </item>
  </channel>
</rss>

