I am trying to create an example of PWM working on an EKS-LM4F232. I have an LED that is driven off of PG3. When used as a GPIO, I can turn the LED on and off, so I conclude that my circuit is working. I then stop using PG3 as an output pin and set it up to use as a PWM pin. With a scope on PG3, I see nothing happening. There are no examples of PWM for the M4 chip, but I have used examples for M3 chips and from Stellaris DRL pdf as a guide.
I should expect to see PG3 work at a 50% duty cycle for the following code, correct?
I put in a forever loop in order to change the duty cycle via breakpoint and variable modification.
void PWM_Init(void) {
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
GPIOPinConfigure(GPIO_PG3_M1PWM1);
GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_3);
ulPeriod = 4000;
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ulPeriod);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, ulPeriod/2);
PWMOutputState(PWM1_BASE, PWM_OUT_1_BIT, true);
PWMGenEnable(PWM1_BASE, PWM_GEN_0);
while (1) {
int i = ulPeriod;
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, i);
}
}
void main(void)
{
// Enable lazy stacking for interrupt handlers.
FPULazyStackingEnable();
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
PWM_Init();