Example #1
0
void MCInitPwm(uint32_t DutyCycle)
{
	// Clock PWM peripheral at SysClk/PWMDIV
	ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

	// Enable peripherals
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	// Configure pin PD0 as PWM output
	ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1);
	ROM_GPIOPinConfigure(GPIO_PD0_M1PWM0);
	ROM_GPIOPinConfigure(GPIO_PD1_M1PWM1);

	// Calculate PWM clock
	uint32_t PWMClock = SysCtlClockGet() / 64;
	// Value from/to which PWM counter counts (subtract 1 becouse counter counts from 0). This is PWM period
	LoadValue = (PWMClock/PWM_FREQUENCY) - 1;
	// Configure PWM
	ROM_PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
	ROM_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, LoadValue);
	// Set PWM signal width
	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1, (DutyCycle*LoadValue)/DUTY_CYCLE_DIVIDER);
	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, (DutyCycle*LoadValue)/DUTY_CYCLE_DIVIDER);
	// Enable PWM output 0 and 1
	ROM_PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT, true);
	// Enable PWM generator
	ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_0);
}
Example #2
0
// * svm_init *****************************************************************
// * setup pins and PWM hardware to talk to servomotors                       *
// * Assumes system clock already configured                                  *
// ****************************************************************************
void svm_init(void)
{
  ROM_SysCtlPeripheralEnable(SVM_OUTPUT_PORT);            // enable clock to GPIO port
  ROM_SysCtlPeripheralReset(SVM_OUTPUT_PORT);             // reset to clear any previous config
                                                          // configure output pads 
  GPIOPinTypeGPIOOutput(SVM_OUTPUT_PORT_BASE, SVM_OUTPUT_PINS);
  
                                                          // configure PWM
  ROM_SysCtlPeripheralEnable(SVM_PWM_MODULE);             // enable clock to pwm module
  ROM_SysCtlPWMClockSet(SVM_PWM_FPWM_DIV);                // configure clock divider to derive Fpwm from Fsys
                                                          // wrap 16b PWM counter at 1041 for 3kHz pwm output
  ROM_PWMDeadBandDisable(SVM_PWM_BASE, SVM_PWM_GEN);      // allow PWM0, PWM1 to behave independently
  ROM_PWMGenConfigure(SVM_PWM_BASE, SVM_PWM_GEN,          // configure pwm generator
                      PWM_GEN_MODE_DOWN |                 // up/down count for center timed PWM
                      PWM_GEN_MODE_NO_SYNC);              // outputs from generator behave independently
  ROM_PWMGenPeriodSet(SVM_PWM_BASE, SVM_PWM_GEN,          // sets period for generator to appropriate period
                      SVM_PWM_PERIOD_TICKS);
  ROM_PWMPulseWidthSet(SVM_PWM_BASE, SVM_1_PWM, 0);       // set initial pulse widths to 0 for safety
  ROM_PWMPulseWidthSet(SVM_PWM_BASE, SVM_2_PWM, 0);       // set initial pulse widths to 0 for safety
  
  ROM_GPIOPinConfigure(SVM_1_PWM_MUX);                    // select mux for pwm output hbridge 1
  ROM_GPIOPinConfigure(SVM_2_PWM_MUX);                    // select mux for pwm output hbridge 2
  ROM_GPIOPinTypePWM(SVM_OUTPUT_PORT_BASE, SVM_1_PWM_PIN);// do some other step configuring pwm...
  ROM_GPIOPinTypePWM(SVM_OUTPUT_PORT_BASE, SVM_2_PWM_PIN);// ...exact function is unknown
  
  ROM_PWMOutputState(SVM_PWM_BASE, SVM_1_PWM_BIT | SVM_2_PWM_BIT, true);
                                                          // enable outputs from pwm generator to pins
  ROM_PWMGenEnable(SVM_PWM_BASE, SVM_PWM_GEN);            // enable pwm output generator
}
Example #3
0
//*****************************************************************************
//
// Esta tarefa faz o ponteiro do servo se movimentar para a esquerda ou direita.
// O usuario seleciona o lado a partir dos botoes SW1 ou SW2
//
//*****************************************************************************
static void
TarefaServo(void *pvParameters)
{
	// Variaveis para programar PWM (Tipo volateis: compilador nao elimina-as)
	volatile uint32_t ui32Load;
	volatile uint32_t ui32PWMClock;
	volatile uint8_t ui8Adjust;

	ui8Adjust = 83; //83: posicao central pra criar um pulso de 1.5mS do PWM.

    uint8_t i8Message;

    ui32PWMClock = SysCtlClockGet() / 64;	//	divisor 64 roda o clock a 625kHz.
    ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
    PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Load);

    ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);
    ROM_PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
    ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_0);

    while(1)
    {
        if(xQueueReceive(g_FilaServo, &i8Message, 0) == pdPASS)
        {
            if(i8Message == LEFT_BUTTON)
            {
            	//Movimento sendo definido PWM
            	ui8Adjust += 15;
            	if (ui8Adjust > 155) ui8Adjust = 155;

            	//	Ajuste do tamanho do pulso PWM
            	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);

            	xSemaphoreTake(g_pUARTSemaphore, portMAX_DELAY);
            	UARTprintf("Servo moveu-se para a posicao %d.\n\n", ui8Adjust);
            	xSemaphoreGive(g_pUARTSemaphore);
            }

            if(i8Message == RIGHT_BUTTON)
            {
            	//	Movimento sendo definido PWM
            	ui8Adjust -= 15;
            	if (ui8Adjust < 40) ui8Adjust = 40;
            	//	Ajuste do tamanho do pulso PWM
            	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, ui8Adjust * ui32Load / 1000);
                //
                // Proteger o MUTEX do UART
            	xSemaphoreTake(g_pUARTSemaphore, portMAX_DELAY);
            	UARTprintf("Servo moveu-se para a posicao %d.\n\n", ui8Adjust);
            	xSemaphoreGive(g_pUARTSemaphore);
            }
        }

    }
}
Example #4
0
void motors_initialize(void)
{
/*
	ui32PWMClock = SysCtlClockGet() /2;
	ui32Load = (ui32PWMClock / 20000) - 1;
	GPIOPinConfigure(GPIO_PF1_M1PWM5);
	GPIOPinConfigure(GPIO_PE4_M0PWM4);
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_5);
	GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_5);// change values
	PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1,ui32Load);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
	PWMGenEnable(PWM1_BASE, PWM_GEN_1);
	PWMGenEnable(PWM1_BASE, PWM_GEN_2);
	PWMOutputState(PWM1_BASE, PWM_OUT_1_BIT, true);
	PWMOutputState(PWM1_BASE, PWM_OUT_2_BIT, true);
*/


					ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
					ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_2);
					ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
					ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
					ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
					ROM_GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_4);
					ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
					ROM_GPIOPinConfigure(GPIO_PE4_M1PWM2);
					ROM_GPIOPinConfigure(GPIO_PF1_M1PWM5);
					ui32PWMClock = SysCtlClockGet() / 2;
					ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
					PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN);
					PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, ui32Load);
					//ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, ui8Adjust * ui32Load / 1000);
					ROM_PWMOutputState(PWM1_BASE, PWM_OUT_2_BIT, true);
					ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_1);
					PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
					PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
					//ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
					ROM_PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
					ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_2);

}
Example #5
0
void cfg_PWM()
{ 
  ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //Configure clock to 40MHz
  ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_64);  //Configure PWM clock to 625kHz (40.000.000/64)
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); //Enable PWM_0 output
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1); //Enable PWM_1 output
  
  ui32PWMClock = SysCtlClockGet() / 64;  //Configure clock for PWM - 50Hz (ESCs and Servo motor default)
  ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;


  /*********************CONFIG_PWM_1*********************************/
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable PWM_0/0 output
  ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6); //Set PB6 for PWM output
  ROM_GPIOPinConfigure(GPIO_PB6_M0PWM0);  //Configure PB6 as PWM_0/0 output
  PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ui32Load);
  ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,1);  //MÁX=1562 MIN=937 - 55Hz (1.5ms----2.5ms)
  /*********************END_CONFIG_PWM_1*****************************/

  /*********************CONFIG_PWM_2*********************************/
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable PWM_0/1 output
  ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7); //Set PB7 for PWM output
  ROM_GPIOPinConfigure(GPIO_PB7_M0PWM1);  //Configure PB7 as PWM_0/1 output
  PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, ui32Load);
  ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1,1);  //MÁX=1562 MIN=937 - 55Hz (1.5ms----2.5ms)
  /*********************END_CONFIG_PWM_2*****************************/

  /*********************CONFIG_PWM_3*********************************/
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable PWM_0/2 output
  ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4); //Set PB4 for PWM output
  ROM_GPIOPinConfigure(GPIO_PB4_M0PWM2);  //Configure PB7 as PWM_0/2 output
  PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, ui32Load);
  ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,1);  //MÁX=1562 MIN=937 - 55Hz (1.5ms----2.5ms)
  /*********************END_CONFIG_PWM_3*****************************/

  /*********************CONFIG_PWM_4*********************************/
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable PWM_0/3 output
  ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5); //Set PB5 for PWM output
  ROM_GPIOPinConfigure(GPIO_PB5_M0PWM3);  //Configure PB5 as PWM_0/3 output
  PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, ui32Load);
  ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3,1);  //MÁX=1562 MIN=937 - 55Hz (1.5ms----2.5ms)
  /*********************END_CONFIG_PWM_4*****************************/

  /*********************CONFIG_PWM_5*********************************/
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Enable PWM_1/0 output
  ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0); //Set PD0 for PWM output
  ROM_GPIOPinConfigure(GPIO_PD0_M1PWM0);  //Configure PD0 as PWM_1/0 output
  PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ui32Load);
  ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0,ui32Load/2);  //MÁX=1562 MIN=937 - 55Hz (1.5ms----2.5ms)
  /*********************END_CONFIG_PWM_5*****************************/

  /*********************CONFIG_PWM_6*********************************/
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Enable PWM_1/1 output
  ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1); //Set PD1 for PWM output
  ROM_GPIOPinConfigure(GPIO_PD1_M1PWM1);  //Configure PD1 as PWM_1/1 output
  PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, ui32Load);
  ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_1,ui32Load/2);  //MÁX=1562 MIN=937 - 55Hz (1.5ms----2.5ms)
  /*********************END_CONFIG_PWM_6*****************************/

  ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
  ROM_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);
  ROM_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);
  ROM_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true);
  ROM_PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
  ROM_PWMOutputState(PWM1_BASE, PWM_OUT_1_BIT, true);

  ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
  ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);
  ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_2);
  ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_3);
  ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_0);
  ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_1);
}
//*****************************************************************************
//
// This example demonstrates how to setup the PWM block to generate signals.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    unsigned long ulPeriod;

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);
    ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
    // Initialize the display driver.
    //
    Formike128x128x16Init();

    //
    // Turn on the backlight.
    //
    Formike128x128x16BacklightOn();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sFormike128x128x16);

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = 14;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "pwmgen", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 7, 0);

    //
    // Tell the user what is happening.
    //
    GrStringDrawCentered(&g_sContext, "Generating PWM on", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 56, 0);
    GrStringDrawCentered(&g_sContext, "pins PWM0 and PWM1", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 68, 0);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Set GPIO F0 and F1 as PWM pins.  They are used to output the PWM0 and
    // PWM1 signals.
    //
    ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1,
                         GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);

    //
    // Compute the PWM period based on the system clock.
    //
    ulPeriod = ROM_SysCtlClockGet() / 8000;

    //
    // Set the PWM period to 440 (A) Hz.
    //
    ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
                        PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);

    //
    // Set PWM0 to a duty cycle of 50% and PWM1 to a duty cycle of 80%.
    //
    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ((ulPeriod * 8) / 10));
    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ((ulPeriod * 2) / 10));

    //
    // Enable the PWM0 and PWM1 output signals.
    //
    ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);

    //
    // Enable the PWM generator.
    //
    ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);

    //
    // Loop forever while the PWM signals are generated.
    //
    while(1)
    {
    }
}
//*****************************************************************************
//
// This example application demonstrates the use of the different sleep modes
// and different power configuration options.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run from the MOSC with the PLL at 16MHz.
    //
    g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                              SYSCTL_OSC_MAIN |
                                              SYSCTL_USE_PLL |
                                              SYSCTL_CFG_VCO_320), 16000000);


    //
    // Set the clocking for Deep-Sleep.
    // Power down the PIOSC & MOSC to save power and run from the
    // internal 30kHz osc.
    //
    ROM_SysCtlDeepSleepClockConfigSet(1, (SYSCTL_DSLP_OSC_INT30 |
                SYSCTL_DSLP_PIOSC_PD | SYSCTL_DSLP_MOSC_PD));

    //
    // Initialize the UART and write the banner.
    // Indicate we are currently in Run Mode.
    //
    ConfigureUART();
    UARTprintf("\033[2J\033[H");
    UARTprintf("Sleep Modes example\n\n");
    UARTprintf("Mode:\t\tClock Source:\tLED Toggle Source:");
    UARTprintf("\nRun\t\tMOSC with PLL\tTimer");

    //
    // Initialize the buttons driver.
    //
    ButtonsInit();

    //
    // Enable the interrupt for the button.
    //
    ROM_GPIOIntEnable(GPIO_PORTJ_AHB_BASE, GPIO_INT_PIN_0);

    //
    // Enable the GPIO ports that are used for the on-board LEDs.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Set pad config.
    //
    MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0,
                          GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    //
    // Set direction.
    //
    ROM_GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN);

    //
    // Enable the interrupt for the button.
    //
    ROM_GPIOIntEnable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0);

    //
    // Enable interrupt to NVIC.
    //
    ROM_IntEnable(INT_GPIOJ);

    //
    // Enable the GPIO ports that are used for the on-board LEDs.
    //
    ROM_SysCtlPeripheralEnable(RUN_GPIO_SYSCTL);
    ROM_SysCtlPeripheralEnable(SLEEP_GPIO_SYSCTL);
    ROM_SysCtlPeripheralEnable(DSLEEP_GPIO_SYSCTL);
    ROM_SysCtlPeripheralEnable(TOGGLE_GPIO_SYSCTL);

    //
    // Enable the GPIO pins for the LED.
    //
    ROM_GPIOPinTypeGPIOOutput(RUN_GPIO_BASE, RUN_GPIO_PIN);
    ROM_GPIOPinTypeGPIOOutput(SLEEP_GPIO_BASE, SLEEP_GPIO_PIN);
    ROM_GPIOPinTypeGPIOOutput(DSLEEP_GPIO_BASE, DSLEEP_GPIO_PIN);
    ROM_GPIOPinTypeGPIOOutput(TOGGLE_GPIO_BASE, TOGGLE_GPIO_PIN);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Configure the 32-bit periodic timer.
    //
    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock);

    //
    // Setup the interrupts for the timer timeout.
    //
    ROM_IntEnable(INT_TIMER0A);
    ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    //
    // Configure the PWM0 to count down without synchronization.
    // This will be used in Deep-Sleep.
    //
    ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
                        PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

    //
    // Enable the PWM0 output signal.
    //
    ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);

    //
    // Set up the period to match the timer.
    //
    ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 65000);

    //
    // Configure the PWM for a 50% duty cycle.
    //
    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 65000 >> 1);

    //
    // Enable the timer.
    //
    ROM_TimerEnable(TIMER0_BASE, TIMER_A);

    //
    // Enable the Timer in Sleep Mode.
    //
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);

    //
    // Enable the PWM in Deep-Sleep Mode.
    //
    ROM_SysCtlPeripheralDeepSleepEnable(SYSCTL_PERIPH_PWM0);

    //
    // Enable the Button Port in Sleep & Deep-Sleep Mode.
    //
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOJ);
    ROM_SysCtlPeripheralDeepSleepEnable(SYSCTL_PERIPH_GPIOJ);

    //
    // Enable the LED Ports in Sleep & Deep-Sleep Mode.
    //
    ROM_SysCtlPeripheralSleepEnable(SLEEP_GPIO_SYSCTL);
    ROM_SysCtlPeripheralDeepSleepEnable(DSLEEP_GPIO_SYSCTL);
    ROM_SysCtlPeripheralSleepEnable(TOGGLE_GPIO_SYSCTL);
    ROM_SysCtlPeripheralDeepSleepEnable(TOGGLE_GPIO_SYSCTL);

    //
    // Enable Auto Clock Gating Control.
    //
    ROM_SysCtlPeripheralClockGating(true);

    //
    // Set LDO to 1.15V in Sleep.
    // Set LDO to 1.10V in Deep-Sleep.
    //
    SysCtlLDOSleepSet(SYSCTL_LDO_1_15V);
    SysCtlLDODeepSleepSet(SYSCTL_LDO_1_10V);

    //
    // Set SRAM to Standby when in Sleep Mode.
    // Set Flash & SRAM to Low Power in Deep-Sleep Mode.
    //
    SysCtlSleepPowerSet(SYSCTL_SRAM_STANDBY);
    SysCtlDeepSleepPowerSet(SYSCTL_FLASH_LOW_POWER | SYSCTL_SRAM_LOW_POWER);

    //
    // Call to set initial LED power state.
    //
    PowerLEDsSet();

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Handle going into the different sleep modes outside of
        // interrupt context.
        //
        if (g_ui32SleepMode == 1)
        {
            //
            // Go into Sleep Mode.
            //
            ROM_SysCtlSleep();
        }
        else if (g_ui32SleepMode == 2)
        {
            //
            // Go into Deep-Sleep Mode.
            //
            ROM_SysCtlDeepSleep();
        }
    }
}
//*****************************************************************************
//
// This example demonstrates how to setup the PWM block to generate signals.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulPeriod;

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
    // Initialize the UART.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);

    //
    // Tell the user what is happening.
    //
    UARTprintf("\033[2JGenerating PWM on PD0 and PD1\n");

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Set GPIO D0 and D1 as PWM pins.  They are used to output the PWM0 and
    // PWM1 signals.
    //
    GPIOPinConfigure(GPIO_PD0_PWM0);
    GPIOPinConfigure(GPIO_PD1_PWM1);
    ROM_GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Compute the PWM period based on the system clock.
    //
    ulPeriod = ROM_SysCtlClockGet() / 440;

    //
    // Set the PWM period to 440 (A) Hz.
    //
    ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
                        PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);

    //
    // Set PWM0 to a duty cycle of 25% and PWM1 to a duty cycle of 75%.
    //
    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ulPeriod / 4);
    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, (ulPeriod * 3) / 4);

    //
    // Enable the PWM0 and PWM1 output signals.
    //
    ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);

    //
    // Enable the PWM generator.
    //
    ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);

    //
    // Loop forever while the PWM signals are generated.
    //
    while(1)
    {
    }
}