int xMotorDriverInit()
{

	SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R10 | SYSCTL_RCGCGPIO_R5;

	vSemaphoreCreateBinary(changeSpeed);

	ROM_GPIOPinTypePWM(MOTOR_L_PWM_PORT, MOTOR_L_PWM_PIN);
	ROM_GPIOPinConfigure(GPIO_PF2_M0PWM2);

	ROM_GPIOPinTypePWM(MOTOR_R_PWM_PORT, MOTOR_R_PWM_PIN);
	ROM_GPIOPinConfigure(GPIO_PF3_M0PWM3);

	GPIO_PORTL_DIR_R |= 0xF;
	GPIO_PORTL_DEN_R |= 0xF;

	PWM0_1_GENA_R = 0x8C;
	PWM0_1_GENB_R = 0x8C;
	ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_GEN_NO_SYNC);
	ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 256);
	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 25);
	ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 25);

	ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);

	MOTOR_L_DIR1_PORT &= ~MOTOR_L_DIR1_PIN;
	MOTOR_L_DIR2_PORT |= MOTOR_L_DIR2_PIN;
	MOTOR_R_DIR1_PORT &= ~MOTOR_R_DIR1_PIN;
	MOTOR_R_DIR2_PORT |= MOTOR_R_DIR2_PIN;

	PWM0_1_CTL_R |= 0x5;
	PWM0_ENABLE_R |= 0x4 | 0x8;

	return 0;
}
Ejemplo n.º 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
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 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);

}
Ejemplo n.º 5
0
void setup(){

	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
	ROM_GPIOPinConfigure(GPIO_PF1_M1PWM5);
	ROM_GPIOPinConfigure(GPIO_PF2_M1PWM6);
	ROM_GPIOPinConfigure(GPIO_PF3_M1PWM7);

	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;

	GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN);
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);



}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
0
//*****************************************************************************
//
// 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)
    {
    }
}
Ejemplo n.º 8
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();
}
Ejemplo n.º 9
0
//*****************************************************************************
//
// 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)
    {
    }
}