Part Number: TM4C129ENCPDT
Other Parts Discussed in Thread: EK-TM4C129EXL,
Hello all,
I'm using the EK-TM4C129EXL (rev A) launch pad board.
I'm using IAR and I started this project with an example project from IAR called "project". This is main() starter that setups and blinks a GPIO pin. That all worked ok. Then I started setting up a PWM generator block. It started out working ok, but later, as I tweaked up the settings and I used PWMClockSet (indented for non-TM4C123x) , and it started throwing exceptions. If I remark out that line, the code sometimes works, however it still seems to throw exception sometimes and other times not. Out of desperation I tried SysCtlPWMClockSet (intended for TM4C123x), and that worked without throwing an exception - the first time. Later that line did seem to throw an exception.
I had a similar problem with CSS some months ago, but I don't really remember the particulars.
Bellow is my code. Could this problem be related to driverlib? Maybe an out of date rev?
Many thanks!! George
#define PART_TM4C129ENCPDT
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Simple Project (project)</h1>
//!
//! A very simple example that can be used as a starting point for more complex
//! projects. Most notably, this project is fully TI BSD licensed, so any and
//! all of the code (including the startup code) can be used as allowed by that
//! license.
//!
//! The provided code simply toggles a GPIO using the Tiva Peripheral Driver
//! Library.
//
//*****************************************************************************
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
int main(void)
{
//
// Set system clock frequency to 120MHz
//
SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000);
//
// Enable the GPIO module.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_GPION));
//
// Configure PN1 as an output.
//
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);
PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
// SysCtlPWMClockSet(SYSCTL_PWMDIV_2);
//
// Enable the PWM module.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0));
//
// Enable the GPIO module port F for the PWM.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF));
//
// Configure PF2 and PF3 as outputs for the PWM.
//
// ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);
ROM_GPIOPinConfigure(GPIO_PF2_M0PWM2);
ROM_GPIOPinConfigure(GPIO_PF3_M0PWM3);
ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);
//
// Configure the PWM generator for count down mode with immediate updates to the parameters.
//
ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
//
// Set the period.
//
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 200);
//
// Set the pulse width of PWM2.
//
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 0);
//
// Set the pulse width of PWM3.
//
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 100);
//
// Enable the outputs.
//
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true);
//
// Start the timers in generator 1.
//
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);
int period = 0;
//
// Loop forever.
//
while(1)
{
//
// Set the GPIO high.
//
ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1);
//
// Delay for a while.
//
ROM_SysCtlDelay(1000000);
//
// Set the GPIO low.
//
ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0);
//
// Delay for a while.
//
ROM_SysCtlDelay(1000000);
//
// Set the pulse width of PWM2.
//
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, period);
if (period == 200)
period = 0;
else
++period;
}
}
