#include <stdint.h>
#include <stdbool.h>
#include "driverlib/rom.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
void timerVersion(){
uint32_t ulPeriod, dutyCycle1;
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable port F
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // Enable Timer 1
GPIOPinConfigure(GPIO_PF3_T1CCP1); // Configure pin PF3 as output of Timer 1_B
GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_3); // Enable pin PF3 as output of timer addressed to it
ulPeriod = SysCtlClockGet();
dutyCycle1 = (unsigned long)(ulPeriod-1)*0.50;
TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR|TIMER_CFG_B_PWM)); // Configure Timer 1 as two 16 but timers with both functioning as PWM
TimerControlLevel(TIMER1_BASE, TIMER_BOTH, 0); // Timer 1 is trigger low
TimerLoadSet(TIMER1_BASE, TIMER_B, ulPeriod-1); // Timer 1 Load set
TimerMatchSet(TIMER1_BASE, TIMER_B, dutyCycle1); // Timer 1 Match set
TimerEnable(TIMER1_BASE, TIMER_BOTH);
}
void pwmVersion(){
uint32_t ulPeriod = 0;
//Configure PWM Clock to match system
ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
// Enable the peripherals used by this program.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //The Tiva Launchpad has two modules (0 and 1). Module 1 covers the LED pins
ulPeriod = ROM_SysCtlClockGet(); //PWM frequency 1Hz
//Configure PF3 Pins as PWM
ROM_GPIOPinConfigure(GPIO_PF3_M1PWM7);
ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);
//Configure PWM Options
//PWM_GEN_2 Covers M1PWM4 and M1PWM5
//PWM_GEN_3 Covers M1PWM6 and M1PWM7 See page 207 4/11/13 DriverLib doc
ROM_PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
//Set the Period (expressed in clock ticks)
ROM_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ulPeriod);
//Set PWM duty-50% (Period /2)
ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ulPeriod/2);
// Enable the PWM generator
ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_3);
// Turn on the Output pins
ROM_PWMOutputState(PWM1_BASE, PWM_OUT_7_BIT, true);
}
int main(void)
{
//
// Set the clocking to run at 50 MHz from the PLL.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
timerVersion(); //16, 50 MHz-> illuminating LED
//pwmVersion(); //50 MHz-> "black" LED
while(1)
{
}
}