<?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 KL03 TPM: CMOD gets changed to zero each time TPM_DRV_PwmStart() runs in Kinetis Software Development Kit</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657119#M7123</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems that each time the TPM_DRV_PwmStart() is run that the TPM0.SC.CMOD gets set to zero.&amp;nbsp; As a result the PWM output never changes at pin PTA6.&amp;nbsp; Attached is a screen shot.&amp;nbsp;&amp;nbsp; If I set a breakpoint just after the TPM_DRV_PwmStart() and then change CMOD back to 0x1, then it works fine.&amp;nbsp;&amp;nbsp;&amp;nbsp; It is not clear to me why CMOD reverts to zero after TPM_DRV_PwmStart()?&amp;nbsp; Any suggestions?&amp;nbsp;&amp;nbsp;&amp;nbsp; I just want to be able to adjust the PWM output at any time.&amp;nbsp; I am not real familiar with the TPM, so some of this might be just misunderstanding how it works.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have setup the TPM0 as a PWM output.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tpm_general_config_t&amp;nbsp; main_tpm_config;&lt;/P&gt;&lt;P&gt;tpm_pwm_param_t main_tpm_timer_channel_config = {&lt;BR /&gt;&amp;nbsp; .mode = kTpmEdgeAlignedPWM,&lt;BR /&gt;&amp;nbsp; .edgeMode = kTpmHighTrue,&lt;BR /&gt;&amp;nbsp; .uFrequencyHZ = 100000U,&lt;BR /&gt;&amp;nbsp; .uDutyCyclePercent = 50U,&lt;BR /&gt;};&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Initialization portion:&lt;/P&gt;&lt;P&gt;&amp;nbsp; CLOCK_SYS_SetTpmSrc( TPM0_IDX, kClockTpmSrcIrc48M );&lt;BR /&gt;&amp;nbsp; TPM_DRV_Init( TPM0_IDX, &amp;amp;main_tpm_config );&lt;BR /&gt;&amp;nbsp; TPM_DRV_SetClock( TPM0_IDX, kTpmClockSourceModuleClk, kTpmDividedBy2 );&lt;BR /&gt;&amp;nbsp; main_tpm_timer_channel_config.uDutyCyclePercent = 50;&lt;BR /&gt;&amp;nbsp; TPM_DRV_PwmStart( TPM0_IDX, &amp;amp;main_tpm_timer_channel_config, 0U );&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Software:&amp;nbsp; KDS 3.0.0, KSDK 1.3.0.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Jan 2017 13:35:33 GMT</pubDate>
    <dc:creator>aes_mike</dc:creator>
    <dc:date>2017-01-03T13:35:33Z</dc:date>
    <item>
      <title>KL03 TPM: CMOD gets changed to zero each time TPM_DRV_PwmStart() runs</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657119#M7123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems that each time the TPM_DRV_PwmStart() is run that the TPM0.SC.CMOD gets set to zero.&amp;nbsp; As a result the PWM output never changes at pin PTA6.&amp;nbsp; Attached is a screen shot.&amp;nbsp;&amp;nbsp; If I set a breakpoint just after the TPM_DRV_PwmStart() and then change CMOD back to 0x1, then it works fine.&amp;nbsp;&amp;nbsp;&amp;nbsp; It is not clear to me why CMOD reverts to zero after TPM_DRV_PwmStart()?&amp;nbsp; Any suggestions?&amp;nbsp;&amp;nbsp;&amp;nbsp; I just want to be able to adjust the PWM output at any time.&amp;nbsp; I am not real familiar with the TPM, so some of this might be just misunderstanding how it works.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have setup the TPM0 as a PWM output.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tpm_general_config_t&amp;nbsp; main_tpm_config;&lt;/P&gt;&lt;P&gt;tpm_pwm_param_t main_tpm_timer_channel_config = {&lt;BR /&gt;&amp;nbsp; .mode = kTpmEdgeAlignedPWM,&lt;BR /&gt;&amp;nbsp; .edgeMode = kTpmHighTrue,&lt;BR /&gt;&amp;nbsp; .uFrequencyHZ = 100000U,&lt;BR /&gt;&amp;nbsp; .uDutyCyclePercent = 50U,&lt;BR /&gt;};&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Initialization portion:&lt;/P&gt;&lt;P&gt;&amp;nbsp; CLOCK_SYS_SetTpmSrc( TPM0_IDX, kClockTpmSrcIrc48M );&lt;BR /&gt;&amp;nbsp; TPM_DRV_Init( TPM0_IDX, &amp;amp;main_tpm_config );&lt;BR /&gt;&amp;nbsp; TPM_DRV_SetClock( TPM0_IDX, kTpmClockSourceModuleClk, kTpmDividedBy2 );&lt;BR /&gt;&amp;nbsp; main_tpm_timer_channel_config.uDutyCyclePercent = 50;&lt;BR /&gt;&amp;nbsp; TPM_DRV_PwmStart( TPM0_IDX, &amp;amp;main_tpm_timer_channel_config, 0U );&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Software:&amp;nbsp; KDS 3.0.0, KSDK 1.3.0.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jan 2017 13:35:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657119#M7123</guid>
      <dc:creator>aes_mike</dc:creator>
      <dc:date>2017-01-03T13:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: KL03 TPM: CMOD gets changed to zero each time TPM_DRV_PwmStart() runs</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657120#M7124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also, as I sweep the PWM from 0 to 100, incrementing the PWM by one each second, I notice that the output frequency will vary from 100KHz, 366Hz or DC.&amp;nbsp; In other words, it does not seem to be operating in a PWM mode from perspective of the output at PTA6.&amp;nbsp; Mike.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jan 2017 15:54:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657120#M7124</guid>
      <dc:creator>aes_mike</dc:creator>
      <dc:date>2017-01-03T15:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: KL03 TPM: CMOD gets changed to zero each time TPM_DRV_PwmStart() runs</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657121#M7125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;As you know that condition&amp;nbsp; the TPM counts tick is that the CMOD bits can not be 0 or 3. So before you call the TPM_DRV_PwmStart(), you have to call &amp;nbsp;TPM_DRV_SetClock(BOARD_BUBBLE_TPM_INSTANCE, kTpmClockSourceModuleClk, kTpmDividedBy2);&lt;/P&gt;&lt;P&gt;The TPM_DRV_SetClock() can assign the kTpmClockSourceModuleClk to a global variable so that the global variable can set up the CMOD bits in TPM_DRV_PwmStart().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//BOARD_BUBBLE_TPM_INSTANCE=0;&lt;/P&gt;&lt;P&gt;Hope it can help you&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;XiangJun Rong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jan 2017 06:25:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657121#M7125</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2017-01-04T06:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: KL03 TPM: CMOD gets changed to zero each time TPM_DRV_PwmStart() runs</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657122#M7126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To close out this question and help others out there struggling with similar issue, it turns out that the issue is a stack overflow problem which is clobbering the global variable (s_tpmClockSource) that you mentioned.&amp;nbsp; I setup a watchpoint on that variable and sure enough it was being change in unexpected ways. &amp;nbsp; That is why the PWM appears to come and go because the s_tpmClockSource is used to write to CMOD anytime TPM_DRV_PwmStart() is run. &lt;/P&gt;&lt;P&gt;I now have set a watchpoint at the bottom of the stack and that has helped as well as using the -fstack_usage flag for the GCC compiler which produces a report on the stack foot print of each function that is compiled.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2017 19:57:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/KL03-TPM-CMOD-gets-changed-to-zero-each-time-TPM-DRV-PwmStart/m-p/657122#M7126</guid>
      <dc:creator>aes_mike</dc:creator>
      <dc:date>2017-01-06T19:57:16Z</dc:date>
    </item>
  </channel>
</rss>

