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.

PWM Output Question , TM4C



Hello 

Why does not the PWM output ?

thanks

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/pwm.h"


//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************

#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
 
void
ConfigureUART(void)
{

    // Enable the GPIO Peripheral used by the UART.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
 

    // Enable UART0
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
 

    // Configure GPIO Pins for UART mode.
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
 
    // Use the internal 16MHz oscillator as the UART clock source.
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    // Initialize the UART for console I/O.
    UARTStdioConfig(0, 115200, 16000000);
}
 


void
PWM0IntHandler(void)
{   
    // Clear the pwm0 interrupt.
    
    PWMGenIntClear(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_ZERO);

}

int
main(void)
{
    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();
 
    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
 

    // Initialize the UART and write status.
     ConfigureUART();

		// PWM Clock set 
			ROM_SysCtlPWMClockSet(SYSCTL_PERIPH_PWM0);
		
		//  PWM0 Peripheral Enable
			ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
		
    //PWM Corresponding GPIO Port Enable
			ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
 
    //GPIO Anternate Function.  
			GPIOPinConfigure(GPIO_PH0_M0PWM0);
		
		// PWM Config Set
				PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
		
			// Set the period
				PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 400);
			
			//Set the pulse width of PWM0 for a 25% duty cycle.
				PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 100);
			
			// Set the pulse width of PWM1 for a 75% duty cycle.1
				PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 300);
			
			// Start the timers in generator 0.
				PWMGenEnable(PWM0_BASE, PWM_GEN_0);
			
			// Enable the outputs.
				PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);
  
				UARTprintf(" PWM Out  , GPIO PH0(Gen0)_ PH1(Gen1)\n");
 

				ROM_IntMasterEnable();
				ROM_PWMIntEnable(PWM0_BASE,PWM_INT_GEN_0 );

   
    //
    // Loop forever while the timers run.
    //
    while(1)
    {
    }
}

  • Jame shin said:
    Why does not the PWM output ?

    Might the "absence" of (necessary) PWM, Set-Up/Configure code (beyond your:  "GPIOPinConfigure(GPIO_PH0_M0PWM0)"

    somewhat explain?   For instance - is not "GPIOPinType()" also required?    (targeted at your (incompletely set-up) "GPIO_PH0_M0PWM0.")

    Further down your "code chain" you seek PWM output from "PWM_OUT_1" - which has "never/ever" been "Set-Up/Configured" - at all!

    There are quite good & helpful PWM code examples w/in the driver library. (follow Peripherals > Examples > PWM) 

    Only after your full/complete/proper set-up of (normal) GPIO pins into their alternate (PWM function - in your case) will PWM output reveal.

  • Hello cb1_moblie

    It works well. Thank you.


    [Add below ]

    // Configuration Pin for use by the PWM peripheral
    GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_0);