This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123AE6PM: PWM signal not going to 0

Part Number: TM4C123AE6PM

Tool/software:

Positive going PWM signal; when I set the Pulse Width to 0, instead of being 0 it stays solid at 100% high.  I've tried various combinations of PWMGenDisable(), PWMOutputState(), and PWMOutputInvert() with no luck.  Any advice (other than adding an AND gate at each PWM output).

Thanks,

Doug

  • Hi Doug,

      I tried the below code and it is generating a 0% duty cycle PWM with the pin always low. 

    int
    main(void)
    {
        //
        // Set the clocking to run directly from the external crystal/oscillator.
        //
        MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_16MHZ);
    
        //
        // Set the PWM clock to the system clock.
        //
        MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    
        //
        // Initialize the UART.
        //
        ConfigureUART();
    
        //
        // Display the setup on the console.
        //
        UARTprintf("PWM ->\n");
        UARTprintf("  Module: PWM0\n");
        UARTprintf("  Pin: PB6\n");
        UARTprintf("  Configured Duty Cycle: 25%%\n");
        UARTprintf("  Inverted Duty Cycle: 75%%\n");
        UARTprintf("  Features: PWM output inversion every 2 seconds.\n\n");
        UARTprintf("Generating PWM on PWM0 (PB6) -> State = ");
    
        //
        // The PWM peripheral must be enabled for use.
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    
        //
        // Enable the GPIO port that is used for the PWM output.
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
        //
        // Configure the PWM function for this pin.
        //
        MAP_GPIOPinConfigure(GPIO_PB6_M0PWM0);
        MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
    
        //
        // Configure PWM0 to count up/down without synchronization.
        //
        MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |
                            PWM_GEN_MODE_NO_SYNC);
    
        //
        // Set the PWM period to 250Hz.  To calculate the appropriate parameter
        // use the following equation: N = (1 / f) * SysClk.  Where N is the
        // function parameter, f is the desired frequency, and SysClk is the
        // system clock frequency.
        //
        MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, (SysCtlClockGet() / 250));
    
        //
        // Set PWM0 to a duty cycle of 0%.
        //
        MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
                             0);
    
        //
        // Enable PWM Out Bit 0 (PB6) output signal.
        //
        MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
    
        //
        // Enable the PWM generator block.
        //
        MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
    
        while (1);
    
    
    }

  • Very good.  The issue was that I configured it to PWM_GEN_MODE_LOCAL_SYNC but when I changed it to PWM_GEN_MODE_NO_SYNC it works.

    Thanks