Hi friends!
I am using a LPC11u3x microcontroller with 16 and 32 bits PWM counters to manage RGB leds.
The 32bit counter is working properly at 10kHz but 16bit ones can't get that frequency.
Anyway, I don't need 10kHz for this application, of course, but I configured a 200Hz frequency and the counters didn't work properly neither.
This is my config function:
#define PWM_FREQ_HZ 10000
#define PWM_DUTY 50
timerFreq = Chip_Clock_GetSystemClockRate();
Chip_TIMER_Disable(LPC_TIMER32_0); //disable to modify registers
Chip_TIMER_Disable(LPC_TIMER16_0);
Chip_TIMER_Disable(LPC_TIMER16_1);
Chip_TIMER_Init(LPC_TIMER32_0);
Chip_TIMER_Init(LPC_TIMER16_0);
Chip_TIMER_Init(LPC_TIMER16_1);
// This configures MRx to act as PWM register --> GPIO (MAT0..3)
// Value written to MATx_pin will determine when GPIO goes high
// which basically determines PWM duty cycle
LPC_TIMER32_0->PWMC = (1 << 3); //P0.11 MAT3
LPC_TIMER16_0->PWMC = (1 << 0); //P0.8 MAT0
LPC_TIMER16_1->PWMC = (1 << 1); //P0.22 MAT1
// pr = SystemCoreClock / (4 * 1000000) - 1; // 12 Mhz - 1 = 11 for prescaler
// Chip_TIMER_PrescaleSet(LPC_TIMER16_0, pr); // C16Bx need prescaler to not overload
// Chip_TIMER_PrescaleSet(LPC_TIMER16_1, pr); //
// We set TIMER32_0 to reset TC on MR1 match --> usar otro que no sea el del PWM
// this effectively makes value written to MR1 -->
// to determine PWM signal frequency
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 0); //MR0
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_0, 1); //MR1
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_1, 0); //MR0
periodRate = timerFreq / PWM_FREQ_HZ;
Chip_TIMER_SetMatch(LPC_TIMER32_0, 0, periodRate); //MR0
Chip_TIMER_SetMatch(LPC_TIMER16_0, 1, periodRate); //MR1
Chip_TIMER_SetMatch(LPC_TIMER16_1, 0, periodRate); //MR0
dutyMatchCount = ((periodRate + 1) * PWM_DUTY) / 100;
Chip_TIMER_SetMatch(LPC_TIMER32_0, 3, dutyMatchCount); //MR3
Chip_TIMER_SetMatch(LPC_TIMER16_0, 0, dutyMatchCount); //MR0
Chip_TIMER_SetMatch(LPC_TIMER16_1, 1, dutyMatchCount); //MR1
// Just in case, set MR1, MR2 to 0, which makes them do nothing basically.
Chip_TIMER_SetMatch(LPC_TIMER32_0, 1, 0);
Chip_TIMER_SetMatch(LPC_TIMER32_0, 2, 0);
Chip_TIMER_SetMatch(LPC_TIMER16_1, 2, 0);
My question is, what is the maximum and minimum frequencies reachable by the 32 and 16 bits PWM counters taking account of a 12MHz oscillator.
At 1000Hz, all the counters are working fine.