<?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: Output Compare on the MC9S08AC16</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210850#M18072</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;It is always more helpful if you include a code snippet to show the problem area.&amp;nbsp; It is unclear whether you require an output pulse width 2ms greater than the input pulse width, or a fixed output pulse width of 5ms, independent of the input pulse width.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will assume that you might be using TPM channel&amp;nbsp;interrupts, rather than polling, to control the pulse generation.&amp;nbsp; Note that, unless you gate the input pulse externally to the&amp;nbsp;MCU, the start of the output pulse will be delayed by a number of bus cycles from the transition edge of the input pulse.&amp;nbsp; This is the time required to&amp;nbsp;allow for the latency of the input capture ISR and to update the output compare register of the second channel.&amp;nbsp; I would recommend that you use two channels from the same TPM module, say TPM1Ch0 and TPM1Ch1, rather than from different TPM modules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A possible&amp;nbsp;procedure,&amp;nbsp;within the input capture channel ISR, might be to -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Read TPM1CNT value, and set TPM1C1V (the output compare channel) to this value, plus a few TPM clock cycles.&amp;nbsp; This is to make sure that, by the time that the register is updated, the TPM1CNT value is not already greater than the required time.&amp;nbsp; The output compare transition should generate the positive edge of the output pulse.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a fixed output pulse period, you&amp;nbsp;would wait until the ouput compare event occurs (the channel flag becomes set), and then set the TPM1C!V value for the required pulse width&amp;nbsp;beyond the previous channel register setting, with with a low output state&amp;nbsp;for the next output compare event.&amp;nbsp; Then exit the ISR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For extending the input pulse width by a fixed amount,&amp;nbsp;you would set the next input capture event for a negative transition, and exit the ISR.&amp;nbsp; When the next interrupt occurs, set the TPM1C1V value to the required delay beyond the current TPM1C0V capture value, with the next output compare event to a low state.&amp;nbsp; Revert to a positive edge for the next input capture event, and exit the ISR.&amp;nbsp; You will need to keep track whether the current execution of the ISR is for a positive or negative input capture edge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Interrupts on TPM1Ch1 are not required for the pulse generation.&amp;nbsp; Note that the TPM overflow period must be greater than the delay you are attempting to create, to avoid additional complication to the code.&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, 31 May 2011 12:38:32 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2011-05-31T12:38:32Z</dc:date>
    <item>
      <title>Output Compare on the MC9S08AC16</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210849#M18071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am attempting to create a pulse using the output compare function on the MC9S08AC16.&lt;/P&gt;&lt;P&gt;I measure an incoming pulse for example - 3 msec and I would like to set the out going pulse to be longer - say 5 msec.&amp;nbsp; The outgoing pulse has to begin on the rising edge of the incoming pulse.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using TPM3CH0 to measure the incoming pulse - this appears to work correctly.&lt;/P&gt;&lt;P&gt;I am using TPM1CH0 to create the outgoing pulse - does not work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the rising edge of the incoming pulse I set&amp;nbsp; PTE2 (TPM1CH0).&lt;/P&gt;&lt;P&gt;On the falling edge of the incoming pulse, I set the compare value and enable clear on compare function and enable the compare interrupt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TPM1C0V = TPM1CNT + delta&lt;/P&gt;&lt;P&gt;delta is the 2 msec that would be added to the 3 to give 5msec&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output compare does not happen at any predictable time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 May 2011 01:54:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210849#M18071</guid>
      <dc:creator>Forest</dc:creator>
      <dc:date>2011-05-31T01:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Output Compare on the MC9S08AC16</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210850#M18072</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;It is always more helpful if you include a code snippet to show the problem area.&amp;nbsp; It is unclear whether you require an output pulse width 2ms greater than the input pulse width, or a fixed output pulse width of 5ms, independent of the input pulse width.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will assume that you might be using TPM channel&amp;nbsp;interrupts, rather than polling, to control the pulse generation.&amp;nbsp; Note that, unless you gate the input pulse externally to the&amp;nbsp;MCU, the start of the output pulse will be delayed by a number of bus cycles from the transition edge of the input pulse.&amp;nbsp; This is the time required to&amp;nbsp;allow for the latency of the input capture ISR and to update the output compare register of the second channel.&amp;nbsp; I would recommend that you use two channels from the same TPM module, say TPM1Ch0 and TPM1Ch1, rather than from different TPM modules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A possible&amp;nbsp;procedure,&amp;nbsp;within the input capture channel ISR, might be to -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Read TPM1CNT value, and set TPM1C1V (the output compare channel) to this value, plus a few TPM clock cycles.&amp;nbsp; This is to make sure that, by the time that the register is updated, the TPM1CNT value is not already greater than the required time.&amp;nbsp; The output compare transition should generate the positive edge of the output pulse.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a fixed output pulse period, you&amp;nbsp;would wait until the ouput compare event occurs (the channel flag becomes set), and then set the TPM1C!V value for the required pulse width&amp;nbsp;beyond the previous channel register setting, with with a low output state&amp;nbsp;for the next output compare event.&amp;nbsp; Then exit the ISR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For extending the input pulse width by a fixed amount,&amp;nbsp;you would set the next input capture event for a negative transition, and exit the ISR.&amp;nbsp; When the next interrupt occurs, set the TPM1C1V value to the required delay beyond the current TPM1C0V capture value, with the next output compare event to a low state.&amp;nbsp; Revert to a positive edge for the next input capture event, and exit the ISR.&amp;nbsp; You will need to keep track whether the current execution of the ISR is for a positive or negative input capture edge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Interrupts on TPM1Ch1 are not required for the pulse generation.&amp;nbsp; Note that the TPM overflow period must be greater than the delay you are attempting to create, to avoid additional complication to the code.&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, 31 May 2011 12:38:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210850#M18072</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-31T12:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Output Compare on the MC9S08AC16</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210851#M18073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have attached 3 files.&lt;/P&gt;&lt;P&gt;I used PE to setup the micro clock and the input capture&lt;/P&gt;&lt;P&gt;I manually setup the output compare&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are 2 paths for pulse generation.&amp;nbsp; The first path generates a duplicate of the incoming pulse and this works.&amp;nbsp; It does not use output compare.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope my comments in the code are clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You for responding,&lt;/P&gt;&lt;P&gt;Forest&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Jun 2011 06:57:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210851#M18073</guid>
      <dc:creator>Forest</dc:creator>
      <dc:date>2011-06-01T06:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: Output Compare on the MC9S08AC16</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210852#M18074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Forest,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your problem is you are writing theTPM1C0SC register immediately after setting the compare value.&amp;nbsp; Believe it or not, this should NOT be done.&amp;nbsp; This is an undesireable aspect of all the TPM modules in the processors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;      // read the count in TPM1 and add the delta to it      TPM1C0V = TPM1CNT + uiOC0delta;      // clear any pending interrupt      A = TPM1C0SC;      // and turn on OC      TPM1C0SC = 0x58;  // terminate pulse on compare&lt;/PRE&gt;&lt;P&gt;Do whatever you need to do to TPM1C0SC &lt;EM&gt;first&lt;/EM&gt;, then set the compare value.&amp;nbsp; Another way around it is to set the compare value first, then wait until you see the timer value (TPM1CNT) change, then you can change the control register.&amp;nbsp; The latter way is not always desireable in an interrupt service routine however.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I think happens, but also see their explanation below from the manual.&amp;nbsp; When you load the compare value, it has to get synchronized with the clock to the timer and writing both bytes of the 16-bit compare value coherently.&amp;nbsp; That is done with a "coherency mechanism" that employs a "latching mechanism" in the TPM.&amp;nbsp; Any write to a TPMxCxSC register will reset the latching mechanism, and possibly leave an incorrect value in the compare register.&amp;nbsp; I said above, "what I think happens" but I should have said, "what I KNOW happens" since I have verified this situation.&amp;nbsp; Read the two paragraphs below from their manual.&amp;nbsp; These are easy to miss, but are absolutely critical to getting a correct compare value.&amp;nbsp; The second paragraph is the most important one, especially the bolded text.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;In output compare or PWM modes, writing to either byte (TPMxCnVH or TPMxCnVL) latches the value into a buffer. After both bytes are written, they are transferred as a coherent 16-bit value into the timer-channel registers according to the value of CLKSB:CLKSA bits and the selected mode...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;The latching mechanism may be manually reset by writing to the TPMxCnSC register&lt;/STRONG&gt; (whether BDM mode is active or not). This latching mechanism allows coherent 16-bit writes in either big-endian or little-endian order which is friendly to various compiler implementations.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What results if you do NOT do things correctly is the coherency mechanism gets messed up and the compare register gets what looks like a random value.&amp;nbsp; In my code, I opted to make sure my compare value would be at least a few timer counts greater than the current timer value (TPM1CNT), then I set the control register, and lastly set the compare register value.&amp;nbsp; My control register enabled interrupts, but I could guarantee I would not get one immediately since the compare value was at least a few timer counts later.&amp;nbsp; The way I had to do it seems totally backwards to my normal way of thinking about things, but it worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry I did not see your post earlier, and I hope you see this reply.&amp;nbsp; It cost me a lot of time figuring this one out, and I really want to help others avoid this same problem.&amp;nbsp; It is a strange problem that I think is the result of a poor design.&amp;nbsp; If any of the hardware designers read this post (unlikely) I would recommend they figure out a way to not reset the coherency/latching mechanism on writes to the control register.&amp;nbsp; There's gotta be a way to do that.&amp;nbsp; And if they are not going to change the hardware, &lt;EM&gt;at least&lt;/EM&gt; they could highlight or emphasize that area in the manual to show how critical it is, and not leave it as a two sentence paragraph in a discussion on the channel value registers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this takes care of your problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lou&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 19:59:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Output-Compare-on-the-MC9S08AC16/m-p/210852#M18074</guid>
      <dc:creator>Luigi</dc:creator>
      <dc:date>2011-06-13T19:59:37Z</dc:date>
    </item>
  </channel>
</rss>

