<?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>Kinetis Microcontrollers中的主题 Re: KL0x - Timer PWM Interrupt</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL0x-Timer-PWM-Interrupt/m-p/1308727#M61041</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You can still use the TPM0. For example , one task is 100ms.&amp;nbsp; task2 is 200ms.&lt;/P&gt;
&lt;P&gt;You can set TPM0 generate interrupt at 100ms. And define a global variable like 'interruptCount'. Use it for judge if the task2 need to be run.&amp;nbsp; When you go to the interrupt the 'interruptCount' will be added. The task1 will run. When the 'interruptCount' is 2, the judgement is active, the task 2 will also run. And clear the 'interruptCount '&lt;/P&gt;
&lt;P&gt;If the task2 time is smaller than the task, you can also do this.&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;TIC&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;
&lt;P&gt;- We are following threads for 7 days after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jul 2021 01:47:20 GMT</pubDate>
    <dc:creator>nxf56274</dc:creator>
    <dc:date>2021-07-16T01:47:20Z</dc:date>
    <item>
      <title>KL0x - Timer PWM Interrupt</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL0x-Timer-PWM-Interrupt/m-p/1308684#M61039</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Platform: KL02 dev board, MCUXpresso SDK&lt;/P&gt;&lt;P&gt;Problem: I´m trying to generate a sequence of 4kHz burst pulses using the timer in PWM mode. The IO outputs 4kHz a clock for 100ms. Next 100ms is off. Next 100ms is on. The idea is to drive a buzzer (beep...silence...beep...silence...beep...silence)&lt;/P&gt;&lt;P&gt;I´m able to generate the 4KHz clock out of the pin using TMP1 (PTA12 | TMP1_CH0). I could use the LPTMR or the TMP0 to turn on/off TMP1 at every 100ms, but they are already assigned to other tasks.&lt;/P&gt;&lt;P&gt;I was wondering if I could use the TMP1 interrupt handler to change the state of&amp;nbsp;tpmParam.level (from&amp;nbsp;&lt;EM&gt;kTPM_HighTrue&lt;/EM&gt; to&amp;nbsp;&lt;EM&gt;kTPM_NoPwmSignal&lt;/EM&gt;) at every 100ms. So I was asuming the timer in PWM mode would behave like a periodic timer overflow, therefore after a X-number of the clocks the interrupt handler is reached where the timer parameter (e.g. tpmParam.level) could be changed.&lt;/P&gt;&lt;P&gt;In my code I wa trying to toggle the led that would represent the PWM output ON and OFF.&lt;/P&gt;&lt;P&gt;First question: is that feasable? If so could you please take a look at my code and suggest a change?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Andre VB&lt;/P&gt;&lt;P&gt;--------------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;&lt;FONT size="2"&gt;#define TPM1_HANDLER TPM1_IRQHandler&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;void TPM1_HANDLER(void)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="2"&gt;/* Clear interrupt flag.*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;TPM_ClearStatusFlags(TPM1, kTPM_TimeOverflowFlag); &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;GPIO_PortToggle(GPIOB, 1 &amp;lt;&amp;lt; 10);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;int main(void)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="2"&gt;/* Board pin, clock, debug console init */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;BOARD_InitPins();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;BOARD_BootClockRUN();&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;tpm_config_t tpmInfo;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;tpm_chnl_pwm_signal_param_t tpmParam;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;/* Configure tpm params with frequency 4kHZ */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;tpmParam.chnlNumber = (tpm_chnl_t)0U; // TIMER 1 at PTA12&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;tpmParam.level = kTPM_HighTrue;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;tpmParam.dutyCyclePercent = 50;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;/* Select the clock source for the TPM counter as MCGFLLCLK */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;CLOCK_SetTpmClock(1U);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;/*&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.prescale = kTPM_Prescale_Divide_128;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.useGlobalTimeBase = false;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.enableDoze = false;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.enableDebugMode = true;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.enableReloadOnTrigger = false;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.enableStopOnOverflow = false;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.enableStartOnTrigger = false;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.enablePauseOnTrigger = false;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.triggerSelect = kTPM_Trigger_Select_0;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp;tpmInfo.triggerSource = kTPM_TriggerSource_External;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;TPM_GetDefaultConfig(&amp;amp;tpmInfo);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;/* Initialize TPM module */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;TPM_Init(TPM1, &amp;amp;tpmInfo);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;TPM_SetupPwm(TPM1, &amp;amp;tpmParam, 1U, kTPM_CenterAlignedPwm, 4000U, CLOCK_GetFreq(kCLOCK_McgFllClk));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;TPM_EnableInterrupts(TPM1, kTPM_TimeOverflowInterruptEnable);&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;EnableIRQ(TPM1_IRQn);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;TPM_StartTimer(TPM1, kTPM_SystemClock);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;while (1)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;{}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 00:05:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL0x-Timer-PWM-Interrupt/m-p/1308684#M61039</guid>
      <dc:creator>AndreVB</dc:creator>
      <dc:date>2021-07-16T00:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: KL0x - Timer PWM Interrupt</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL0x-Timer-PWM-Interrupt/m-p/1308727#M61041</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You can still use the TPM0. For example , one task is 100ms.&amp;nbsp; task2 is 200ms.&lt;/P&gt;
&lt;P&gt;You can set TPM0 generate interrupt at 100ms. And define a global variable like 'interruptCount'. Use it for judge if the task2 need to be run.&amp;nbsp; When you go to the interrupt the 'interruptCount' will be added. The task1 will run. When the 'interruptCount' is 2, the judgement is active, the task 2 will also run. And clear the 'interruptCount '&lt;/P&gt;
&lt;P&gt;If the task2 time is smaller than the task, you can also do this.&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;TIC&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;/P&gt;
&lt;P&gt;- We are following threads for 7 days after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 01:47:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL0x-Timer-PWM-Interrupt/m-p/1308727#M61041</guid>
      <dc:creator>nxf56274</dc:creator>
      <dc:date>2021-07-16T01:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: KL0x - Timer PWM Interrupt</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL0x-Timer-PWM-Interrupt/m-p/1309172#M61046</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;It works, as well as using &lt;SPAN&gt;TMP0/LPTMR to turn on/off TMP&lt;/SPAN&gt;1 (in PWM mode). But what I was trying to do is to avoid using another time to perform the task.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In summary: how to create a X-kHz burst pulses using a single PWM timer channel. Maybe it can´t be done, I would like to confirm that.&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Andre VB&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2021 14:04:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL0x-Timer-PWM-Interrupt/m-p/1309172#M61046</guid>
      <dc:creator>AndreVB</dc:creator>
      <dc:date>2021-07-16T14:04:19Z</dc:date>
    </item>
  </channel>
</rss>

