LPC11U68 PWM frequency

cancel
Showing results for 
Search instead for 
Did you mean: 

LPC11U68 PWM frequency

232 Views
castle
Contributor I

Hello,

I have LPCXpresso OM13058 board with LPC11U68 MCU. 

Board schematic: https://www.nxp.com/downloads/en/schematics/LPC11U68_Xpresso_v2_Schematic_RevC_1.pdf

I am using this board standalone and compile my program with IAR IDE. For MCU programming I use Flash magic. I attached my project configuration files, including SystemInit.

My program runs at 48MHz. I am trying to generate 200kHz PWM for a GPIO pin. I init my CT32B0 timer:

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);
LPC_CT32B0->CTCR = 0x0;
LPC_CT32B0->PR = 48-1; //prescale, I get 1MHz
LPC_CT32B0->TCR = 0x02;

Then I have a timer counter based delay function:

void delay(unsigned int ms)
{
  LPC_CT32B0->TCR = 0x02;
  LPC_CT32B0->TCR = 0x01;
  while(LPC_CT32B0->TC < ms);
  LPC_CT32B0->TCR = 0x00;
}

Simple GPIO toggling to get 1kHz (works well, oscilloscope shows 1kHz):

LPC_GPIO_PORT->NOT[0] |= (1<<17);
delay(500);

Then I changed a value from 500 to 50, but instead of getting 10kHz, my oscilloscope shows 9.88kHz.

LPC_GPIO_PORT->NOT[0] |= (1<<17);
delay(50);

By changing value to 5, a result get much more inaccurate. I get 87.7kHz instead of 100kHz:

LPC_GPIO_PORT->NOT[0] |= (1<<17);
delay(5);

As you can see, the frequency is not so high, but the error is not acceptable. I have implemented USART that is running 115200 baud rate without any issues, so I think the main clock frequency is actually running at 48MHz (SystemCoreClock also returns value 48000000).

I have tried different ports and pins, but result the same. Also, I have tried to run the same code on another board with 72MHz MCU LPC1343, ant GPIO switching at 200kHz was perfect and without any errors.

Could you please help to find out the problem. Are there any additional configuration needed or the issue is hardware?

0 Kudos
3 Replies

7 Views
Badman
Contributor I

I think the timer is counting too fast. If actually mcu clocked at 48 MHz for delay (5) only 5 us.

0 Kudos

173 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello castle,

Generate PWM , recommend you use SCTIEMR, there is PWM application note, you can refer to:  

https://www.nxp.com/docs/en/application-note/AN11538.zip  

Toggle gpio by software not as accurate as hardware(SCTIEMR).

 

BR

Alice

 

0 Kudos

207 Views
castle
Contributor I

Any help?

0 Kudos