<?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 problem in LPC1227 with PIO1_6 in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/PWM-problem-in-LPC1227-with-PIO1-6/m-p/1403578#M47716</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to use PIO1_5 and PIO1_6 for PWM. PWM works on the PIO1_5 without problems, but not on the PIO1_6. When I set PIO1_6 as CT16B1_MAT1, there is always a log.0, even if EM1 bit changes in the EMR register. This situation executing code with MY_SWITCH = 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to use PIO1_6 as a GPIO pin in order to check if this pin is ok (toggling). It is definitely working properly. Also I changed PIO1_6 to&amp;nbsp;PIO0_16 with CT16B1_MAT1 mode and it works perfectly.&amp;nbsp;This situation executing code with MY_SWITCH = 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested on two HW - the original LPCXpresso1200 with LPC1227 in LQFP64 case and one on my boards with LPC1227 in LQFP48.&amp;nbsp;Same behaviour on both chips.&lt;/P&gt;&lt;P&gt;Here is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/*
===============================================================================
 Name        : Test_PWM.c
 Author      : R-Michalek
 Version     :
 Copyright   : $(copyright)
 Description : Simple test of PWM on PIO1_5 and PIO1_6
===============================================================================
*/

//#ifdef __USE_CMSIS
#include "LPC122x.h"
//#endif

#include &amp;lt;cr_section_macros.h&amp;gt;

/*
 * MY_SWITCH
 *  = 1		~ PWM on PIO1_5 and PIO1_6 - wanted version
 *  = 2		~ PWM on PIO1_6 and PIO0_16; PIO1_6 is on GPIO mode and toggles in main loop
 */
#define MY_SWITCH       1


#define		IOCON_FUNC_0			(0)
#define		IOCON_FUNC_1			(1)
#define		IOCON_FUNC_2			(2)
#define		IOCON_FUNC_3			(3)
#define		IOCON_FUNC_4			(4)
#define		IOCON_MODE_PULL_UP		(1 &amp;lt;&amp;lt; 4)
#define		IOCON_ADMODE_DIGITAL	(1 &amp;lt;&amp;lt; 7)


int main(void)
{
    volatile unsigned char i = 0;

	LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL = 0x0001001FUL;	// Enable SYS, ROM, RAM, FLASHREG, FLASHARRAY and IOCON
	LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= (0x01 &amp;lt;&amp;lt; 8);	// Enable CT16B1
	LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= (0x01 &amp;lt;&amp;lt; 30);	// Enable GPIO1
	LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= (0x01 &amp;lt;&amp;lt; 31);	// Enable GPIO0

    #if MY_SWITCH == 1
	LPC_IOCON-&amp;gt;PIO1_5 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT0
	LPC_IOCON-&amp;gt;PIO1_6 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1
    #endif

    #if MY_SWITCH == 2
	LPC_IOCON-&amp;gt;PIO1_5 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT0
	LPC_IOCON-&amp;gt;PIO0_16 = IOCON_FUNC_4 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1
	LPC_IOCON-&amp;gt;PIO1_6 = IOCON_FUNC_0 + IOCON_ADMODE_DIGITAL;		// GPIO
    LPC_GPIO1-&amp;gt;DIR |= (1 &amp;lt;&amp;lt; 6);                                                                                                     // GPIO Output
    #endif

	// configure CT16B1
	LPC_CT16B1-&amp;gt;TCR = 0x02;			// reset on
	LPC_CT16B1-&amp;gt;TCR = 0x00;			// reset off

	LPC_CT16B1-&amp;gt;CTCR = 0x00;		// Timer mode
	LPC_CT16B1-&amp;gt;PR = 0x0000;		// no pre-scale
	LPC_CT16B1-&amp;gt;MR0 = 250;			// PWM on MAT0 (ratio 1:1)
	LPC_CT16B1-&amp;gt;MR1 = 250;			// PWM on MAT1 (ratio 1:1)
	LPC_CT16B1-&amp;gt;MR2 = 500;			// cycle length
	LPC_CT16B1-&amp;gt;MCR = (0x01 &amp;lt;&amp;lt; 7);	// reset on MR2 =&amp;gt; cycle length
	LPC_CT16B1-&amp;gt;CCR = 0x00;			// disable all captures
	LPC_CT16B1-&amp;gt;PWMC = 0x03;		// MAT0 and MAT1 is enabled for PWM mode
	LPC_CT16B1-&amp;gt;EMR = (0x02 &amp;lt;&amp;lt; 4) | (0x02 &amp;lt;&amp;lt; 6);	// set bit EM0 and EM1 to high on match

	LPC_CT16B1-&amp;gt;TCR = 0x01;			// counter enable
    // end of configuration

	while (1)
	{
		i = 1 - i;

        #if MY_SWITCH == 2
        // SetGPIO1(PIO1_6, i);
        i ? (LPC_GPIO1-&amp;gt;SET = 1&amp;lt;&amp;lt;6) : (LPC_GPIO1-&amp;gt;CLR = 1&amp;lt;&amp;lt;6);
        #endif

        // "Dummy" NOP to allow source level single
        // stepping of tight while() loop
        __asm volatile ("nop");
	}
    return 0 ;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Jan 2022 19:06:49 GMT</pubDate>
    <dc:creator>r_michalek</dc:creator>
    <dc:date>2022-01-23T19:06:49Z</dc:date>
    <item>
      <title>PWM problem in LPC1227 with PIO1_6</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/PWM-problem-in-LPC1227-with-PIO1-6/m-p/1403578#M47716</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to use PIO1_5 and PIO1_6 for PWM. PWM works on the PIO1_5 without problems, but not on the PIO1_6. When I set PIO1_6 as CT16B1_MAT1, there is always a log.0, even if EM1 bit changes in the EMR register. This situation executing code with MY_SWITCH = 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to use PIO1_6 as a GPIO pin in order to check if this pin is ok (toggling). It is definitely working properly. Also I changed PIO1_6 to&amp;nbsp;PIO0_16 with CT16B1_MAT1 mode and it works perfectly.&amp;nbsp;This situation executing code with MY_SWITCH = 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested on two HW - the original LPCXpresso1200 with LPC1227 in LQFP64 case and one on my boards with LPC1227 in LQFP48.&amp;nbsp;Same behaviour on both chips.&lt;/P&gt;&lt;P&gt;Here is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/*
===============================================================================
 Name        : Test_PWM.c
 Author      : R-Michalek
 Version     :
 Copyright   : $(copyright)
 Description : Simple test of PWM on PIO1_5 and PIO1_6
===============================================================================
*/

//#ifdef __USE_CMSIS
#include "LPC122x.h"
//#endif

#include &amp;lt;cr_section_macros.h&amp;gt;

/*
 * MY_SWITCH
 *  = 1		~ PWM on PIO1_5 and PIO1_6 - wanted version
 *  = 2		~ PWM on PIO1_6 and PIO0_16; PIO1_6 is on GPIO mode and toggles in main loop
 */
#define MY_SWITCH       1


#define		IOCON_FUNC_0			(0)
#define		IOCON_FUNC_1			(1)
#define		IOCON_FUNC_2			(2)
#define		IOCON_FUNC_3			(3)
#define		IOCON_FUNC_4			(4)
#define		IOCON_MODE_PULL_UP		(1 &amp;lt;&amp;lt; 4)
#define		IOCON_ADMODE_DIGITAL	(1 &amp;lt;&amp;lt; 7)


int main(void)
{
    volatile unsigned char i = 0;

	LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL = 0x0001001FUL;	// Enable SYS, ROM, RAM, FLASHREG, FLASHARRAY and IOCON
	LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= (0x01 &amp;lt;&amp;lt; 8);	// Enable CT16B1
	LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= (0x01 &amp;lt;&amp;lt; 30);	// Enable GPIO1
	LPC_SYSCON-&amp;gt;SYSAHBCLKCTRL |= (0x01 &amp;lt;&amp;lt; 31);	// Enable GPIO0

    #if MY_SWITCH == 1
	LPC_IOCON-&amp;gt;PIO1_5 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT0
	LPC_IOCON-&amp;gt;PIO1_6 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1
    #endif

    #if MY_SWITCH == 2
	LPC_IOCON-&amp;gt;PIO1_5 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT0
	LPC_IOCON-&amp;gt;PIO0_16 = IOCON_FUNC_4 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1
	LPC_IOCON-&amp;gt;PIO1_6 = IOCON_FUNC_0 + IOCON_ADMODE_DIGITAL;		// GPIO
    LPC_GPIO1-&amp;gt;DIR |= (1 &amp;lt;&amp;lt; 6);                                                                                                     // GPIO Output
    #endif

	// configure CT16B1
	LPC_CT16B1-&amp;gt;TCR = 0x02;			// reset on
	LPC_CT16B1-&amp;gt;TCR = 0x00;			// reset off

	LPC_CT16B1-&amp;gt;CTCR = 0x00;		// Timer mode
	LPC_CT16B1-&amp;gt;PR = 0x0000;		// no pre-scale
	LPC_CT16B1-&amp;gt;MR0 = 250;			// PWM on MAT0 (ratio 1:1)
	LPC_CT16B1-&amp;gt;MR1 = 250;			// PWM on MAT1 (ratio 1:1)
	LPC_CT16B1-&amp;gt;MR2 = 500;			// cycle length
	LPC_CT16B1-&amp;gt;MCR = (0x01 &amp;lt;&amp;lt; 7);	// reset on MR2 =&amp;gt; cycle length
	LPC_CT16B1-&amp;gt;CCR = 0x00;			// disable all captures
	LPC_CT16B1-&amp;gt;PWMC = 0x03;		// MAT0 and MAT1 is enabled for PWM mode
	LPC_CT16B1-&amp;gt;EMR = (0x02 &amp;lt;&amp;lt; 4) | (0x02 &amp;lt;&amp;lt; 6);	// set bit EM0 and EM1 to high on match

	LPC_CT16B1-&amp;gt;TCR = 0x01;			// counter enable
    // end of configuration

	while (1)
	{
		i = 1 - i;

        #if MY_SWITCH == 2
        // SetGPIO1(PIO1_6, i);
        i ? (LPC_GPIO1-&amp;gt;SET = 1&amp;lt;&amp;lt;6) : (LPC_GPIO1-&amp;gt;CLR = 1&amp;lt;&amp;lt;6);
        #endif

        // "Dummy" NOP to allow source level single
        // stepping of tight while() loop
        __asm volatile ("nop");
	}
    return 0 ;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jan 2022 19:06:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/PWM-problem-in-LPC1227-with-PIO1-6/m-p/1403578#M47716</guid>
      <dc:creator>r_michalek</dc:creator>
      <dc:date>2022-01-23T19:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: PWM problem in LPC1227 with PIO1_6</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/PWM-problem-in-LPC1227-with-PIO1-6/m-p/1403607#M47717</link>
      <description>&lt;P&gt;Hi, Rastilav,&lt;/P&gt;
&lt;P&gt;Pls refer to the pin assignment, for the P1_6 pin, it appears that you should set the FUNC as 2, but you set it as 3.&lt;/P&gt;
&lt;P&gt;Pls use the line&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;LPC_IOCON-&amp;gt;PIO1_6 = IOCON_FUNC_2 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following is your original code:&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;LPC_IOCON-&amp;gt;PIO1_6 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1&lt;/LI-CODE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xiangjun_rong_0-1642989556870.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/168565i5B3603D0DDC2E4DE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xiangjun_rong_0-1642989556870.png" alt="xiangjun_rong_0-1642989556870.png" /&gt;&lt;/span&gt;&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 02:01:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/PWM-problem-in-LPC1227-with-PIO1-6/m-p/1403607#M47717</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2022-01-24T02:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: PWM problem in LPC1227 with PIO1_6</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/PWM-problem-in-LPC1227-with-PIO1-6/m-p/1403744#M47725</link>
      <description>&lt;P&gt;Oh, I was blind. I checked it several times and still didn't see it. Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 06:43:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/PWM-problem-in-LPC1227-with-PIO1-6/m-p/1403744#M47725</guid>
      <dc:creator>r_michalek</dc:creator>
      <dc:date>2022-01-24T06:43:21Z</dc:date>
    </item>
  </channel>
</rss>

