<?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>8-bit Microcontrollers中的主题 Re: TPM misbehaves in QD4</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167639#M10859</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 wonder if it is possible that the period you are attempting to measure may exceed the overflow period for TPM1?&amp;nbsp; If so the capture results will be meaningless (without also tracking overflows).&amp;nbsp; Try increasing the prescale value for TPM1, and see if the problem persists.&amp;nbsp; I presume that TPM1 does not have a reduced modulo setting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I notice that you are altering TPM2 settings within the TPM1 ISR, including stopping the timer and changing the modulo value.&amp;nbsp; This is rather unorthodox.&amp;nbsp; The more traditional aproach would be to utilize output compare interrupt, and leave the TPM running continuously with full modulo count. From within the TPM1 ISR, simply read the current 16-bit counter value for TPM2, add the required timeout delay (0x7000), and update the TPM2 channel register.&amp;nbsp; A channel interrupt will occur upon expiry of the timeout period.&amp;nbsp;&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;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Mar 2009 03:00:54 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2009-03-30T03:00:54Z</dc:date>
    <item>
      <title>TPM misbehaves in QD4</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167638#M10858</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 am using QD4 for a Universal IR capture algorithm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using TPM1CH1 (Pin 7,alternate function is PTAD1 as GPIO).This pin is used as an Interrupt driven&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;counter which will measure duration of incoming pulses between rising and falling edges (interrupts).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using a Timeout of 90msec after the first edge intr occurs.I also use some 70 bytes for this train&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;of pulses.So that after acquiring 70 bytes of info I fall out of that routine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works fine for a RC5/6 type of protocol which has a repeatabilty of ~100msec,but with some&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;others like SIRC,which has repeatable w/f in ~15msec,multiple packets of data are captured.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here as an error correction mechanism,I will lookout for a TPMCNT&amp;gt;my threshold,after which I skip all&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the data ,so effectively only a single frame is put up for conditioning.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is used in some Compare and Actions based on those Compares.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Channel ISR is attached here&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
 //TPM1 channel INTR Service Routine //-------------------------------------------------------------------------------------// //---------------------------------------------------------------------// TPM1channel 1 edge Interrupt//----------------------------------------------------------------------interrupt 6 void TPM1C1_ISR (void){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMC1SC;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMC1SC_CH1F=RESET;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(i==70)&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; TPMC1SC_CH1IE=RESET;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMCNT=0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMSC=0x00;&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; if(i&amp;gt;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;&amp;nbsp;&amp;nbsp; TPM2SC=0x00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Stop Timer2 or Stop timeout timer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; store[i].period[0]=TPMC1VH;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; store[i].period[1]=TPMC1VL;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2MOD=0x7000;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Timeout of 86msec.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2SC=0x4D;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Restart Timer&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;&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; TPMCNT=0;&amp;nbsp;&amp;nbsp; i++;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;PRE&gt;
interrupt 10 void Timer2_Overflow_INTR(void){&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; TPMC1SC_CH1IE=RESET;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPMCNT=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; if(common.LEARN==SET)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; common.LEARN_DONE=SET;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; common.ACTION_READY=SET;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; common.TIME_OUT=SET;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2SC;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2SC_TOIE=RESET;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;My problem is that often it will recv the waveform correctly but some of times I cannot get the&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;correct waveform..I am not sure if the algorithm I am using is correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help?..I can tell more..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expecting help as usual..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:15:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167638#M10858</guid>
      <dc:creator>abicash</dc:creator>
      <dc:date>2020-10-29T09:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: TPM misbehaves in QD4</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167639#M10859</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 wonder if it is possible that the period you are attempting to measure may exceed the overflow period for TPM1?&amp;nbsp; If so the capture results will be meaningless (without also tracking overflows).&amp;nbsp; Try increasing the prescale value for TPM1, and see if the problem persists.&amp;nbsp; I presume that TPM1 does not have a reduced modulo setting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I notice that you are altering TPM2 settings within the TPM1 ISR, including stopping the timer and changing the modulo value.&amp;nbsp; This is rather unorthodox.&amp;nbsp; The more traditional aproach would be to utilize output compare interrupt, and leave the TPM running continuously with full modulo count. From within the TPM1 ISR, simply read the current 16-bit counter value for TPM2, add the required timeout delay (0x7000), and update the TPM2 channel register.&amp;nbsp; A channel interrupt will occur upon expiry of the timeout period.&amp;nbsp;&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Mar 2009 03:00:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167639#M10859</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-03-30T03:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: TPM misbehaves in QD4</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167640#M10860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mac and thank you so much for the reply..&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The TPM1 Channel interrupt is invoked on every edge (rising and falling) and in the ISR i reset the TPM2CNT,so that largely,the overall code is trying to look for a Timeout.&lt;/P&gt;&lt;P&gt;This is to insure that multiple packets are not processed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is TPM2 altering not suitable within another ISR?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did not understand the part where you said to add the req. timeout delay after reading the current 16-bit cnt value.&lt;/P&gt;&lt;P&gt;Did you mean that I subtract current cnt from the req. cnt and then add this cnt to the existing cnt?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is this beneficial?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please reply&lt;/P&gt;&lt;P&gt;Thanks and regards&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by abicash on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-03-30&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;12:58 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Mar 2009 18:57:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167640#M10860</guid>
      <dc:creator>abicash</dc:creator>
      <dc:date>2009-03-30T18:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: TPM misbehaves in QD4</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167641#M10861</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;My previous response was badly worded.&amp;nbsp; The unorthodoxy that I was referring to was not the modification of the registers from within the ISR, but the stopping, starting and clearing of the TPM counter, and the changing of the TPMMOD value - it is usually possible to avoid these.&amp;nbsp; The reason they should generally be avoided is they affect all channels of the TPM module, and may prevent the use of spare channels for other purposes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the case of TPM2, with only a single channel, this issue is probably not of importance, but I was alluding to the fact that there is an alternative way of handling the timing that avoids the issue.&amp;nbsp; I did not mean to imply that your method could not be made to work, and had any bearing on your current problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The alternative method in more detail -&lt;/P&gt;&lt;P&gt;Within the TPM1 channel (input capture) ISR:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM2C0SC = 0x50;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Software output compare interrupt&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM2C0V = TPM2CNT + 0x7000;&amp;nbsp; // Setup timeout period&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM2C0SC_CH0F = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clear flag (if set)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When timeout occurs, a TPM2 channel 0 interrupt would take place.&amp;nbsp; Within this ISR:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM2C0SC = 0x00; &amp;nbsp;&amp;nbsp; // Disable output compare mode&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="courier new,courier"&gt;TPM2C0SC_CH0F = 0;&amp;nbsp; // Clear flag&lt;/FONT&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your input capture ISR code might then become something like the following -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define RESET 0&lt;BR /&gt;&lt;BR /&gt;byte i;&lt;BR /&gt;&lt;FONT color="#ff0000"&gt;word store[70];&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;interrupt 6 void TPM1C1_ISR (void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;TPM&lt;FONT color="#ff0000"&gt;1&lt;/FONT&gt;C1SC;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;Unnecessary for flag clearing&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; TPM&lt;FONT color="#ff0000"&gt;1&lt;/FONT&gt;C1SC_CH1F = RESET; Clear flag&amp;nbsp;&lt;BR /&gt;&amp;nbsp; if (i == 70) {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;TPMC1SC_CH1IE = RESET;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;TPMCNT=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;TPMSC=0x00;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;TPM1C1SC = 0x00;&amp;nbsp; // Disable input capture operation&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;TPM2C0SC = 0x00;&amp;nbsp; // ?? Disable output compare operation&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &lt;FONT color="#ff0000"&gt;else if (i &amp;gt; 1) {&amp;nbsp;&amp;nbsp; // I presume this is what is really intended&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;if (i &amp;gt; 1 ) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;TPM2SC=0x00; //Stop Timer2 or Stop timeout timer&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;store[i] = TPM1C1V; // Simpler to handle a word value&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;store[i].period[0]=TPMC1VH;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;store[i].period[1]=TPMC1VL;&lt;BR /&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;TPM2C0SC = 0x50;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Software output compare interrupt&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000" face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2C0V = TPM2CNT + 0x7000;&amp;nbsp; // Setup timeout period 86ms&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000" face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM2C0SC_CH0F = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clear flag (if set)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;TPM2MOD = 0x7000;&amp;nbsp;&amp;nbsp; //Timeout of 86msec.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;TPM2SC = 0x4D;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Restart Timer&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;i++;&amp;nbsp; // May be better placed here&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;TPMCNT = 0;&lt;BR /&gt;&amp;nbsp; &lt;FONT color="#ff0000"&gt;//&lt;/FONT&gt;i++;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;}&lt;BR /&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;One other point about input capture operation - it may be more reliable to capture on a single edge at a time, rather than both edges. This may prevent phasing errors occurring in the event of spurious interrupts - you will always be assured of the edge polarity that each capture event represents. During the input capture ISR simply toggle to the opposite edge for the next event.&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Apr 2009 11:44:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/TPM-misbehaves-in-QD4/m-p/167641#M10861</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-04-01T11:44:08Z</dc:date>
    </item>
  </channel>
</rss>

