<?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 PWM issues - LPC1769 in LPCXpresso IDE</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586821#M27375</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by nbaer89 on Wed Nov 16 12:40:51 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to get PWM control servo motors for a project I am working on however I can only get one of the pwm pins to change its pulse width. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The PWM_Init function below works fine, it sets each pin to the 1.5ms pulsewidth I need and the servos hold their center position.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;void PWM_Init( void )
{

&amp;nbsp; LPC_PINCON-&amp;gt;PINSEL4 &amp;amp;= ~0x000000FF; // Clear P2.0~3 Pins
&amp;nbsp; LPC_PINCON-&amp;gt;PINSEL4 |=&amp;nbsp; 0x00000055; // Set pins for PWM

&amp;nbsp; LPC_PWM1-&amp;gt;TCR = 0x00000002;&amp;nbsp;&amp;nbsp; /* Counter Reset */
&amp;nbsp; LPC_PWM1-&amp;gt;PR&amp;nbsp; = 0x18;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Count Frequency = Peripheral clock / (24+1) = [1 Mhz]*/
&amp;nbsp; LPC_PWM1-&amp;gt;MCR = (1&amp;lt;&amp;lt;1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Reset TC on Match 0 */
&amp;nbsp; LPC_PWM1-&amp;gt;MR0 = 20000;&amp;nbsp; /* set PWM cycle */
&amp;nbsp; LPC_PWM1-&amp;gt;MR1 = 1500;
&amp;nbsp; LPC_PWM1-&amp;gt;MR2 = 1500;
&amp;nbsp; LPC_PWM1-&amp;gt;MR3 = 1500;
&amp;nbsp; LPC_PWM1-&amp;gt;MR4 = 1500;

&amp;nbsp; /* all PWM latch enabled */
&amp;nbsp; LPC_PWM1-&amp;gt;LER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN;
&amp;nbsp; return;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However when I call PWM_Set to change the pulsewidth of a servo I can only get the PWM1[2] pulsewidth(set with case CH_ELEVATOR) to change, the others will keep the initial pulsewidth.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;void PWM_Set( uint32_t channelNum, uint32_t pulseWidth )
{

&amp;nbsp; // Set new pulse width to match register and enable latch
&amp;nbsp; switch ( channelNum )
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; case CH_ROLL :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;MR1 = pulseWidth; // Set match register 1 value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;LER = (1&amp;lt;&amp;lt;1); // Enable latch 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; case CH_ELEVATOR :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;MR2 = pulseWidth; // Set match register 2 value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;LER = (1&amp;lt;&amp;lt;2); // Enable latch 2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; case CH_THROTTLE :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;MR3 = pulseWidth; // Set match register 3 value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;LER = (1&amp;lt;&amp;lt;3); // Enable latch 3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; case CH_RUDDER :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;MR4 = pulseWidth; // Set match register 4 value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;LER = (1&amp;lt;&amp;lt;4); // Enable latch 4
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; }
&amp;nbsp; return;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I doing something wrong here? The code is running in freeRTOS however I don't think that is the cause of the issue. Any help will be greatly appreciated, thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jun 2016 01:21:55 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-16T01:21:55Z</dc:date>
    <item>
      <title>PWM issues - LPC1769</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586821#M27375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by nbaer89 on Wed Nov 16 12:40:51 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to get PWM control servo motors for a project I am working on however I can only get one of the pwm pins to change its pulse width. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The PWM_Init function below works fine, it sets each pin to the 1.5ms pulsewidth I need and the servos hold their center position.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;void PWM_Init( void )
{

&amp;nbsp; LPC_PINCON-&amp;gt;PINSEL4 &amp;amp;= ~0x000000FF; // Clear P2.0~3 Pins
&amp;nbsp; LPC_PINCON-&amp;gt;PINSEL4 |=&amp;nbsp; 0x00000055; // Set pins for PWM

&amp;nbsp; LPC_PWM1-&amp;gt;TCR = 0x00000002;&amp;nbsp;&amp;nbsp; /* Counter Reset */
&amp;nbsp; LPC_PWM1-&amp;gt;PR&amp;nbsp; = 0x18;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Count Frequency = Peripheral clock / (24+1) = [1 Mhz]*/
&amp;nbsp; LPC_PWM1-&amp;gt;MCR = (1&amp;lt;&amp;lt;1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Reset TC on Match 0 */
&amp;nbsp; LPC_PWM1-&amp;gt;MR0 = 20000;&amp;nbsp; /* set PWM cycle */
&amp;nbsp; LPC_PWM1-&amp;gt;MR1 = 1500;
&amp;nbsp; LPC_PWM1-&amp;gt;MR2 = 1500;
&amp;nbsp; LPC_PWM1-&amp;gt;MR3 = 1500;
&amp;nbsp; LPC_PWM1-&amp;gt;MR4 = 1500;

&amp;nbsp; /* all PWM latch enabled */
&amp;nbsp; LPC_PWM1-&amp;gt;LER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN;
&amp;nbsp; return;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However when I call PWM_Set to change the pulsewidth of a servo I can only get the PWM1[2] pulsewidth(set with case CH_ELEVATOR) to change, the others will keep the initial pulsewidth.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;void PWM_Set( uint32_t channelNum, uint32_t pulseWidth )
{

&amp;nbsp; // Set new pulse width to match register and enable latch
&amp;nbsp; switch ( channelNum )
&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; case CH_ROLL :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;MR1 = pulseWidth; // Set match register 1 value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;LER = (1&amp;lt;&amp;lt;1); // Enable latch 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; case CH_ELEVATOR :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;MR2 = pulseWidth; // Set match register 2 value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;LER = (1&amp;lt;&amp;lt;2); // Enable latch 2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; case CH_THROTTLE :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;MR3 = pulseWidth; // Set match register 3 value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;LER = (1&amp;lt;&amp;lt;3); // Enable latch 3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp; case CH_RUDDER :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;MR4 = pulseWidth; // Set match register 4 value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LPC_PWM1-&amp;gt;LER = (1&amp;lt;&amp;lt;4); // Enable latch 4
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; }
&amp;nbsp; return;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I doing something wrong here? The code is running in freeRTOS however I don't think that is the cause of the issue. Any help will be greatly appreciated, thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:21:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586821#M27375</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: PWM issues - LPC1769</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586822#M27376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Wed Nov 16 13:04:57 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you use debugger to check if your function PWM_Set is selecting the correct case (or always case CH_ELEVATOR)?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:21:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586822#M27376</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: PWM issues - LPC1769</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586823#M27377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by nbaer89 on Wed Nov 16 13:27:11 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Yeah it steps through the cases properly. Right now I only call the function for the first two cases. But I think I have found the problem, I was setting the latch values instead of ORing them so when I called pitch it set the latch register for only latch 2 before the first latch was utilized.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:21:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586823#M27377</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: PWM issues - LPC1769</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586824#M27378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Ex-Zero on Wed Nov 16 13:33:21 MST 2011&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, of course :rolleyes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I usually write all PWM latch bits even if I change only one of them. It's faster than reading and writing :)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:21:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586824#M27378</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: PWM issues - LPC1769</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586825#M27379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by raymond.centek on Fri Jan 20 00:57:43 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I also encountered the similar problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;According to the code at "lpc17xx_pwm.c" version 2.1 (31-3-2011), the method to write one Match Register (void PWM_ConfigMatch()) is write MR and "OR" the corresponding Latch to high.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In my case, when event occured, I need to change two PWM value. The first method I tried is to call "PWM_ConfigMatch" twice only. Using this method sometimes will cause the channel output full power, i.e., always output high. I investigated the registers about PWM when it goes wrong, but the values were what I assigned to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The second method which I currently use to avoid the problem is using the function "PWM_MultiMatchUpdate" in PWM library. However, I need to assign the array of struct, which I think is an inefficient way to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I mentioned the pwm library is because I think if the official library(though I'm not sure if it is really the official library from NXP. I assume it is) use this method as well, the MCU should be support this method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to know if the second method is the only method I can use to avoid the problem, or there is something need to do if I want to use method one.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 01:21:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/PWM-issues-LPC1769/m-p/586825#M27379</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T01:21:58Z</dc:date>
    </item>
  </channel>
</rss>

