Other Parts Discussed in Thread: EK-TM4C123GXL
Title says it all. I'm using the EK-TM4C123GXL launchpad.
#include <stdint.h> #include <stdbool.h> #include <inc/hw_memmap.h> #include <inc/hw_gpio.h> #include <driverlib/pwm.h> #include <driverlib/sysctl.h> #include <driverlib/gpio.h> #include <driverlib/pin_map.h> int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB)); GPIOPinConfigure(GPIO_PB4_M0PWM2); GPIOPinConfigure(GPIO_PB7_M0PWM1); GPIOPinConfigure(GPIO_PB6_M0PWM0); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6); GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0)); PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); //0xff =256; 256/16MHz = 16us //0xff =256; 256/16MHz = 16us PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 0xff); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 0xff); //blue PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 0); //green PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 1); //red PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 0x80); PWMGenEnable(PWM0_BASE, PWM_GEN_0); PWMGenEnable(PWM0_BASE, PWM_GEN_1); PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT), true); while(1); return 0; }
PWM_OUT_1 gets a duty cycle of 1/256 and I see a tiny pulse on the scope. PWM_OUT_0's duty cycle is set to 0, but it is high (100% duty). Setting a 100% duty cycle gets the expected results.
This issue has been found by at least two others:
The second one is marked "answered", but I don't understand af36's workaround.