<?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: QE128 Timer problem</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153008#M8445</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tony&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your recommendation but it doesn't change anything. Another solution that works is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while(TPM1MOD != frequency) TPM1MOD = frequency;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the same with TPM1C2V.&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>Mon, 09 Nov 2009 20:57:59 GMT</pubDate>
    <dc:creator>Kaare</dc:creator>
    <dc:date>2009-11-09T20:57:59Z</dc:date>
    <item>
      <title>QE128 Timer problem</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153006#M8443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a weird problem with the MC9S08QE128 device and timer operation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use a timer as a PWM output so i do it like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Set PWM to BUSCLK and prescaler to 0&lt;/P&gt;&lt;P&gt;TPM1SC = 0x08;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Edge-aligned PWM, High-true pulses&lt;/P&gt;&lt;P&gt;TPM1C2SC = 0x28;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Set the period&amp;nbsp;&lt;/P&gt;&lt;P&gt;TPM1MOD = 32000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Set the duty cycle to 50%&lt;/P&gt;&lt;P&gt;TPM1C2V = 16000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the above code does not change the Modulo or the dutycycle the first time it is run. I need to run the above code block twice to get it to set the TPM1MOD and TPM1C2V registers and i need to wait at least 10mS between the two writes for it to work. Why is that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, i use an external 32.768 Khz crystal and the bus is set to run at 20MHz. When i measure on the above mentioned output, it takes aprox. 2.5 seconds before the pwm is available from when i hit Run in the debugger.&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Kaare on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-09&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;12:41 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Nov 2009 19:15:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153006#M8443</guid>
      <dc:creator>Kaare</dc:creator>
      <dc:date>2009-11-09T19:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: QE128 Timer problem</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153007#M8444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From Peripheral Quick Reference Guide:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Configuring the TPM to generate PWM signals with common duty cycles is straightforward:&lt;BR /&gt;1. Load the desired period for all channels on the base timer TPMMOD register.&lt;BR /&gt;2. Load the desired duty cycle for each channel on the TPMCnV registers.&lt;BR /&gt;3. Select the PWM functionality for each channel that will be used to generate PWM by using the&lt;BR /&gt;TPMCnSC register of each channel.&lt;BR /&gt;4. Select the PWM mode, input clock and prescaler for the main timer in the TPMSC register.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this order of initialization (TPMMOD first, and TPMSC last).&amp;nbsp;&amp;nbsp; The way you do it, it's possible the settings don't take effect until after the current period expires, which might explain the 2.5 sec delay (just guessing).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by tonyp on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-11-09&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, 09 Nov 2009 20:02:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153007#M8444</guid>
      <dc:creator>tonyp</dc:creator>
      <dc:date>2009-11-09T20:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: QE128 Timer problem</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153008#M8445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tony&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your recommendation but it doesn't change anything. Another solution that works is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while(TPM1MOD != frequency) TPM1MOD = frequency;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the same with TPM1C2V.&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>Mon, 09 Nov 2009 20:57:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153008#M8445</guid>
      <dc:creator>Kaare</dc:creator>
      <dc:date>2009-11-09T20:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: QE128 Timer problem</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153009#M8446</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;As TonyP has already pointed out, is important to set the CLKSB:CLKSA bits of the TPM1SC register after the TPM1MOD and the TPM channel registers have been set up, in order to avoid a delay of a full TPM overflow cycle in free running mode.&amp;nbsp; Here is an extract from the datasheet.&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;EM&gt;Writing to either byte (TPMxMODH or TPMxMODL) latches the value into a buffer and the registers are updated with the value of their write buffer according to the value of CLKSB:CLKSA bits, so:&lt;BR /&gt;• If (CLKSB:CLKSA = 0:0), then the registers are updated when the second byte is written&lt;BR /&gt;• If (CLKSB:CLKSA not = 0:0), then the registers are updated after both bytes were written, and the TPM counter changes from (TPMxMODH:TPMxMODL - 1) to (TPMxMODH:TPMxMODL). If the TPM counter is a free-running counter, the update is made when the TPM counter changes from 0xFFFE to 0xFFFF.&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Similar considerations also apply to the update of the channel registers -&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;EM&gt;In output compare or PWM modes, writing to either byte (TPMxCnVH or TPMxCnVL) latches the value&lt;/EM&gt; &lt;EM&gt;into a buffer. After both bytes are written, they are transferred as a coherent 16-bit value into the&lt;/EM&gt; &lt;EM&gt;timer-channel registers according to the value of CLKSB:CLKSA bits and the selected mode, so:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;• If (CLKSB:CLKSA = 0:0), then the registers are updated when the second byte is written.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;• If (CLKSB:CLKSA not = 0:0 and in output compare mode) then the registers are updated after the&lt;/EM&gt; &lt;EM&gt;second byte is written and on the next change of the TPM counter (end of the prescaler counting).&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;• If (CLKSB:CLKSA not = 0:0 and in EPWM or CPWM modes), then the registers are updated after&lt;/EM&gt; &lt;EM&gt;the both bytes were written, and the TPM counter changes from (TPMxMODH:TPMxMODL - 1)&lt;/EM&gt; &lt;EM&gt;to (TPMxMODH:TPMxMODL). If the TPM counter is a free-running counter then the update is&lt;/EM&gt; &lt;EM&gt;made when the TPM counter changes from 0xFFFE to 0xFFFF.&lt;/EM&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Even if the update of the TPM1MOD and channel registers occurs while CLKSB:CLKSA = 0:0, the PWM output signal will not commence until the first modulo overflow occurs.&amp;nbsp; Perhaps you are not waiting a sufficient time for the changes to take effect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As to the initial 2.5 second delay, this is probably due to the start-up delay of the low frequency crystal. The oscillation amplitude will slowly build up to the normal operating level, and then there will be a further delay until the FLL locks.&amp;nbsp; Higher frequency crystals will have considerably shorter start-up delay.&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>Tue, 10 Nov 2009 01:20:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153009#M8446</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-11-10T01:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: QE128 Timer problem</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153010#M8447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello bigmac and thanks for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the problem is not that it waits a full overflow cycle, but that it never sets the registers at all if i only set them once. If i break somewhere in my code in the debugger and the do TPM3C2V = 0xfafa for example, then the register is not written. If i manually find the adress in the memory window and edit the register there, then it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only way i can get it to change the timer registers is by doing the above mentioned while-loop. But if i do that, then the code gets trapped there if i debug the application as the condition never gets true.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Nov 2009 17:40:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153010#M8447</guid>
      <dc:creator>Kaare</dc:creator>
      <dc:date>2009-11-10T17:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: QE128 Timer problem</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153011#M8448</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;Do you get the correct PWM output if you &lt;U&gt;don't&lt;/U&gt; try to debug the writing of the TPM registers?&amp;nbsp; My understanding is that the TPM coherency mechanism operates differently in BDM mode.&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, 11 Nov 2009 00:09:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/QE128-Timer-problem/m-p/153011#M8448</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-11-11T00:09:04Z</dc:date>
    </item>
  </channel>
</rss>

