Part Number: TM4C1231H6PZ
Hi,
I am using PWM to control LCD backlight brightness - see init function below. I was having an issue where the output pin was turning on after this function, even though I expected it to be off (to be specific, the pin was turning on immediately after the ROM_TimerControlLevel() call).
I played around with the order of these ROM calls, and I figured out that the issue was fixed if I moved the ROM_TimerMatchSet() and ROM_TimerPrescaleMatchSet() calls after the ROM_TimerConfigure() call. Does this make sense? Do the MatchSet() functions need to be after the TimerConfigure in order for them to work properly? Just want to make sure I got to the root of the problem, and didn't just fix it by accident.
static void LCD_BacklightInit(void){
UINT32 timerPeriod;
UINT8 timerPrescaler;
backlightLoadValue = SysCtlClockGet() / BACKLIGHT_PWM_FREQ_HZ;
timerPeriod = backlightLoadValue & 0xFFFF; //lowest 4 bytes
timerPrescaler = backlightLoadValue >> 16;
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
ROM_TimerDisable(TIMER2_BASE, TIMER_B);
ROM_TimerMatchSet(TIMER2_BASE, TIMER_B, 0); // Initially off
ROM_TimerPrescaleMatchSet(TIMER2_BASE, TIMER_B, 0);ROM_GPIOPinConfigure(GPIO_PF5_T2CCP1);
ROM_GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_5);
ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);
ROM_TimerControlLevel(TIMER2_BASE, TIMER_B, TRUE); //Inverse PWM output, enables simpler duty cycle set function
ROM_TimerLoadSet(TIMER2_BASE, TIMER_B, timerPeriod);
ROM_TimerPrescaleSet(TIMER2_BASE, TIMER_B, timerPrescaler);
ROM_TimerEnable(TIMER2_BASE, TIMER_B);
}