Part Number: EK-TM4C123GXL
Hello everyone.
I started working with PWM module in TIVA TM4C123G, I want the period to be same as the System clock ,and then i want to vary the duty cycle to be 50% ,30%, 70% etc.The PF1 pin i have connected with A DSO to check the width variation and same is refelected on onboard RED LED with brightness variations.I tried to do for 50% and its working fine but when i try for some other duty cycle,it is not working as expected. Kindly check the code below.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_gpio.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/adc.h"
Int main(void)
{
unsigned long ulPeriod;
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
ulPeriod = SysCtlClockGet();
GPIOPinConfigure(GPIO_PF1_M1PWM5);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ulPeriod );
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5,ulPeriod/2);// when i divide the uIPeriod by any other value,its not giving the results as expected.
PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT , true);
while(1)
{
}
}
Thank You