<?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>LPC MicrocontrollersのトピックRe: LPC54606 SCTimer change period problem</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC54606-SCTimer-change-period-problem/m-p/1742653#M54487</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/160756"&gt;@luimarma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about low the change frequency, it means delay the time before change period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Alice&lt;/P&gt;</description>
    <pubDate>Thu, 19 Oct 2023 06:49:12 GMT</pubDate>
    <dc:creator>Alice_Yang</dc:creator>
    <dc:date>2023-10-19T06:49:12Z</dc:date>
    <item>
      <title>LPC54606 SCTimer change period problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC54606-SCTimer-change-period-problem/m-p/1740520#M54426</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am working with SCTimer to generate a PWM signal.&lt;/P&gt;&lt;P&gt;This signal I need to change the period and duty cycle frequently.&lt;/P&gt;&lt;P&gt;I have created a function in fs_timer library using the code of " SCTIMER_UpdatePwmDutycycle".&lt;/P&gt;&lt;P&gt;The function works when stepping in debug mode step by step, but when runing normal it stops generating the pulses. I am missing abything needed to change the match register and do not break anything?&lt;/P&gt;&lt;P&gt;The following is the function code used:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;void SCTIMER_UpdatePwmPeriod(SCT_Type *base, sctimer_out_t output,
        sctimer_pwm_mode_t mode,
        uint32_t pwmFreq_Hz,
		uint8_t dutyCyclePercent,
        uint32_t srcClock_Hz,
        uint32_t event)
{
    assert(0U != srcClock_Hz);
    assert(0U != pwmFreq_Hz);
    assert((uint32_t)output &amp;lt; (uint32_t)FSL_FEATURE_SCT_NUMBER_OF_OUTPUTS);
    assert(1U == (base-&amp;gt;CONFIG &amp;amp; SCT_CONFIG_UNIFY_MASK));
    status_t status = kStatus_Fail;
    status_t status2;
    uint32_t period, pulsePeriod = 0;
    uint32_t sctClock    = srcClock_Hz / (((base-&amp;gt;CTRL &amp;amp; SCT_CTRL_PRE_L_MASK) &amp;gt;&amp;gt; SCT_CTRL_PRE_L_SHIFT) + 1U);
    uint32_t periodEvent = 0, pulseEvent = 0;
    uint32_t reg;
    uint32_t periodMatchReg, pulseMatchReg;
    bool isHighTrue      = (0U != (base-&amp;gt;OUT[output].CLR &amp;amp; (1UL &amp;lt;&amp;lt; (event + 1U))));

   if ((s_currentEvent + 2U) &amp;lt;= (uint32_t)FSL_FEATURE_SCT_NUMBER_OF_EVENTS)
     {
       /* Calculate PWM period match value */
       if (mode == kSCTIMER_EdgeAlignedPwm)
          {
            period = (sctClock / pwmFreq_Hz) - 1U;
          }
          else
          {
            period = sctClock / (pwmFreq_Hz * 2U);
          }

          /* For 100% dutycyle, make pulse period greater than period so the event will never occur */
          if (dutyCyclePercent &amp;gt;= 100U)
          {
             pulsePeriod = period + 2U;
             /* Set the initial output level base on output mode */
             if (isHighTrue)
             {
                 base-&amp;gt;OUTPUT |= (1UL &amp;lt;&amp;lt; (uint32_t)output);
             }
             else
             {
                 base-&amp;gt;OUTPUT &amp;amp;= ~(1UL &amp;lt;&amp;lt; (uint32_t)output);
             }
          }
          else
          {
             pulsePeriod = (uint32_t)(((uint64_t)period * dutyCyclePercent) / 100U);
          }

          /* Retrieve the match register number for the PWM period */
          periodMatchReg = base-&amp;gt;EV[event].CTRL &amp;amp; SCT_EV_CTRL_MATCHSEL_MASK;

          /* Retrieve the match register number for the PWM pulse period */
          pulseMatchReg = base-&amp;gt;EV[event + 1U].CTRL &amp;amp; SCT_EV_CTRL_MATCHSEL_MASK;
          /* Stop the counter before updating match register */
          SCTIMER_StopTimer(base, (uint32_t)kSCTIMER_Counter_U);
          /* Update dutycycle */
          base-&amp;gt;MATCH[periodMatchReg]    = period;
          base-&amp;gt;MATCHREL[periodMatchReg] = period;
          base-&amp;gt;MATCH[pulseMatchReg]    = pulsePeriod;
          base-&amp;gt;MATCHREL[pulseMatchReg] = pulsePeriod;

          /* Restart the counter */
          SCTIMER_StartTimer(base, (uint32_t)kSCTIMER_Counter_U);
      }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 15:12:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC54606-SCTimer-change-period-problem/m-p/1740520#M54426</guid>
      <dc:creator>luimarma</dc:creator>
      <dc:date>2023-10-16T15:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: LPC54606 SCTimer change period problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC54606-SCTimer-change-period-problem/m-p/1742653#M54487</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/160756"&gt;@luimarma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about low the change frequency, it means delay the time before change period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Alice&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 06:49:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC54606-SCTimer-change-period-problem/m-p/1742653#M54487</guid>
      <dc:creator>Alice_Yang</dc:creator>
      <dc:date>2023-10-19T06:49:12Z</dc:date>
    </item>
  </channel>
</rss>

