<?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: HCS0AW32 Timer Toggle  Function in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144661#M6927</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Well Ake's code is saying the same thing as Mac's first part. i.e. change to edge aligned PWM mode from toggling output compare, which I would agree with.&lt;/DIV&gt;&lt;DIV&gt;What remains to be seen is which assumption made by these two is correct. i.e. did the OP really want a PWM that toggles between 27% and 73% every period or just running at 73%.&lt;/DIV&gt;&lt;DIV&gt;My money is on bigmac here.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 11 Sep 2007 06:17:04 GMT</pubDate>
    <dc:creator>peg</dc:creator>
    <dc:date>2007-09-11T06:17:04Z</dc:date>
    <item>
      <title>HCS0AW32 Timer Toggle  Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144658#M6924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I'm using a bus clock of 8 MHz.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;here is the code:&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;bool pwmPhase;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;// selects bus clock, and 8 as the divisor&lt;BR /&gt;T2SC = 0x0B;&lt;BR /&gt;// total duration is 55 microseconds&lt;BR /&gt;T2MODH = 0;&lt;BR /&gt;T2MODL = 55;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;// sets the channel timer as toggle type&lt;BR /&gt;T2CH0SC = 0x14;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;// sets the timer channel value register&lt;BR /&gt;T2CH0VH = 0;&lt;BR /&gt;T2CH0VL = 55;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;pwmPhase = false;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;// clears the flag&lt;BR /&gt;T2CH0SC &amp;amp;= 0x7F;&lt;BR /&gt;// enables the interrupt&lt;BR /&gt;T2CH0IE = 1;&lt;BR /&gt;when an interrupt occurs, the following codes are executed:&lt;/DIV&gt;&lt;DIV&gt;//clears the flag&lt;BR /&gt;T2CH0SC &amp;amp;= 0x7F;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;if( pwmPhase )&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; // OFF time&lt;BR /&gt;&amp;nbsp; T2CH0VH = 0;&lt;BR /&gt;&amp;nbsp; T2CH0VL = 15;&lt;BR /&gt;&amp;nbsp; pwmPhase = false;&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; // ON time&lt;BR /&gt;&amp;nbsp; T2CH0VH = 0;&lt;BR /&gt;&amp;nbsp; T2CH0VL = 40;&lt;BR /&gt;&amp;nbsp; pwmPhase = true;&lt;BR /&gt;}&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;The code above is running.&lt;BR /&gt;The problem is the output port of the timer channel 0 is not behaving properly.&lt;BR /&gt;Sometimes the ON time becomes the OFF time and the OFF time becomes the ON time for the PWM signal.&lt;BR /&gt;What seeems to be the problem?&lt;BR /&gt;Can you please help me.&lt;BR /&gt;Thank you in advance.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2007 13:05:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144658#M6924</guid>
      <dc:creator>cris2pher</dc:creator>
      <dc:date>2007-09-10T13:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: HCS0AW32 Timer Toggle  Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144659#M6925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;It appears you are attempting to generate a waveform with an on period of 40 us and an off period of 15 us, to give a total waveform period of 55 us.&amp;nbsp; Is this correct?&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;There are two potential methods of doing this using the TPM -&lt;/FONT&gt;&lt;/DIV&gt;&lt;OL&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Edge aligned PWM mode for the TPM channel (interrupt not required), or&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="2"&gt;Output compare interrupt for each edge of the waveform.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;You seem to be attempting to combine both PWM operation and interrupts.&amp;nbsp; Because of the relatively short period the PWM method is probably more appropriate, with minimal software overheads.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;For example:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;T2MOD = 55;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* TPM overflow period 55 us */&lt;BR /&gt;T2CH0V = 40;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*&amp;nbsp;PWM on Ch 0 with period 40 us */&amp;nbsp;&lt;BR /&gt;T2CH0SC = 0x28; /* Edge aligned PWM mode for Ch 0 */&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Arial"&gt;The waveform should now be generated without the need for interrupts.&amp;nbsp; The possible disadvantage of this method is that the other TPM channel are stuck with the same very short timer overflow period, which may limit their usefulness.&lt;BR /&gt;&lt;BR /&gt;To use the output compare interrupt method, the T2MOD value should remain at&amp;nbsp;its default value.&amp;nbsp; The "toggle on output compare" setting must be avoided to prevent the possibility of incorrect phasing.&amp;nbsp; Instead, within the ISR code, the setting for T2CH0SC should be either 0x58 (clear output on compare) or 0x5C (set output on compare) depending on the &lt;U&gt;next&lt;/U&gt; required output state.&amp;nbsp; You will also need to calculate the next output compare value, which will depend on the edge currently being processed, and this value used to update T2CH0V.&lt;BR /&gt;&lt;BR /&gt;The output compare interrupt method will be disrupted if interrupt processing takes too much time relative to the&amp;nbsp;required &amp;nbsp;waveform period, or if the occurrence of other interrupts prevents update of the next output compare value in a timely manner.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Mac&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2007 21:51:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144659#M6925</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2007-09-10T21:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: HCS0AW32 Timer Toggle  Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144660#M6926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;Here is a piece of code that does what you wanted.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Ake&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://www.freescale.com/files/community_files/8BITCOMM/7392_aw60_tpm_1.zip" rel="nofollow" target="_self"&gt;AW60_TPM_1.zip&lt;/A&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by t.dowe on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-10-27&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;02:04 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2007 22:43:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144660#M6926</guid>
      <dc:creator>Ake</dc:creator>
      <dc:date>2007-09-10T22:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: HCS0AW32 Timer Toggle  Function</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144661#M6927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Well Ake's code is saying the same thing as Mac's first part. i.e. change to edge aligned PWM mode from toggling output compare, which I would agree with.&lt;/DIV&gt;&lt;DIV&gt;What remains to be seen is which assumption made by these two is correct. i.e. did the OP really want a PWM that toggles between 27% and 73% every period or just running at 73%.&lt;/DIV&gt;&lt;DIV&gt;My money is on bigmac here.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Sep 2007 06:17:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS0AW32-Timer-Toggle-Function/m-p/144661#M6927</guid>
      <dc:creator>peg</dc:creator>
      <dc:date>2007-09-11T06:17:04Z</dc:date>
    </item>
  </channel>
</rss>

