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.

TM4C129XNCZAD: Program to toggle PWM pin does not work as expected

Part Number: TM4C129XNCZAD

Dear All,

I am trying to write a program that generate a pulse signal on a GPIO using PWM pin (PK5).

Following is what I wrote. However, when I checked the the Pin, i did not get any signal.

Is there anything I may have messed up?

Kind regards,

Jean

// A Function to toggle a given GPIO pin
//
# include <stdint.h>
# include <stdio.h>
# include <stdbool.h>
# include "inc/hw_memmap.h"
# include "inc/hw_types.h"
# include "inc/hw_ints.h"
# include "driverlib/sysctl.h"
# include "driverlib/gpio.h"
# include "driverlib/interrupt.h"
# include "driverlib/pin_map.h"
# include "driverlib/rom.h"
# include "driverlib/rom_map.h"
# include "driverlib/pwm.h"
#include "driverlib/flash.h"
#include "utils/swupdate.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"


uint32_t g_ui32SysClock;
/**
* main.c
*/
int main(void)
{
// Set the frequency of Microcontroller

g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
// Enable the peripheral port f (activate port F)
// SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOR);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOS);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOT);

// Enable the peripheral port K (activate port K)
// SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);

// Enable the PWM0 peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

// initialize the pin PK5 as an output pin
GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_5);
//
// set the pull up functionality for pin PF5
GPIOPadConfigSet(GPIO_PORTK_BASE, GPIO_PIN_5, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);

//write the output on pin PK5
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_5, GPIO_PIN_5);

// set the default output of PK5 to zero
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_5, 0);

//set pin PK5 function type as PWM
//
GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_5);
//
// Configure pin PK5 as an PWM7 pin signal
GPIOPinConfigure(GPIO_PK5_M0PWM7);
//
//
// Wait for the PWM0 module to be ready.
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
{
}
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

// Configure the PWM generator for count down mode with immediate updates
// to the parameters.
//
PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
//
// Set the period. For a 100 KHz frequency, the period = 1/100,000, or 10
// microseconds. For a 120 MHz clock, this translates to 1200 clock ticks.
// Use this value to set the period.
//
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, 1200);
//
// Set the pulse width of PWM0 for a 25% duty cycle.
//
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_7, 300);

// Start the timers in generator 0.
//
PWMGenEnable(PWM0_BASE, PWM_GEN_3);

// Enable the outputs.
//
PWMOutputState(PWM0_BASE, (PWM_OUT_7_BIT), true);

return 0;
}