LPC11U68 PWM frequency

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC11U68 PWM frequency

1,421 次查看
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 项奖励
3 回复数

1,196 次查看
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 项奖励

1,362 次查看
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 项奖励

1,396 次查看
castle
Contributor I

Any help?

0 项奖励