Other Parts Discussed in Thread: TM4C123GH6PM
Hi, I have the Stellaris launchpad , with the LM4F120 and I'm trying to use the PWM generator to vary the brightness of the LED included, controlled by an ADC input. The problem I have is that when I start the debugger and get to the PWM setup functions an error occurs, as if I had not used the functions to enable it. At first I had the same error with the configuration of the GPIO, until I realized that I lacked the habilitation. In this case I can not find what may be the failure of the code. This is the first part of the program. I really appreciate your time and help, and sorry if my English is not very good.
#define PART_LM4F120H5QR
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/cpu.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "driverlib/uart.h"
#include <math.h>
#ifdef DEBUG
void__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
int main(void) {
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
ADCSequenceDisable(ADC0_BASE, 0);
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceEnable(ADC0_BASE, 0);
GPIOPinConfigure(GPIO_PF1_T0CCP1);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
PWMGenDisable(PWM1_BASE, PWM_GEN_1); //This line is where the error occurs
PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_GEN_NO_SYNC);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, 1000);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, 1);
PWMGenEnable(PWM1_BASE, PWM_GEN_1);
PWMOutputState(PWM1_BASE, PWM_OUT_4, 0);