PWM problem in LPC1227 with PIO1_6

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PWM problem in LPC1227 with PIO1_6

Jump to solution
1,659 Views
r_michalek
Contributor I

Hello,

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.

 

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 PIO0_16 with CT16B1_MAT1 mode and it works perfectly. This situation executing code with MY_SWITCH = 2.

 

I tested on two HW - the original LPCXpresso1200 with LPC1227 in LQFP64 case and one on my boards with LPC1227 in LQFP48. Same behaviour on both chips.

Here is the code:

 

 

 

 

/*
===============================================================================
 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 <cr_section_macros.h>

/*
 * 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 << 4)
#define		IOCON_ADMODE_DIGITAL	(1 << 7)


int main(void)
{
    volatile unsigned char i = 0;

	LPC_SYSCON->SYSAHBCLKCTRL = 0x0001001FUL;	// Enable SYS, ROM, RAM, FLASHREG, FLASHARRAY and IOCON
	LPC_SYSCON->SYSAHBCLKCTRL |= (0x01 << 8);	// Enable CT16B1
	LPC_SYSCON->SYSAHBCLKCTRL |= (0x01 << 30);	// Enable GPIO1
	LPC_SYSCON->SYSAHBCLKCTRL |= (0x01 << 31);	// Enable GPIO0

    #if MY_SWITCH == 1
	LPC_IOCON->PIO1_5 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT0
	LPC_IOCON->PIO1_6 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1
    #endif

    #if MY_SWITCH == 2
	LPC_IOCON->PIO1_5 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT0
	LPC_IOCON->PIO0_16 = IOCON_FUNC_4 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1
	LPC_IOCON->PIO1_6 = IOCON_FUNC_0 + IOCON_ADMODE_DIGITAL;		// GPIO
    LPC_GPIO1->DIR |= (1 << 6);                                                                                                     // GPIO Output
    #endif

	// configure CT16B1
	LPC_CT16B1->TCR = 0x02;			// reset on
	LPC_CT16B1->TCR = 0x00;			// reset off

	LPC_CT16B1->CTCR = 0x00;		// Timer mode
	LPC_CT16B1->PR = 0x0000;		// no pre-scale
	LPC_CT16B1->MR0 = 250;			// PWM on MAT0 (ratio 1:1)
	LPC_CT16B1->MR1 = 250;			// PWM on MAT1 (ratio 1:1)
	LPC_CT16B1->MR2 = 500;			// cycle length
	LPC_CT16B1->MCR = (0x01 << 7);	// reset on MR2 => cycle length
	LPC_CT16B1->CCR = 0x00;			// disable all captures
	LPC_CT16B1->PWMC = 0x03;		// MAT0 and MAT1 is enabled for PWM mode
	LPC_CT16B1->EMR = (0x02 << 4) | (0x02 << 6);	// set bit EM0 and EM1 to high on match

	LPC_CT16B1->TCR = 0x01;			// counter enable
    // end of configuration

	while (1)
	{
		i = 1 - i;

        #if MY_SWITCH == 2
        // SetGPIO1(PIO1_6, i);
        i ? (LPC_GPIO1->SET = 1<<6) : (LPC_GPIO1->CLR = 1<<6);
        #endif

        // "Dummy" NOP to allow source level single
        // stepping of tight while() loop
        __asm volatile ("nop");
	}
    return 0 ;
}

 

 

 

 

 

Labels (2)
0 Kudos
Reply
1 Solution
1,627 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Rastilav,

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.

Pls use the line

LPC_IOCON->PIO1_6 = IOCON_FUNC_2 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1

 

The following is your original code:

LPC_IOCON->PIO1_6 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1

xiangjun_rong_0-1642989556870.png

Hope it can help you

BR

XiangJun Rong

 

View solution in original post

0 Kudos
Reply
2 Replies
1,619 Views
r_michalek
Contributor I

Oh, I was blind. I checked it several times and still didn't see it. Thank you.

0 Kudos
Reply
1,628 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Rastilav,

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.

Pls use the line

LPC_IOCON->PIO1_6 = IOCON_FUNC_2 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1

 

The following is your original code:

LPC_IOCON->PIO1_6 = IOCON_FUNC_3 + IOCON_ADMODE_DIGITAL;		// CT16B1_MAT1

xiangjun_rong_0-1642989556870.png

Hope it can help you

BR

XiangJun Rong

 

0 Kudos
Reply