<?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: Frequency n Period Calculation Of an Input Signal in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184088#M6351</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello bigmac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I didn't get the no 158400???&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;for a given PPR (pulse per revolution) and wheel radius, I have got the calculated values of wheel speed as 56.548Kmph and wheel RPM as 500. and the formula involved is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wheel speed (in Kmph) = (no of pulses per sec / PPR)*circumference*(3600)*(1/1000000)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while coding, I did not include these calculations in the ISR, what I did is called a separate functions for these calculations outside the ISR but have included the parameters that were used in the ISR.. When i tried to run, I have noticed on the true-time simulator window that the RPM and Wheel speed are not appearing against the variables....&lt;/P&gt;&lt;P&gt;what might have gone wrong? verify the ISR code that&amp;nbsp;is there in my previous(first) post..&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;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Mar 2010 16:12:46 GMT</pubDate>
    <dc:creator>admin</dc:creator>
    <dc:date>2010-03-26T16:12:46Z</dc:date>
    <item>
      <title>Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184082#M6345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;&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;&lt;/P&gt;&lt;P&gt;I have written&amp;nbsp; code to measure the parameters (frequency, period, duty cycle)of an input signal fed from a function generator, using interrupts. I have used the Enhanced Capture timer for the input capture and PLL. I have run the program on HCS12X demokit&amp;nbsp; SK-S12XDP512A but the frequency and period calculation is going wrong... also, i have declared period as an unsigned long int and frequency as a float type...I have attatched my program. do verify and clarify my doubt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#include &amp;lt;hidef.h&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* common defines and macros */&lt;BR /&gt;#include &amp;lt;mc9s12xdp512.h&amp;gt;&lt;BR /&gt;#pragma LINK_INFO DERIVATIVE "mc9s12xdp512"&lt;/P&gt;&lt;P&gt;void init_PLL(void);&lt;BR /&gt;void init_ECT(void);&lt;BR /&gt;void period_frequency(void);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned int r1;&lt;BR /&gt;unsigned int r2;&lt;BR /&gt;unsigned int r3;&lt;BR /&gt;unsigned int count;&lt;BR /&gt;long int period;&lt;BR /&gt;float&amp;nbsp;&amp;nbsp;&amp;nbsp; frequency;&lt;BR /&gt;unsigned long int freq;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void main(void)&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp;init_PLL();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;init_ECT();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;EnableInterrupts;&lt;BR /&gt;&amp;nbsp;for(;&lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif"&gt;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/A&gt;&lt;BR /&gt;&amp;nbsp;{&lt;BR /&gt;&amp;nbsp;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void init_PLL(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;CLKSEL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;= 0x7F;&amp;nbsp;&amp;nbsp; // Deselect PLL Clock so can change SYNR, REFDV, PLLCTL&lt;BR /&gt;&amp;nbsp;PLLCTL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;= 0xBF;&amp;nbsp;&amp;nbsp; // Turn off PLL so can change freq&lt;BR /&gt;&amp;nbsp;SYNR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; 4;&lt;BR /&gt;&amp;nbsp;REFDV&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; 0;&lt;BR /&gt;&amp;nbsp;PLLCTL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0xD1;&amp;nbsp;&amp;nbsp; // 1101 0001 ; Enable auto tracking mode, turn on pll, clock monitor, self clock mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;CLKSEL_PLLSEL =&amp;nbsp;&amp;nbsp;&amp;nbsp; 1;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void init_ECT(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;ICSYS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // no input sharing, normal operation&lt;BR /&gt;&amp;nbsp;TSCR2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x81;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // timer overflow interrupt enable, prescaler factor 2&lt;BR /&gt;&amp;nbsp;TIOS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // set the channel to input capture&lt;BR /&gt;&amp;nbsp;TCTL4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x10;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // capture rising edges&lt;BR /&gt;&amp;nbsp;TFLG1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0xFF;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // clear flags&lt;BR /&gt;&amp;nbsp;TIE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 0x04;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // enable the timer interrupts&lt;BR /&gt;&amp;nbsp;TSCR1_TEN = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // timer on&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#pragma CODE_SEG __NEAR_SEG NON_BANKED&lt;BR /&gt;interrupt 10 void TIMCH2_ISR(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;TFLG1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; 0x04;&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; //clear the flag&lt;BR /&gt;&amp;nbsp;r1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp; TC2;&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;&lt;BR /&gt;&amp;nbsp;r2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = count;&lt;BR /&gt;&amp;nbsp;period&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = (r1+(r2*0xFFFF)-r3)*0.1;&amp;nbsp; // calculates the period&lt;BR /&gt;&amp;nbsp;r3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = r2;&lt;BR /&gt;&amp;nbsp;count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;frequency&amp;nbsp; = 1.0/period;&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; // frequency value in floating point&lt;BR /&gt;&amp;nbsp;freq&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = (int) frequency;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //frequency value in integer&lt;BR /&gt;}&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#pragma CODE_SEG __NEAR_SEG NON_BANKED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;interrupt 16 void TIMOVF_ISR(void)&lt;BR /&gt;{&amp;nbsp;&lt;BR /&gt;&amp;nbsp;TFLG2_TOF = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // clear the overflow flag&lt;BR /&gt;&amp;nbsp;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; //increment the counter&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;#pragma CODE_SEG DEFAULT&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Mar 2010 18:02:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184082#M6345</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2010-03-18T18:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184083#M6346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; period&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = (r1+(r2*0xFFFF)-r3)*0.1;&amp;nbsp; // calculates the period&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;timer overflow period is 0x10000, not 0xFFFF.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) r2 is short, 0xFFFF is also short. In C short times short gives short. You should typecast at least one of multipliers to long. This should work better:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; period&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = (r1+((unsigned short)r2*0x10000UL)-r3)*0.1;&amp;nbsp; // calculates the period&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) Your algorithm isn't good to measure long time periods. Please download HC11 reference manual &lt;A href="http://www.freescale.com/files/microcontrollers/doc/ref_manual/M68HC11RM.pdf" rel="nofollow" target="_blank" title="HC11 reference manual"&gt;here&lt;/A&gt;&amp;nbsp;and look at 10.5.5 Measuring Long Time Periods with Input Capture and Overflow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Mar 2010 20:35:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184083#M6346</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2010-03-18T20:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184084#M6347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Manasa,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another point to consider is that the floating point operations are very slow.&amp;nbsp; It would be a good idea to move the floating code from the interrupt routines to the mainline otherwise your minimum period may be limited.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The interrupt code should do the minimum work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bye&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Mar 2010 06:34:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184084#M6347</guid>
      <dc:creator>pgo</dc:creator>
      <dc:date>2010-03-19T06:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184085#M6348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello manasa,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There seems to be some further problems with your period calculation, in addition to the incorrect constant multiplier for the &lt;FONT face="courier new,courier"&gt;count&lt;/FONT&gt; value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The &lt;FONT face="courier new,courier"&gt;r3&lt;/FONT&gt; value being subtracted is the &lt;FONT face="courier new,courier"&gt;count&lt;/FONT&gt; value from the previous interrupt.&amp;nbsp; Since the &lt;FONT face="courier new,courier"&gt;count&lt;/FONT&gt; value starts from zero each time, this would appear to be&amp;nbsp;incorrect.&amp;nbsp; It would make more sense with &lt;FONT face="courier new,courier"&gt;r3 = r1;&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;r3 = TC2;&lt;/FONT&gt; &lt;FONT face="arial,helvetica,sans-serif"&gt;after the period calculation.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;The final constant multiplier of 0.1 within the &lt;FONT face="courier new,courier"&gt;period&amp;nbsp;&lt;/FONT&gt;expression is a floating point value.&amp;nbsp; Since all other values within the expression are 16-bit or 32-bit integers, you will want to avoid unnecessary floating point conversions, particularly within the ISR, as has already been mentioned.&amp;nbsp; Therefore the&amp;nbsp;expression should be modified&amp;nbsp;as follows:&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;period = ( ... ) / 10;&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Mar 2010 21:50:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184085#M6348</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-03-19T21:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184086#M6349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Bigmac, thank you.&lt;/P&gt;&lt;P&gt;It worked. Now, there is another task of calculating wheel Speed and RPM for a given PPR(Pulse per Revolution) and a given wheel radius..&lt;/P&gt;&lt;P&gt;I consider the PPR&amp;nbsp;n WheelSpeed as two variables here.. how would the code look like?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Mar 2010 13:31:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184086#M6349</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2010-03-25T13:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184087#M6350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not know the scaling of your measured pulse period, but I will assume that it is an integral number of microseconds.&amp;nbsp; I will also assume that the wheel speed result that you require is an integer number of kilometres per hour, and that integer calculations would be used for efficiency.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the following calculation, R is the wheel radius in millimetres, N is the number of pulses per revolution, and T is the pulse period in microseconds.&amp;nbsp; Also the integer approximation 22 / 7 is used for pi.&amp;nbsp; If my reckoning is correct, the following expression should provide the wheel speed.&amp;nbsp; Obviously the calculation will use 32-bit values - some additional casts may prove to be necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;speed = (byte)(158400 * R / (7 * N * T));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;If the calibration of the pulse period differs from that assumed, this will need to be taken into account in the scaling of the result.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Mar 2010 02:35:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184087#M6350</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-03-26T02:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184088#M6351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello bigmac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I didn't get the no 158400???&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;for a given PPR (pulse per revolution) and wheel radius, I have got the calculated values of wheel speed as 56.548Kmph and wheel RPM as 500. and the formula involved is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wheel speed (in Kmph) = (no of pulses per sec / PPR)*circumference*(3600)*(1/1000000)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while coding, I did not include these calculations in the ISR, what I did is called a separate functions for these calculations outside the ISR but have included the parameters that were used in the ISR.. When i tried to run, I have noticed on the true-time simulator window that the RPM and Wheel speed are not appearing against the variables....&lt;/P&gt;&lt;P&gt;what might have gone wrong? verify the ISR code that&amp;nbsp;is there in my previous(first) post..&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;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Mar 2010 16:12:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184088#M6351</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2010-03-26T16:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184089#M6352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have chosen to directly&amp;nbsp;utilise the period between pulses (in microseconds) rather than pulse frequency, since the period is the quantity measured.&amp;nbsp; I have also calculated the circumference of the wheel from its radius (2 * pi * R) with the radius conveniently in millimetres, and with the approximation for pi of 22 / 7, which should give sufficient accuracy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the symbols that I defined in my previous post, we have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;speed&amp;nbsp; = (1000000 / (N * T)) * (2 * 22 / 7 * R / 1000) * 3600 / 1000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#0000ff"&gt;Revs per second&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp; &amp;nbsp;Circumference (m)&amp;nbsp;&amp;nbsp;&amp;nbsp; |Factor for km/h&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Reducing all the numeric value to a simple quotient, and re-arranging the sequence&amp;nbsp;to suit an&amp;nbsp;integer calculation process, gives the expression in my previous post.&amp;nbsp; The value 158400 was obtained from (2 * 22 * 3600).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ISR code will need to flag the main loop (via a volatile global variable) when each new period reading has been completed.&amp;nbsp; Only when the flag is set will the main loop calculate the speed from the measured period.&amp;nbsp; Perhaps you are not doing this.&amp;nbsp; Perhaps you will need to use the real hardware, rather than simulation, to test the input capture and timer overflow processes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Mar 2010 23:52:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184089#M6352</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-03-26T23:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency n Period Calculation Of an Input Signal</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184090#M6353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;FONT color="#000000" face="Times New Roman" size="3"&gt;hello bigmac,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Times New Roman" size="3"&gt;&amp;nbsp;thank you again. I understood what you suggested in the thread n I have modified the code accordingly..&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Times New Roman" size="3"&gt;The main loop is continuous and the values are updating.. Thank you so much.. Iam looking forward to more suggestions and help in the future..&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Mar 2010 16:25:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Frequency-n-Period-Calculation-Of-an-Input-Signal/m-p/184090#M6353</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2010-03-27T16:25:44Z</dc:date>
    </item>
  </channel>
</rss>

