Other Parts Discussed in Thread: TM4C123GH6PZ
I am using a TM4C123GH6PZ using CCS 5.1 and TivaWare 1.0. I have ported PWM code that was working on the LM4F EKS and is not working our new target hardware that arrived this week. The HW is working nicely on many levels. I have an example main loop that was derived from LM3F example code and example code in the TivaWare user guide. The #define lets me put out a wave form on H0,1,2 using simple GPIO writes to prove that the HW works. The outputs drive test LEDs. The HW works. Would any sharp eye pick up what is in the PWM code that is not working? The LEDs are off at all times. With the USE_FAUX_PWM set to 1, all LEDs flash.
Tiva™ TM4C123GH6PZ
#define USE_FAUX_PWM 0
{
unsigned long ulPeriod;
unsigned long fauxPWMcounter = 0;
unsigned long onOff = 0;
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
| SYSCTL_XTAL_20MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
#if USE_FAUX_PWM
GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
#else
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_2);
GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ulPeriod = SysCtlClockGet() / 500;
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ulPeriod / 4);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ulPeriod * 3 / 4);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
#endif
/// ***************************************************************
while (1) {
fauxPWMcounter++;
if (fauxPWMcounter>=100000) {
fauxPWMcounter = 0;
if (onOff) {
#if USE_FAUX_PWM
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, 0);
#else
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_2, 0);
#endif
onOff = 0;
}
else {
#if USE_FAUX_PWM
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
#else
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_2, GPIO_PIN_2);
#endif
onOff = 1;
}
}
}
}