Content originally posted in LPCWare by IanJames on Wed Mar 13 08:20:48 MST 2013
I am trying to configure PIO0_18 as a PWM output
I have this:
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);
LPC_CT32B0->EMR = (1<<EMC3)|(2<<EMC2)|(1<<EMC1)|(1<<EMC0);
LPC_IOCON->PIO0_18 &= ~0x07; LPC_IOCON->PIO0_18 |= 0x04; /* Timer0_32 MAT0 */
LPC_IOCON->PIO0_19 &= ~0x07; LPC_IOCON->PIO0_19 |= 0x04; /* Timer0_32 MAT1 */
LPC_IOCON->PIO0_20 &= ~0x07; LPC_IOCON->PIO0_20 |= 0x04; /* Timer0_32 MAT2 */
LPC_IOCON->PIO0_21 &= ~0x07; LPC_IOCON->PIO0_21 |= 0x04; /* Timer0_32 MAT3 */
/* Enable the selected PWMs */
LPC_CT32B0->PWMC = 0x0000000F;
LPC_CT32B0->MCR = (1<<10) | (1 << 9);/* Interrupt AND Reset on MR3 */
LPC_CT32B0->MR0 = 50000;
LPC_CT32B0->MR1 = 50000;
LPC_CT32B0->MR2 = 50000;
LPC_CT32B0->MR3 = 50000;
I calculate that 12000000/50000 = 240Hz which is what I need
To set the pwm to say 50% I do this:
LPC_CT32B0->MR0 = 25000;
The problem is that the pwm output is off until it gets to approx 29500 ie 59% thereafter it increases up to 100% when LPC_CT32B0->MR0 = 50000
Does anyone know why low values on MR0 give no pwm output
I changed the pwm range to 500000 with a similar result ie nothing no pwm until MR0 reached 29500, this time of course the value would be about 5.9%. Unfortunately this means that the refresh rate is 24Hz!!