I am beginner. I would like to write simple program, which use pwm. I searched in manual but I didn't find any helpful information. Can someone tell in which chapter manual describes pwm? http://www.nxp.com/documents/user_manual/UM10524.pdf . It will be Systick Handler? Thanks!
I use a LPC1347 to control a RGBW ledstrip. The PWM frequency I use is 10kHz and is working to satisfaction.
Value set to show an example :smileyhappy:
Look at the picture:
If you want to reset the counter when it reaches the value of the MR0 register, you must set bit 1 in MCR
LPC_TMR16B0->MCR = 1<<1;
If you want to reset the counter when it reaches the value of the MR0 register and generate interrupt, you must set bit 0 and 1
LPC_TMR16B0->MCR = 1<<0 | 1<<1;
What frequency to work with PWM ?
No, You must use timer CT16B0/1 or CT32B0/1, see 16.7.12 PWM Control register and 17.7.12 PWM Control Register.
The following code, which I have not tested:
#include "LPC13xx.h"
int main(void) {
/* IO CONFIG */
LPC_SYSCON->SYSAHBCLKCTRL |= 1<<16; // enable IOCON
LPC_IOCON->PIO0_8 |= 0x2; // CT16B0_MAT0
/* TIMER CONFIG */
LPC_SYSCON->SYSAHBCLKCTRL |= 1<<7; // enable CT16B0
LPC_TMR16B0->MR3 = 1000; // timer period
LPC_TMR16B0->MR0 = 500; // 50% duty cycle
LPC_TMR16B0->MCR |= 1<10; // reset TC on match MR3
LPC_TMR16B0->PWMC |= 1<0; // enable PWM on CT16B0_MAT0
LPC_TMR16B0->TCR = 1; // start timer and PWM
while(1) {
}
return 0 ;
}
Mateusz are you from Poland ?
Hi Tom,
Why did you choose a value of 1000 for the timer period?
I need to control an RGB LED through PWM and I'm having a hard time configuring the registers.. I have setup MR0-MR2 to control the three PWM signals I need, but I don't understand how to configure MCR. Any help would be greatly appreciated.
Thank you very much
Hi,
Please check the following tutorial and let me know if this helps.
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------