<?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: TPM1 and SCI2D relations in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176922#M12468</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found that case with &amp;nbsp;SCI2D and TPM1 was just coincedent. Basically setup TPM1 PWM required some time to complete this task. And that amount of time expired exactly on the command to write to SCI2D.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Jul 2012 20:39:48 GMT</pubDate>
    <dc:creator>d0ct0r</dc:creator>
    <dc:date>2012-07-05T20:39:48Z</dc:date>
    <item>
      <title>Single TPM for IN and OUT</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176917#M12463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For simlicuty, lets say I need to use two channels from the same TPM. Not at the same time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex.: TPM1&lt;/P&gt;&lt;P&gt;CH0: capturing (from sensor)&lt;/P&gt;&lt;P&gt;CH1: pwm out (to buzzer)&lt;/P&gt;&lt;P&gt;Bus: 24Mhz&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could initialise TPM1 as follow:&lt;/P&gt;&lt;P&gt;TPM1SC = 0x17;&lt;/P&gt;&lt;P&gt;TPM1C0SC = 0x44;&lt;/P&gt;&lt;P&gt;TPM1C1SC = 0x38;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P align="left"&gt;TPM1MODH=0x03;&lt;/P&gt;&lt;P align="left"&gt;TPM1MODL=0x54;&lt;/P&gt;&lt;P align="left"&gt;TPM1C1VH=0x03;&lt;/P&gt;&lt;P&gt;TPM1C1VL=0x54;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to use Interrupt for TPM1CH0 for capturing some data from sensor (data coming in microsecond intervals). This part working fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But then, for some uncertain reason, I cannot change TPM1MOD from zero to anything else to produce PWM signal. As well I can't write to TPM1CH1V. It just ignore anything I try to put there. However, buzzer could produce some sounds after long period of time. Then I am able turn it&amp;nbsp;OFF (TPM1SC=0) and ON (TPM1SC=0x17). Its a mistery why its working in that manner.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas, what is wrong in theory ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 05:48:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176917#M12463</guid>
      <dc:creator>d0ct0r</dc:creator>
      <dc:date>2012-07-03T05:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Single TPM for IN and OUT</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176918#M12464</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;Whenever you update the TPMxMOD or TPMxCnV registers, there is a coherency mechanism involved, before the value can change.&amp;nbsp; This mechanism differs slightly for different versions of the TPM module.&amp;nbsp; The update of these registers will&amp;nbsp;occur more quickly if the TPM module is disabled when the values are altered, i.e TPMxSC is zero.&amp;nbsp; During initialisation, TPMxSC should then be the last register to be set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I note that you have a large prescale setting of 128, and a relatively small TPM1MOD setting.&amp;nbsp; I would suggest to greatly reduce the prescale value to, say 2, and increase the TPM1MOD value by a factor of 64.&amp;nbsp; This will increase the resolution of the input capture process, but retain the same overflow period.&amp;nbsp; I note that you are writing individual byte values to the 16 bit registers.&amp;nbsp; This is unnecessary - it is simpler to write the full 16-bit value to these registers, It is also&amp;nbsp;possible that you may not have taken into account that the PWM period is actually equal to (TPM1MOD+1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The input capture range will be zero to TPM1MOD value.&amp;nbsp; The calculation of the period&amp;nbsp;between input capture events&amp;nbsp;must therefore compensate for the truncated range.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I note that, with TPM1C1V equal to TPM1MOD, your PWM duty setting will be very close to 100 percent, which may cause the buzzer to be inaudible.&amp;nbsp; For 50 percent duty, you would require &lt;FONT face="courier new,courier"&gt;TPM1C1V = (TPM1MOD+1)/2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Your initialisation code might then become -&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM1MOD = 0xD4FF;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM1C0SC = 0x44;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Input capture on +ve edge&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM1C1SC = 0x38;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// Edge aligned PWM mode&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM1C1V = (TPM1MOD+1)/2; // 50% duty&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;TPM1SC = 0x11;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Fixed system clock, prescale 2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within your input capture ISR, you might incorporate the following code to determine the period between events -&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;static word oldval;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;period = TPM1C0V - oldval;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;oldval = TPM1C0V;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if (period &amp;gt;= (TPM1MOD+1))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; period -= (TPM1MOD+1);&amp;nbsp; // Corrected period value&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The global (or static) word variable &lt;FONT face="courier new,courier"&gt;period&lt;/FONT&gt; would need to be defined as &lt;FONT face="courier new,courier"&gt;volatile&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>Tue, 03 Jul 2012 10:17:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176918#M12464</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2012-07-03T10:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Single TPM for IN and OUT</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176919#M12465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes ! It did the trick. Now its working as expected. Much thanks !!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 20:56:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176919#M12465</guid>
      <dc:creator>d0ct0r</dc:creator>
      <dc:date>2012-07-03T20:56:14Z</dc:date>
    </item>
    <item>
      <title>TPM1 and SCI2D relations</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176920#M12466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another interesting observation: as soon as I write to SCI2D, TPM1 (CH1) produce PWM output (my buzzer starts beeping).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code (fragments):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[skip]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P align="left"&gt;TPM1MOD = 0xD4FF; &lt;FONT color="#3F7F5F" size="2"&gt;&lt;FONT color="#3F7F5F" size="2"&gt;// MODULO (period or frequency)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P align="left"&gt;TPM1C0SC = 0x44; &lt;FONT color="#3F7F5F" size="2"&gt;&lt;FONT color="#3F7F5F" size="2"&gt;// Input capture&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P align="left"&gt;TPM1C1SC = 0x38; &lt;FONT color="#3F7F5F" size="2"&gt;&lt;FONT color="#3F7F5F" size="2"&gt;// Edge aligned PWM mode&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P align="left"&gt;TPM1C1V = (TPM1MOD+1)/2; &lt;FONT color="#3F7F5F" size="2"&gt;&lt;FONT color="#3F7F5F" size="2"&gt;// 50% duty&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P align="left"&gt;TPM1SC = 0x11; &lt;FONT color="#3F7F5F" size="2"&gt;&lt;FONT color="#3F7F5F" size="2"&gt;// Fixed system clock, &lt;U&gt;prescale&lt;/U&gt; 2&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[skip]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#7F0055" size="2"&gt;&lt;FONT color="#7F0055" size="2"&gt;while&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT size="2"&gt;(SCI2S1_TDRE == 0);&lt;/FONT&gt; &lt;FONT color="#3F7F5F" size="2"&gt;&lt;FONT color="#3F7F5F" size="2"&gt;// Wait until SCI2 ready to send next byte&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;SCI2D = buf[i];&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>Wed, 04 Jul 2012 00:41:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176920#M12466</guid>
      <dc:creator>d0ct0r</dc:creator>
      <dc:date>2012-07-04T00:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: TPM1 and SCI2D relations</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176921#M12467</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 might have expected that the buzzer would be active immediately the TPM1SC register was initialized.&amp;nbsp; I see no&amp;nbsp;relationship between the PWM output and the SCI2 output (assuming they do not share the same pin).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In practice, you will need the capability to&amp;nbsp;control the state of&amp;nbsp;the buzzer.&amp;nbsp; I would usually accomplish this by writing to the TPM1C1SC register.&amp;nbsp; A zero value would turn the buzzer off, by reverting to GPIO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my previous post, I included a code snippet that purported to provide an adjustment for the input capture&amp;nbsp;period calculation, for a TPM module that was not free-running.&amp;nbsp; This code was wrong.&amp;nbsp; Here is a corrected version (I think) -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;static word oldval;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if (TPM1C0V &amp;lt; oldval)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; period = TPM1C0V + (TPM1MOD + 1 - oldval);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;else&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; period = TPM1C0V - oldval;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;oldval = TPM1C0V;&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>Wed, 04 Jul 2012 12:57:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176921#M12467</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2012-07-04T12:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: TPM1 and SCI2D relations</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176922#M12468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found that case with &amp;nbsp;SCI2D and TPM1 was just coincedent. Basically setup TPM1 PWM required some time to complete this task. And that amount of time expired exactly on the command to write to SCI2D.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 20:39:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Single-TPM-for-IN-and-OUT/m-p/176922#M12468</guid>
      <dc:creator>d0ct0r</dc:creator>
      <dc:date>2012-07-05T20:39:48Z</dc:date>
    </item>
  </channel>
</rss>

