Пример #1
0
void pwm_duty(int duty){



	volatile uint32_t ui32Load;
	volatile uint32_t ui32PWMClock;
	volatile uint32_t divisor;


	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;

	divisor = duty*ui32Load/100;

	ROM_PWMGenDisable(PWM1_BASE, PWM_GEN_0);
	ROM_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, divisor);
	ROM_PWMGenEnable(PWM1_BASE, PWM_GEN_0);

}
Пример #2
0
//*****************************************************************************
//
// The interrupt handler for the button interrupt.
//
//*****************************************************************************
void
ButtonIntHandler(void)
{
    //
    // Delay here on button push for simple debouncing.
    //
    SysCtlDelay(g_ui32SysClock / 10);

    //
    // Clear the timer interrupt.
    //
    ROM_GPIOIntClear(GPIO_PORTJ_AHB_BASE, GPIO_INT_PIN_0);

    //
    // Increment Mode.
    //
    g_ui32SleepMode = (g_ui32SleepMode + 1) % 3;

    switch (g_ui32SleepMode)
    {
        //
        // Enter Run Mode.
        //
        case 0:

            //
            // Disable the PWM.
            //
            ROM_PWMGenDisable(PWM0_BASE, PWM_GEN_0);

            //
            // Configure Toggle LED as a GPIO output.
            //
            ROM_GPIOPinTypeGPIOOutput(TOGGLE_GPIO_BASE, TOGGLE_GPIO_PIN);

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

            //
            // Print mode over the UART.
            //
            UARTprintf("\033[100D");
            UARTprintf("\033[K");
            UARTprintf("Run\t\tMOSC with PLL\tTimer");
            SysCtlDelay(10000);
            break;

            //
            // Enter Sleep Mode.
            //
        case 1:

            //
            // Print mode over the UART.
            // Delay to let the UART finish before going to Sleep.
            //
            UARTprintf("\033[100D");
            UARTprintf("\033[K");
            UARTprintf("Sleep\t\tPIOSC\t\tTimer");
            SysCtlDelay(10000);

            //
            // Switch clock to PIOSC and power down the MOSC before going into 
            // Sleep.
            //
            g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_OSC_INT |
                                                      SYSCTL_USE_OSC |
                                                      SYSCTL_MAIN_OSC_DIS), 
                                                      16000000);

            break;

            //
            // Enter Deep-Sleep Mode.
            //
        case 2:

            //
            // Switch back to the MOSC + PLL.
            //
            g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                      SYSCTL_OSC_MAIN |
                                                      SYSCTL_USE_PLL |
                                                      SYSCTL_CFG_VCO_320), 
                                                      16000000);

            //
            // Disable the timer.
            //
            ROM_TimerDisable(TIMER0_BASE, TIMER_A);

            //
            // Configure the toggle pin as a PWM pin.
            //
            ROM_GPIOPinConfigure(GPIO_PF0_M0PWM0);
            ROM_GPIOPinTypePWM(TOGGLE_GPIO_BASE, TOGGLE_GPIO_PIN);

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

            //
            // Print mode over the UART.
            // Delay to let the UART finish before going to Sleep.
            //
            UARTprintf("\033[100D");
            UARTprintf("\033[K");
            UARTprintf("Deep-Sleep\tLFIOSC\t\tPWM");
            SysCtlDelay(10000);
            break;

        default:
            break;
    }

    //
    // Set LEDs to show what mode we are in.
    //
    PowerLEDsSet();
}