Created
December 21, 2013 12:25
-
-
Save deanrock/8068750 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "inc/hw_gpio.h" | |
#include "inc/hw_memmap.h" | |
#include "inc/hw_sysctl.h" | |
#include "inc/hw_types.h" | |
#include "driverlib/gpio.h" | |
#include "driverlib/rom.h" | |
#include "driverlib/sysctl.h" | |
#include "inc/hw_types.h" | |
#include "inc/hw_memmap.h" | |
#include "driverlib/sysctl.h" | |
#include "driverlib/gpio.h" | |
#include "driverlib/timer.h" | |
#include "driverlib/pin_map.h" | |
int main(void) { | |
unsigned long ulPeriod, dutyCycle; | |
// 40 MHz system clock | |
ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL| | |
SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); | |
ulPeriod = 1000; | |
dutyCycle = 250; | |
// Turn off LEDs | |
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); | |
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); | |
ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); | |
// Configure PB6 as T0CCP0 | |
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); | |
ROM_GPIOPinConfigure(GPIO_PB6_T0CCP0); | |
ROM_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6); | |
// Configure timer | |
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); | |
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); | |
ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1); | |
ROM_TimerMatchSet(TIMER0_BASE, TIMER_A, dutyCycle); // PWM | |
ROM_TimerEnable(TIMER0_BASE, TIMER_A); | |
while(1) { // The following code varies the duty cycle over time | |
ROM_TimerMatchSet(TIMER0_BASE, TIMER_A, dutyCycle++); | |
if(dutyCycle >= ulPeriod - 1) | |
dutyCycle = 0; | |
ROM_SysCtlDelay(50000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment