<?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: LPC55S28 SCTimer two PWM outputs with different frequencies</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S28-SCTimer-two-PWM-outputs-with-different-frequencies/m-p/1713948#M53967</link>
    <description>&lt;P&gt;I realize I am late for the party but I found a more flexible solution.&lt;BR /&gt;I used it to generate a 1MHz 50% dutycycle signal synchronized to a kHz 20% dutycyle.&lt;BR /&gt;I used the peripherals perspective in mcuxpresso, so it is hard to share source code, but the setup is as follows:&lt;BR /&gt;SCT clock is 16 MHz, using a prescaler of 8, the counter frequency is 2 MHz.&lt;/P&gt;&lt;P&gt;event 0:&lt;BR /&gt;match event with match value 0&lt;BR /&gt;action: toggle sct output 1&lt;/P&gt;&lt;P&gt;event 1&lt;BR /&gt;match event with match value 400&lt;BR /&gt;action: clear sct output 2&lt;/P&gt;&lt;P&gt;event 2&lt;BR /&gt;match event with match value 1999&lt;BR /&gt;action: set sct output 2 and limit counter (restart it from zero).&lt;/P&gt;&lt;P&gt;in the source code, add the following line before starting the timer:&lt;BR /&gt;SCT0-&amp;gt;EV[0].CTRL |= SCT_EV_CTRL_MATCHMEM(1);&lt;BR /&gt;This means that the event 0 fires every clock after the initial match. since the match is set to 0 it just toggles the output at 1MHz from the the timer is started.&lt;/P&gt;&lt;P&gt;event 1 and event 2 control the second output and are responsible for limiting the timer.&lt;BR /&gt;They can be set almost independently of event0.&lt;/P&gt;&lt;P&gt;summary:&lt;BR /&gt;Choose a prescaler to get a counter frequency twice as fast as the fastest signal, by using the MATCHMEM setting of event 0.&lt;BR /&gt;Use two indenpendent events to set the second pwm channel and limit the counter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Lauge&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Aug 2023 09:48:15 GMT</pubDate>
    <dc:creator>laugechristense</dc:creator>
    <dc:date>2023-08-30T09:48:15Z</dc:date>
    <item>
      <title>LPC55S28 SCTimer two PWM outputs with different frequencies</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S28-SCTimer-two-PWM-outputs-with-different-frequencies/m-p/1228017#M43884</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have tried to generate 2 PWM outputs with SCT0 of &lt;A href="https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/lpc5500-cortex-m33/lpc552x-s2x-mainstream-arm-cortex-m33-based-microcontroller-family:LPC552x-S2x" target="_blank" rel="noopener"&gt;LPC55S28&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;The requirements:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;No CPU load (callbacks)&lt;/LI&gt;&lt;LI&gt;Outputs must be synchronized&lt;/LI&gt;&lt;LI&gt;Output X must have a frequency of output Y times 4&lt;/LI&gt;&lt;LI&gt;Duty cycle of both outputs must be 50 %&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;No luck yet with the examples or the PWM cookbook. Is this possible in theory?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2 PWM outputs with different frequencies" style="width: 823px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/136760iB9492D96A0535ED7/image-size/large?v=v2&amp;amp;px=999" role="button" title="SCTimer_two_freq.png" alt="2 PWM outputs with different frequencies" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;2 PWM outputs with different frequencies&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;&lt;SPAN&gt;: The signal of SCTIMER_Out_X in the picture is actually 8MHz while it should be 4MHz.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:48:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S28-SCTimer-two-PWM-outputs-with-different-frequencies/m-p/1228017#M43884</guid>
      <dc:creator>vanska</dc:creator>
      <dc:date>2021-02-10T09:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55S28 SCTimer two PWM outputs with different frequencies</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S28-SCTimer-two-PWM-outputs-with-different-frequencies/m-p/1229217#M43905</link>
      <description>&lt;P&gt;Got it working. The resolution is not that good with MHz frequencies, though.&lt;/P&gt;&lt;P&gt;Here's one solution that might require some refactoring:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;uint32_t pwmFrequency = frequency * 4;
uint32_t sctClock = CLOCK_GetFreq(kCLOCK_BusClk) / (((base-&amp;gt;CTRL &amp;amp; SCT_CTRL_PRE_L_MASK) &amp;gt;&amp;gt; SCT_CTRL_PRE_L_SHIFT) + 1U);

uint32_t period = (sctClock / pwmFrequency) - 1U;	// edge aligned PWM
uint32_t pulsePeriod = (period * 50U) / 100U;		// pulse width match value

base-&amp;gt;MATCHREL_ACCESS16BIT[0].MATCHRELL = (uint16_t)(period * 4);	// match value for 1MHz

for (uint8_t i = 1; i &amp;lt; 8; i++)
{
	// Match values for the rest of the events
	base-&amp;gt;MATCHREL_ACCESS16BIT[i].MATCHRELL = (uint16_t)((uint16_t)(i/2) * period + (i%2) * pulsePeriod);
}

for (uint8_t i = 0; i &amp;lt; 8; i++)
{
	base-&amp;gt;EV[i].STATE = 0xFFFFFFFF;                 // all states
	base-&amp;gt;EV[i].CTRL = (i &amp;lt;&amp;lt; 0) | (1 &amp;lt;&amp;lt; 12);        // match i condition only
}

base-&amp;gt;OUT[2].SET = (1 &amp;lt;&amp;lt; 0);                        // event 0 will set SCT0_OUT2
base-&amp;gt;OUT[2].CLR = (1 &amp;lt;&amp;lt; 4);                        // event 4 will clear SCT0_OUT2
base-&amp;gt;OUT[3].SET = 0x55;                            // even events (0, 2, 4, 6) will set SCT0_OUT3
base-&amp;gt;OUT[3].CLR = 0xAA;                            // odd events (1, 3, 5, 7) will clear SCT0_OUT3

base-&amp;gt;CTRL &amp;amp;= ~(SCT_CTRL_HALT_L_MASK);              // start/unhalt timer by clearing bit 2 of CTRL register&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:43:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S28-SCTimer-two-PWM-outputs-with-different-frequencies/m-p/1229217#M43905</guid>
      <dc:creator>vanska</dc:creator>
      <dc:date>2021-02-10T09:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55S28 SCTimer two PWM outputs with different frequencies</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S28-SCTimer-two-PWM-outputs-with-different-frequencies/m-p/1713948#M53967</link>
      <description>&lt;P&gt;I realize I am late for the party but I found a more flexible solution.&lt;BR /&gt;I used it to generate a 1MHz 50% dutycycle signal synchronized to a kHz 20% dutycyle.&lt;BR /&gt;I used the peripherals perspective in mcuxpresso, so it is hard to share source code, but the setup is as follows:&lt;BR /&gt;SCT clock is 16 MHz, using a prescaler of 8, the counter frequency is 2 MHz.&lt;/P&gt;&lt;P&gt;event 0:&lt;BR /&gt;match event with match value 0&lt;BR /&gt;action: toggle sct output 1&lt;/P&gt;&lt;P&gt;event 1&lt;BR /&gt;match event with match value 400&lt;BR /&gt;action: clear sct output 2&lt;/P&gt;&lt;P&gt;event 2&lt;BR /&gt;match event with match value 1999&lt;BR /&gt;action: set sct output 2 and limit counter (restart it from zero).&lt;/P&gt;&lt;P&gt;in the source code, add the following line before starting the timer:&lt;BR /&gt;SCT0-&amp;gt;EV[0].CTRL |= SCT_EV_CTRL_MATCHMEM(1);&lt;BR /&gt;This means that the event 0 fires every clock after the initial match. since the match is set to 0 it just toggles the output at 1MHz from the the timer is started.&lt;/P&gt;&lt;P&gt;event 1 and event 2 control the second output and are responsible for limiting the timer.&lt;BR /&gt;They can be set almost independently of event0.&lt;/P&gt;&lt;P&gt;summary:&lt;BR /&gt;Choose a prescaler to get a counter frequency twice as fast as the fastest signal, by using the MATCHMEM setting of event 0.&lt;BR /&gt;Use two indenpendent events to set the second pwm channel and limit the counter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Lauge&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 09:48:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55S28-SCTimer-two-PWM-outputs-with-different-frequencies/m-p/1713948#M53967</guid>
      <dc:creator>laugechristense</dc:creator>
      <dc:date>2023-08-30T09:48:15Z</dc:date>
    </item>
  </channel>
</rss>

