Esempio n. 1
1
int main(void)
{
	volatile uint32_t ui32Load;
	volatile uint32_t ui32PWMClock;
	volatile uint8_t ui8Adjust;
	ui8Adjust = 254;

	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);

	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
	GPIOPinConfigure(GPIO_PF1_M1PWM5);

	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);

	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_2);

	while(1)
	{

		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00)
		{
			ui8Adjust--;
			if (ui8Adjust < 10)
			{
				ui8Adjust = 10;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
		}

		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00)
		{
			ui8Adjust++;
			if (ui8Adjust > 254)
			{
				ui8Adjust = 254;
			}
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust * ui32Load / 1000);
		}

		SysCtlDelay(100000);
	}

}
Esempio n. 2
0
void PWM_Setup()
{
	SysCtlPWMClockSet(PWM_SYSCLK_DIV_64);
	//
	// Configure the PWM generator for count down mode with immediate updates
	// to the parameters.
	//
	PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	// Set the period. For a 50 KHz frequency, the period = 1/50,000, or 20
	// microseconds. For a 20 MHz clock, this translates to 400 clock ticks.
	// Use this value to set the period.
	//
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, MAXPERIOD);
	//
	// Set the pulse width of PWM1 for a 75% duty cycle.
	//
	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, 0);
	
	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, 0);
	// 50MHZ is to fast
	PWMClockSet(PWM1_BASE,PWM_SYSCLK_DIV_64);
	//
	// Start the timers in generator 3.
	//
	PWMGenEnable(PWM1_BASE, PWM_GEN_3);
	//
	// Enable the outputs.
	//
	PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT , true);

}
Esempio n. 3
0
//PWM³õʼ»¯
void initPWM()
{
    //³õʼ»¯ÍâÉè¶Ë¿Ú
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);  
    
    //ÉèÖÃPWMÐźÅʱÖÓ
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    
    //ÉèÖÃPG2ºÍPD1ΪPWMÊä³ö
    GPIOPinConfigure(GPIO_PG2_PWM0);
    GPIOPinConfigure(GPIO_PD1_PWM1);
    GPIOPinTypePWM(GPIO_PORTG_BASE, PWM_L);
    GPIOPinTypePWM(GPIO_PORTD_BASE, PWM_R);
    
    //ÅäÖÃPWM·¢ÉúÄ£¿é1
    PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC);
    //PWMGenConfigure(PWM_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN|PWM_GEN_MODE_NO_SYNC);

    PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 1000);
    //PWMGenPeriodSet(PWM_BASE, PWM_GEN_3, 800);
    
   // PWMPulseWidthSet(PWM_BASE, PWM_OUT_0,700);//×ó
   // PWMPulseWidthSet(PWM_BASE, PWM_OUT_1,500);//ÓÒ
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_0,banlanceL);//×ó
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_1,banlanceR);//ÓÒ
    //ʹÄÜPWM2Êä³ö
    PWMOutputState(PWM_BASE,PWM_OUT_0_BIT,true);
    //ʹÄÜPWM3Êä³ö
    PWMOutputState(PWM_BASE,PWM_OUT_1_BIT,true);
    
    PWMGenEnable(PWM_BASE, PWM_GEN_0);
}
Esempio n. 4
0
//--------------------------------
void pwm_stepper::Initialize() {
	g_pTheStepper = this;
	SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOPinConfigure(GPIO_PA6_M1PWM2);
	GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6);
	PWMGenConfigure(Base, Generator, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
	// Set the PWM period to 250Hz.  To calculate the appropriate parameter
	// use the following equation: N = (1 / f) * SysClk.  Where N is the
	// function parameter, f is the desired frequency, and SysClk is the
	// system clock frequency.
	// In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles.  Note that
	// the maximum period you can set is 2^16.
	PWMGenPeriodSet(Base, Generator, Default_StartSpeed);
	PWMPulseWidthSet(Base, PWM_OUT_2, 64);
	// Allow PWM1 generated interrupts.  This configuration is done to
	// differentiate fault interrupts from other PWM1 related interrupts.
	PWMIntEnable(Base, PWM_INT_GEN_1);
	// Enable the PWM1 LOAD interrupt on PWM1.
	PWMGenIntTrigEnable(Base, Generator, PWM_INT_CNT_LOAD);
	// Enable the PWM1 interrupts on the processor (NVIC).
	IntEnable(INT_PWM1_1);
	// Enable the PWM1 output signal (PA6).
//	PWMOutputInvert(Base, PWM_OUT_2_BIT, true);
	PWMOutputState(Base, PWM_OUT_2_BIT, true);
}
Esempio n. 5
0
void motors_init(void) {

	int i;
	uint8_t pin_mask;
	uint32_t motor_per;

	// Set Pins to output/PWM in GPIO
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	GPIOPinConfigure(GPIO_PF2_M1PWM6);
	GPIOPinConfigure(GPIO_PF3_M1PWM7);
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);

	// Configure the pin for standby control
	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);

	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
	// Configure the PWM for each pin:
	// Turn on the generators and set the PW to 0
	// The output is still OFF. Turn on with set_motor_pwm_state
	for (i = 0; i < NUM_MOTORS; i++) {
		PWMGenConfigure(motors[i].pwm_base_module, motors[i].pwm_generator, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
		motor_per = calc_cycles(MOTOR_PERIOD);
		PWMGenPeriodSet(motors[i].pwm_base_module, motors[i].pwm_generator, motor_per);
		PWMPulseWidthSet(motors[i].pwm_base_module, motors[i].pwm_pin, 0);
		PWMGenEnable(motors[i].pwm_base_module, motors[i].pwm_generator);
		pin_mask = 1 << (0x0000000F & motors[i].pwm_pin);
		PWMOutputState(motors[i].pwm_base_module, pin_mask, 0);
	}

}
//******************************************************************
// Initialise the PWM generator (PWM1 & PWM4)
//******************************************************************
void
initPWMchan (void)
{
	unsigned long period;

    SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM);
    //
    // Compute the PWM period based on the system clock.
    //
        SysCtlPWMClockSet (PWM_DIV_CODE);

    PWMGenConfigure (PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    PWMGenConfigure (PWM_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    period = SysCtlClockGet () / PWM_DIVIDER / MOTOR_RATE_HZ;
    PWMGenPeriodSet (PWM_BASE, PWM_GEN_0, period);
    PWMGenPeriodSet (PWM_BASE, PWM_GEN_2, period);
    PWMPulseWidthSet (PWM_BASE, PWM_OUT_1, period * main_duty / 100);
    PWMPulseWidthSet (PWM_BASE, PWM_OUT_4, period * tail_duty / 100);
    //
    // Enable the PWM output signal.
    //
    PWMOutputState (PWM_BASE, PWM_OUT_1_BIT, false);
    PWMOutputState (PWM_BASE, PWM_OUT_4_BIT, false);
    //
    // Enable the PWM generator.
    //
    PWMGenEnable (PWM_BASE, PWM_GEN_0);
    PWMGenEnable (PWM_BASE, PWM_GEN_2);
}
Esempio n. 7
0
void Init_PWM() {
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
	SysCtlPWMClockSet(SYSCTL_PWMDIV_2);
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
	PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 400);
	PWMGenEnable(PWM_BASE, PWM_GEN_0);
	PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, true);
}
void pwmInit(void) {
	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
	GPIOPinConfigure(GPIO_PD1_M1PWM1);
	PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_1_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_0);
}
Esempio n. 9
0
int main(void)
{
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    if (REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    // Set the clocking to run at 50MHz from the PLL.
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    // Initialise the OLED display.
    RIT128x96x4Init(1000000);

    // Initialise the required peripherals.
    initStatusLight();
    initialisePortB();
    initialiseButtons();
    initialisePWM();
    initialiseADC();
    initialiseUART();

	/* Create the queue used by the OLED task.  Messages for display on the OLED
	are received via this queue. */
	xSendQueue = xQueueCreate( mainSEND_QUEUE_SIZE, sizeof( xQueueMessage ) );
	vCreateQueuesAndSemaphore();

    /*-------------------------------------------
         Create tasks and start scheduler
    -------------------------------------------*/

    /* Create the required tasks */
    xTaskCreate( vSendTask, "Send Task", 240, NULL, 1, NULL);
    xTaskCreate( vLedBlink, "LED Blink", configMINIMAL_STACK_SIZE, NULL, 4, NULL );
    vStartControlTasks( xSendQueue );

	// Enable interrupts to the processor.
	IntMasterEnable();

    /* Start the scheduler so our tasks start executing. */
    vTaskStartScheduler();

    /* If all is well we will never reach here as the scheduler will now be
    running.  If we do reach here then it is likely that there was insufficient
    heap available for the idle task to be created. */
    while (1)
    {
    }
}
/*
 *  ======== PWMTiva_setPrescalar ========
 *  Set PWM prescalar for a given peripheral.
 *
 *  @param  pwmBase    PWM period in timer ticks
 *  @param  presRegVal prescalar register value
 */
static inline void PWMTiva_setPrescalar(uint32_t  pwmBase, uint32_t presRegVal)
{
    /* Set PWM prescalar - device dependent */
    if ((HWREG(SYSCTL_DID0) & SYSCTL_DID0_CLASS_M) ==
        SYSCTL_DID0_CLASS_TM4C129) {
        /* TM4C129 device */
        PWMClockSet(pwmBase, presRegVal);
    }
    else {
        /* TM4C123 device */
        SysCtlPWMClockSet(presRegVal);
    }
}
Esempio n. 11
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);
	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);
	volatile uint32_t ui32PWMClock;
	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
}
Esempio n. 12
0
void MotorInit(uint8_t report)
{

	SystickInit(1);
	// 设置PWM时钟和系统时钟一致
	SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

	 // 使能PWM外设
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

	// 使能外设端口
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	//设置对应管脚的PWM信号功能
	GPIOPinConfigure(GPIO_PB4_M0PWM2);
	GPIOPinConfigure(GPIO_PB5_M0PWM3);
	GPIOPinConfigure(GPIO_PB6_M0PWM0);
	GPIOPinConfigure(GPIO_PB7_M0PWM1);

	//设置PWM信号端口
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);

	//PWM生成器配置
	PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);

	//设置PWM信号周期
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, PERIOD_TIME);
	PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, PERIOD_TIME);

	//设置PWM信号占空比
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 0);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 0);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 0);
	PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 0);

	// 使能PWM输出端口
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT|PWM_OUT_1_BIT|PWM_OUT_2_BIT|PWM_OUT_3_BIT, true);

	// 使能PWM生成器
	PWMGenEnable(PWM0_BASE, PWM_GEN_0);
	PWMGenEnable(PWM0_BASE, PWM_GEN_1);

	// 使能PWm生成器模块的及时功能.
	PWMSyncTimeBase(PWM0_BASE, PWM_GEN_0);
	PWMSyncTimeBase(PWM0_BASE, PWM_GEN_1);

	if(report)
		UARTprintf("PWM初始化完成!\r\n");
}
Esempio n. 13
0
/* *************************************************
 * Function: PWM_Init
 *
 * Inputs: None
 *
 * Outputs: None
 *
 * Date: 7/11/2013
 *
 * Description: This function initializes the PWM
 * peripherals.
 * ********************************************** */
void PWM_Init(void)
{

    // Set PWM Clock Divider to divide by 1
       SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    // Initialize GPIO Port corresponding to PWM output PWM1
       SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    // Enable the PWM0 peripheral.
       SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

    // Set GPIO pin as PWM output
       GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);

}
Esempio n. 14
0
//*****************************************************************************
//
// This example demonstrates how to setup the PWM block to generate signals.
//
//*****************************************************************************
void F_PWM_init(void)
{
//!setting up PWN

    volatile unsigned long ulLoop;


    //
    // Set the clocking to run directly from the crystal.
    //

    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
    // Enable the peripherals used by this example.
    //
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    //! Set GPIO B0 and B1 as PWM pins.  They are used to output the PWM0 and
    //! PWM1 signals.
    //
    GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	//
	//! Enable the PWM2 and PWM3 output signals if true.
	//
	PWMOutputState(PWM0_BASE,PWM_OUT_2_BIT|PWM_OUT_3_BIT, false);
	//
	//! Enable the PWM generator.
	//
	PWMGenEnable(PWM0_BASE, PWM_GEN_1);

    //
    //! Compute the PWM period based on the system clock.
    //
    ulPeriod = SysCtlClockGet() / PWMperiedset;

    //
    // Set the PWM2 period
    //
    PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC | PWM_GEN_MODE_DBG_RUN);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, ulPeriod);
}
void InitGPIO (void)
{
	// GPIO test initialisation
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0 | SYSCTL_PERIPH_PWM);
	SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);	// airspeed output
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);	// transponder output
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);	// airspeed response pin
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);	// transponder response pin

	// Configure airspeed input
	GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, UUT_AIRSPEED_RESPONSE_PIN_PE3);
	GPIOIntTypeSet(GPIO_PORTE_BASE, UUT_AIRSPEED_RESPONSE_PIN_PE3, GPIO_RISING_EDGE);
	GPIOPortIntRegister(GPIO_PORTE_BASE, &airspeed_response_isr);

	// Configure transponder input
	GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, UUT_TRANSPONDER_RESPONSE_PIN_PB3);
	GPIOIntTypeSet(GPIO_PORTB_BASE, UUT_TRANSPONDER_RESPONSE_PIN_PB3, GPIO_RISING_EDGE);
	GPIOPortIntRegister(GPIO_PORTB_BASE, &transponder_response_isr);

	// Configure airspeed pulse generation
	GPIOPinTypePWM(GPIO_PORTD_BASE, (1<<1));	// Airspeed output TODO: make pin macro
	PWMGenDisable(PWM0_BASE, PWM_GEN_0);
	PWMIntDisable(PWM0_BASE, PWM_GEN_0);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
	PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD); // configure pwm for end-of-cycle interrupt
	PWMGenIntRegister(PWM0_BASE, PWM_GEN_0, airspeed_pulse_isr);

	// Configure transponder pulse generation
	GPIOPinTypePWM(GPIO_PORTF_BASE, (1<<3));	// Transponder output TODO: make pin macro
	PWMGenDisable(PWM0_BASE, PWM_GEN_2);
	PWMIntDisable(PWM0_BASE, PWM_GEN_2);
	PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_2, PWM_INT_CNT_LOAD); // configure pwm for end-of-cycle interrupt
	PWMGenIntRegister(PWM0_BASE, PWM_GEN_2, transponder_pulse_isr);

	// Configure UUT reset signal
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

	GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_4);
	GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_4, GPIO_PIN_4);
}
Esempio n. 16
0
void manualSetup(void)
{
	led = 0;
	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, led);

	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);


	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2);
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);
	GPIOPinConfigure(GPIO_PF1_M1PWM5);
	GPIOPinConfigure(GPIO_PF2_M1PWM6);
	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);

	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
	PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8Adjust_red * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_2);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8Adjust_blue * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT, true);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8Adjust_green * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_7_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_3);
}
Esempio n. 17
0
//Main
int main(void) {
	//Clock del Sistema a 40MHz
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	//Divisor PWM
	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
	//Habilitar Periferico PWM1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	//Proveer Reloj al Puerto D y F
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	//Periferico como tipo PWM
	GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
	GPIOPinConfigure(GPIO_PD0_M1PWM0);
	//Remover bloqueo del SW0
	GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY;	//
	GPIO_PORTF_CR_R = 0x0f;
	//Switches como Entrada
	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4);
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
	//Llamar Metodo
	Conversion(Angulo);
	ConfiguracionPWM(Ancho);
	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, Ancho * Load / 1000);

	while(1)  {
		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00)   {
			Ancho--;
			if (Ancho < 40)    {
				Ancho = 40;    }
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, Ancho * Load / 1000);
		}
		if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00)   {
			Ancho++;
			if (Ancho > 140)    {
				Ancho = 140;    }
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, Ancho * Load / 1000);
		}
		SysCtlDelay(100000);
	}
}
Esempio n. 18
0
File: Base.c Progetto: ilabmp/micro
void Init_PWM() {
	//PWM 0
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM); //PWM Device Set
	SysCtlPWMClockSet(SYSCTL_PWMDIV_2); // PWM Generation clock Set
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Enable the GPIO port F
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0); // GPIO port F, pin 0 a PWM0
	PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN); // Configuration the PWM gen0
	PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 400); // Set the Period of the PWM Generator0
	PWMGenEnable(PWM_BASE, PWM_GEN_0); // Enable the PWM Generator0
	PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, 399); //Set PWM width
	PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, true); //Start PWM

	//PWM 2
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable the GPIO port B
	GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_0); // GPIO port B, pin 0 a PWM2
	PWMGenConfigure(PWM_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN); // Configuration the PWM gen0
	PWMGenPeriodSet(PWM_BASE, PWM_GEN_1, 400); // Set the Period of the PWM Generator0
	PWMGenEnable(PWM_BASE, PWM_GEN_1); // Enable the PWM Generator0
	PWMPulseWidthSet(PWM_BASE, PWM_OUT_2, 399); //Set PWM width
	PWMOutputState(PWM_BASE, PWM_OUT_2_BIT, true); //Start PWM

}
Esempio n. 19
0
//*****************************************************************************
//
// This example demonstrates how to setup the PWM block to generate signals.
//
//*****************************************************************************
void motor_init(void)
{
//!setting up PWN

    volatile unsigned long ulLoop;

    //
    // Set the clocking to run directly from the crystal.
    //

    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

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

    //
    //! Set GPIO F0 and D1 as PWM pins.  They are used to output the PWM0 and
    //! PWM1 signals.
    //
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
	//
	//! Enable the PWM0 and PWM1 output signals if true.
	//
	PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
	//
	//! Enable the PWM generator.
	//
	PWMGenEnable(PWM0_BASE, PWM_GEN_0);

	//
	//! Loop forever while the PWM signals are generated.
	//
}
Esempio n. 20
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);



}
Esempio n. 21
0
// Summary:	Initialize the MCU, including setting it to run from PLL,
//		enabling SysTick and interrupts.
void InitializeMCU(void)
{
/*	extern void SysTickPeriodSet(unsigned long);
	extern void SysTickEnable(void);//*/
	extern tBoolean IntMasterEnable(void);

	// Set the clocking to run from PLL, using external oscillator
	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
		SYSCTL_XTAL_6MHZ);
	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);	// PWM modules use 16-bit
		// registers, so use a divisor of 16 to prevent overflow

	g_ulTicksPerSecond = SysCtlClockGet();
	g_ulTicksPerUs = g_ulTicksPerSecond / 1000000;
	g_ulPWMTicksPerSecond = g_ulTicksPerSecond / 64;

/*	// Set up and enable the SysTick timer. It will be used as a reference
	// for delay loops in the interrupt handlers. The SysTick timer period
	// will be set up for one second.
	SysTickPeriodSet(g_ulTicksPerSecond);
	SysTickEnable();//*/

	IntMasterEnable();
}
Esempio n. 22
0
void Startup(void) {
  
  //STEP 1: OLED and PWM setup
  unsigned long ulPeriod;
  //SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
  SysCtlPWMClockSet(SYSCTL_PWMDIV_1); 
  SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
  GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
  ulPeriod = SysCtlClockGet() / 400;
  PWMGenConfigure(PWM0_BASE, PWM_GEN_0,PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
  PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
  PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ulPeriod / 16);
  PWMGenEnable(PWM0_BASE, PWM_GEN_0); 
  
  
  //STEP 2: Timer setup
  //SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
  /*TimerState = 0;
  TimerIntUnregister(TIMER1_BASE, TIMER_A);
  TimerIntRegister(TIMER1_BASE, TIMER_A, IntTimer0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
  TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
  TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet());    
  IntEnable(INT_TIMER1A);
  TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
  TimerEnable(TIMER1_BASE, TIMER_A);*/
  
  // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
  
  //STEP 3: Button pad setup 
  TrainState = 0;
  GPIOPortIntUnregister(GPIO_PORTE_BASE);
  GPIOPortIntRegister(GPIO_PORTE_BASE,IntGPIOe);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);    
  GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 );
  GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 , GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
  GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 , GPIO_FALLING_EDGE);
  GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 );
  IntEnable(INT_GPIOE);
  
  IntPrioritySet( INT_GPIOE, configKERNEL_INTERRUPT_PRIORITY);
  
  //STEP 4: Frequency count setup
  tempCount = 0;
  frequencyCount = 0;
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);       
  GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_3);
  GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
  GPIOPortIntUnregister(GPIO_PORTF_BASE);
  GPIOPortIntRegister(GPIO_PORTF_BASE,IntGPIOf);
  GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_RISING_EDGE);
  GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_3);
  IntEnable(INT_GPIOF);
  
  //STEP 5: UART setup  
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                      (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                       UART_CONFIG_PAR_NONE));
  IntEnable(INT_UART0); 
  UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
  
  IntPrioritySet( INT_UART0, configKERNEL_INTERRUPT_PRIORITY);
  
  //STEP 6: pin setup  
  /*SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, PORT_DATA);*/
  
  //STEP 7: ADC SETUP
  SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
  
  ADCSequenceDisable(ADC0_BASE,0);
  ADCSequenceDisable(ADC0_BASE,1);
  ADCSequenceDisable(ADC0_BASE,2);
  ADCSequenceDisable(ADC0_BASE,3);
  
  GPIOPinTypeADC(ADC0_BASE, 0xF); 
  
  ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);   
  ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0); 
  ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); 
  ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
  
  ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
  
  ADCSequenceEnable(ADC0_BASE, 0);
  ADCSequenceEnable(ADC0_BASE, 1);
  ADCSequenceEnable(ADC0_BASE, 2);
  ADCSequenceEnable(ADC0_BASE, 3);
  
   ADCIntClear(ADC0_BASE, 0);
   ADCIntClear(ADC0_BASE, 1);
    ADCIntClear(ADC0_BASE, 2);
  ADCIntClear(ADC0_BASE, 3);
  
  ADCIntEnable(ADC0_BASE, 0);
  ADCIntEnable(ADC0_BASE, 1);
  ADCIntEnable(ADC0_BASE, 2);
   ADCIntEnable(ADC0_BASE, 3);
  
 
  //IntEnable(INT_ADC0);
  //IntPrioritySet(INT_ADC, 50);
  
  //IntEnable(INT_ADC0);
  //ADCIntClear(ADC0_BASE, 0);
  
 
  
  return;
}
Esempio n. 23
0
/* ---- Private Function Prototypes -------------------------------------- */
void A3906Init()
{
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);	
	
    //
    // Enable the peripherals used by this device. (PWM0,1,2,3)
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);	
	
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);  	// PWM 0,1 ROLL_MOTOR 
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);     	// PWM 2,3 PITCH_MOTOR
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);  	// FL1 + FL2

	GPIOPinConfigure(GPIO_PB6_M0PWM0);    
	GPIOPinConfigure(GPIO_PB7_M0PWM1);   	
	
	GPIOPinConfigure(GPIO_PA6_M1PWM2);    
	GPIOPinConfigure(GPIO_PA7_M1PWM3);    
	
    //
    // Set GPIO PWM pins.  They are used to output the PWM0-3 signals
    //
    GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7); //pwm1 2-3
    GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6 | GPIO_PIN_7); //pwm0 2-3
    
    // Set the PWM period to 20KHz.
    // N = (1 / F) * SysClk. 
    // Where N is the function parameter
    // F is the desired frequency
    // SysClk is the system clock frequency.
    // In this case you get: (1 / 20KHz) * 80MHz = 4000 cycles.  Note that
    ulPeriod = 4000;// SysCtlClockGet() / PWMRATE;

    //ulPeriod = SysCtlClockGet() / 50000;//PWMRATE;
	//
	// Set the PWM period to chosen rate.
	//
	PWMGenConfigure(PWM_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulPeriod);
		
	//PWMGenConfigure(PWM_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
	//PWMGenPeriodSet(PWM_BASE, PWM_GEN_1, ulPeriod);

	PWMOutputInvert(PWM_BASE,PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
	//
	// Enable the PWM0 and PWM1 output signals.
	//
	PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
	//
	// Enable the PWM generators.
	//
	PWMGenEnable(PWM_BASE, PWM_GEN_0);
	//PWMGenEnable(PWM_BASE, PWM_GEN_1);

	//
	// Set the PWM period to chosen rate.
	//
	//PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
	//PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0, ulPeriod);
		
	PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, ulPeriod);

	PWMOutputInvert(PWM1_BASE,PWM_OUT_2_BIT | PWM_OUT_3_BIT, true);
	//
	// Enable the PWM0 and PWM1 output signals.
	//
	PWMOutputState(PWM1_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true);
	//
	// Enable the PWM generators.
	//
	//PWMGenEnable(PWM1_BASE, PWM_GEN_0);
	PWMGenEnable(PWM1_BASE, PWM_GEN_1);

	
#if 0
    // setup interrupt handlers for overcurrent
    GPIOPinInit(A3906_OC1_INTERRUPT_PORT,A3906_OC1_INTERRUPT_PIN,true,true);
    GPIOPinInit(A3906_OC2_INTERRUPT_PORT,A3906_OC2_INTERRUPT_PIN,true,true);
#endif
    desiredencoder[0] = -1;  // means not active
    desiredencoder[1] = -1;
    dcycle[0] = PITCH_MINIMUM_DUTYCYCLE; // recommended initial values
    dcycle[1] = ROLL_MINIMUM_DUTYCYCLE;
    brakeOnChange = true;
}
Esempio n. 24
0
int main(void) {
	volatile uint32_t ui32Load;
	volatile uint32_t ui32PWMClock;

	volatile uint8_t ui8AdjustRed, ui8AdjustGreen, ui8AdjustBlue;
	ui8AdjustRed = 254;
	ui8AdjustGreen = 2;
	ui8AdjustBlue = 2;

	// Set the system clock to 40 MHz
	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

	// Set the PWM Clock to 1/64 of the system clock i.e. 625 kHz
	SysCtlPWMClockSet(SYSCTL_PWMDIV_64);

	// Timer related intializations, time period is 10 ms.
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

	uint32_t ui32Period;
	ui32Period = (SysCtlClockGet()/100)/ 2;
	TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
	IntEnable(INT_TIMER0A);
	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	IntMasterEnable();
	TimerEnable(TIMER0_BASE, TIMER_A);

	// Enable the PWM module 1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

	// Enable the GPIO Port F
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	// PWM related initializations
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
	GPIOPinConfigure(GPIO_PF1_M1PWM5);
	GPIOPinConfigure(GPIO_PF2_M1PWM6);
	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);

	ui32PWMClock = SysCtlClockGet() / 64;
	ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;
	PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
	PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ui32Load);
	PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, ui32Load);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8AdjustRed * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_2);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8AdjustBlue * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT, true);

	PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8AdjustGreen * ui32Load / 1000);
	PWMOutputState(PWM1_BASE, PWM_OUT_7_BIT, true);
	PWMGenEnable(PWM1_BASE, PWM_GEN_3);

	// Detecting the phase while in the auto mode, RG, GB or BR.
	int autoLedState = 0;

	while(1) {
		if(mode==0) {
			if(autoLedState==0) {
				ui8AdjustRed--;
				ui8AdjustGreen++;

				if(ui8AdjustRed==2 && ui8AdjustGreen==254) autoLedState = 1;
			}
			else if(autoLedState==1) {
				ui8AdjustGreen--;
				ui8AdjustBlue++;

				if(ui8AdjustGreen==2 && ui8AdjustBlue==254) autoLedState = 2;
			}
			else if(autoLedState==2) {
				ui8AdjustBlue--;
				ui8AdjustRed++;

				if(ui8AdjustBlue==2 && ui8AdjustRed==254) autoLedState = 0;
			}

			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8AdjustRed * ui32Load / 1000);
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8AdjustBlue * ui32Load / 1000);
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8AdjustGreen * ui32Load / 1000);

			SysCtlDelay(delay);
		}
		else {
			if(mode==1) {
				ui8AdjustBlue = 2;
				ui8AdjustGreen = 2;

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00) {
					ui8AdjustRed--;
					if (ui8AdjustRed < 20) ui8AdjustRed = 20;
				}

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00) {
					ui8AdjustRed++;
					if (ui8AdjustRed > 254) ui8AdjustRed = 254;
				}
			}
			else if(mode==2) {
				ui8AdjustRed = 2;
				ui8AdjustGreen = 2;

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00) {
					ui8AdjustBlue--;
					if (ui8AdjustBlue < 20) ui8AdjustBlue = 20;
				}

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00) {
					ui8AdjustBlue++;
					if (ui8AdjustBlue > 254) ui8AdjustBlue = 254;
				}

			}
			else if(mode==3) {
				ui8AdjustBlue = 2;
				ui8AdjustRed = 2;

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_4)==0x00) {
					ui8AdjustGreen--;
					if (ui8AdjustGreen < 20) ui8AdjustGreen = 20;
				}

				if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)==0x00) {
					ui8AdjustGreen++;
					if (ui8AdjustGreen > 254) ui8AdjustGreen = 254;
				}
			}

			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, ui8AdjustRed * ui32Load / 1000);
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, ui8AdjustBlue * ui32Load / 1000);
			PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, ui8AdjustGreen * ui32Load / 1000);

			SysCtlDelay(100000);
		}
	}
}
//*****************************************************************************
//
// The main code for the application.  It sets up the peripherals, displays the
// splash screens, and then manages the interaction between the game and the
// screen saver.
//
//*****************************************************************************
int
main(void)
{
    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    //
    // Set the clocking to run at 50MHz from the PLL.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_8);

    //
    // Get the system clock speed.
    //
    g_ulSystemClock = SysCtlClockGet();

    //
    // Enable the peripherals used by the application.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure the GPIOs used to read the state of the on-board push buttons.
    //
    GPIOPinTypeGPIOInput(GPIO_PORTE_BASE,
                         GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    GPIOPadConfigSet(GPIO_PORTE_BASE,
                     GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD_WPU);

    //
    // Configure the LED, speaker, and UART GPIOs as required.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);

    //
    // Intialize the Ethernet Controller and TCP/IP Stack.
    //
    EnetInit();

    //
    // Configure the first UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    UARTEnable(UART0_BASE);

    //
    // Send a welcome message to the UART.
    //
    UARTCharPut(UART0_BASE, 'W');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, 'l');
    UARTCharPut(UART0_BASE, 'c');
    UARTCharPut(UART0_BASE, 'o');
    UARTCharPut(UART0_BASE, 'm');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, '\r');
    UARTCharPut(UART0_BASE, '\n');

    //
    // Initialize the OSRAM OLED display.
    //
    RIT128x96x4Init(3500000);

    //
    // Initialize the PWM for generating music and sound effects.
    //
    AudioOn();

    //
    // Configure SysTick to periodically interrupt.
    //
    SysTickPeriodSet(g_ulSystemClock / CLOCK_RATE);
    SysTickIntEnable();
    SysTickEnable();

    //
    // Delay for a bit to allow the initial display flash to subside.
    //
    Delay(CLOCK_RATE / 4);

    //
    // Play the intro music.
    //
    AudioPlaySong(g_pusIntro, sizeof(g_pusIntro) / 2);

    //
    // Display the Texas Instruments logo for five seconds (or twelve seconds
    // if built using gcc).
    //
#if defined(gcc)
    DisplayLogo(g_pucTILogo, 120, 42, 12 * CLOCK_RATE);
#else
    DisplayLogo(g_pucTILogo, 120, 42, 5 * CLOCK_RATE);
#endif

    //
    // Display the Code Composer Studio logo for five seconds.
    //
#if defined(ccs)
    DisplayLogo(g_pucCodeComposer, 128, 34, 5 * CLOCK_RATE);
#endif

    //
    // Display the Keil/ARM logo for five seconds.
    //
#if defined(rvmdk) || defined(__ARMCC_VERSION)
    DisplayLogo(g_pucKeilLogo, 128, 40, 5 * CLOCK_RATE);
#endif

    //
    // Display the IAR logo for five seconds.
    //
#if defined(ewarm)
    DisplayLogo(g_pucIarLogo, 102, 61, 5 * CLOCK_RATE);
#endif

    //
    // Display the CodeSourcery logo for five seconds.
    //
#if defined(sourcerygxx)
    DisplayLogo(g_pucCodeSourceryLogo, 128, 34, 5 * CLOCK_RATE);
#endif

    //
    // Display the CodeRed logo for five seconds.
    //
#if defined(codered)
    DisplayLogo(g_pucCodeRedLogo, 128, 32, 5 * CLOCK_RATE);
#endif

    //
    // Throw away any button presses that may have occurred while the splash
    // screens were being displayed.
    //
    HWREGBITW(&g_ulFlags, FLAG_BUTTON_PRESS) = 0;

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Display the main screen.
        //
        if(MainScreen())
        {
            //
            // The button was pressed, so start the game.
            //
            PlayGame();
        }
        else
        {
            //
            // The button was not pressed during the timeout period, so start
            // the screen saver.
            //
            ScreenSaver();
        }
    }
}
Esempio n. 26
0
//*****************************************************************************
//
// Configure PWM0 for a 25% duty cycle signal running at 250Hz.  This example
// also shows how to invert the PWM signal every 5 seconds for 5 seconds.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    // Set the PWM clock to the system clock.
    //
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for Timer operation.
    //
    InitConsole();

    //
    // Display the setup on the console.
    //
    UARTprintf("PWM ->\n");
    UARTprintf("  Module: PWM0\n");
    UARTprintf("  Pin: PD0\n");
    UARTprintf("  Configured Duty Cycle: 25%%\n");
    UARTprintf("  Inverted Duty Cycle: 75%%\n");
    UARTprintf("  Features: PWM output inversion every 5 seconds.\n\n");
    UARTprintf("Generating PWM on PWM0 (PD0) -> State = ");

    //
    // The PWM peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

    //
    // For this example PWM0 is used with PortB Pin6.  The actual port and
    // pins used may be different on your part, consult the data sheet for
    // more information.
    // GPIO port B needs to be enabled so these pins can be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Configure the GPIO pin muxing to select PWM00 functions for these pins.
    // This step selects which alternate function is available for these pins.
    // This is necessary if your part supports GPIO pin function muxing.
    // Consult the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinConfigure(GPIO_PB6_M0PWM0);

    //
    // Configure the PWM function for this pin.
    // Consult the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);

    //
    // Configure the PWM0 to count up/down without synchronization.
    //
    PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |
                    PWM_GEN_MODE_NO_SYNC);

    //
    // Set the PWM period to 250Hz.  To calculate the appropriate parameter
    // use the following equation: N = (1 / f) * SysClk.  Where N is the
    // function parameter, f is the desired frequency, and SysClk is the
    // system clock frequency.
    // In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles.  Note that
    // the maximum period you can set is 2^16.
    // TODO: modify this calculation to use the clock frequency that you are
    // using.
    //
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 64000);

    //
    // Set PWM0 to a duty cycle of 25%.  You set the duty cycle as a function
    // of the period.  Since the period was set above, you can use the
    // PWMGenPeriodGet() function.  For this example the PWM will be high for
    // 25% of the time or 16000 clock ticks (64000 / 4).
    //
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
                     PWMGenPeriodGet(PWM0_BASE, PWM_OUT_0) / 4);

    //
    // Enable the PWM0 Bit0 (PD0) output signal.
    //
    PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);

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

    //
    // Loop forever while the PWM signals are generated.
    //
    while(1)
    {
        //
        // Print out that the level of PWM is normal.
        //
        UARTprintf("Normal  \b\b\b\b\b\b\b\b");

        //
        // This function provides a means of generating a constant length
        // delay.  The function delay (in cycles) = 3 * parameter.  Delay
        // 5 seconds arbitrarily.
        //
        SysCtlDelay((SysCtlClockGet() * 5) / 3);

        //
        // Invert PWM0 signal.
        //
        PWMOutputInvert(PWM0_BASE, PWM_OUT_0_BIT, true);

        //
        // Print out that the level of PWM is inverted.
        //
        UARTprintf("Inverted\b\b\b\b\b\b\b\b");

        //
        // This function provides a means of generating a constant length
        // delay.  The function delay (in cycles) = 3 * parameter.  Delay
        // 5 seconds arbitrarily.
        //
        SysCtlDelay((SysCtlClockGet() * 5) / 3);

        //
        // Switch PWM0 signal back to regular operation.
        //
        PWMOutputInvert(PWM0_BASE, PWM_OUT_0_BIT, false);
    }
}
Esempio n. 27
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.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
    // Initialize the OLED display.
    //
    RIT128x96x4Init(1000000);

    //
    // Clear the screen and tell the user what is happening.
    //
    RIT128x96x4StringDraw("Generating PWM", 18, 24, 15);
    RIT128x96x4StringDraw("on PF0 and PG1", 18, 32, 15);

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

    //
    // Set GPIO F0 and G1 as PWM pins.  They are used to output the PWM0 and
    // PWM1 signals.
    //
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);

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

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

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

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

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

    //
    // Loop forever while the PWM signals are generated.
    //
    while(1)
    {
    }
}
Esempio n. 28
0
//*****************************************************************************
//
// Initialize the IO used in this demo
// 1. STATUS LED on Port F pin 0
// 2. PWM on Port D Pin 1 (PWM1)
//
//*****************************************************************************
void
io_init(void)
{
    unsigned long ulPWMClock;
    
    //
    // Enable GPIO bank F to allow control of the LED.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Configure Port F0 for as an output for the status LED.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_0);

    //
    // Initialize LED to OFF (0)
    //
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);

    //
    // Enable Port G1 for PWM output.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    GPIOPinTypePWM(GPIO_PORTG_BASE,GPIO_PIN_1);

    //
    // Enable the PWM generator.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);

    //
    // Configure the PWM generator for count down mode with immediate updates
    // to the parameters.
    //
    PWMGenConfigure(PWM_BASE, PWM_GEN_0,
                    PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

    //
    // Divide the PWM clock by 4.
    //
    SysCtlPWMClockSet(SYSCTL_PWMDIV_4);

    //
    // Get the PWM clock.
    //
    ulPWMClock = SysCtlClockGet()/4;

    //
    // Intialize the PWM frequency and duty cycle.
    //
    g_ulFrequency = 440;
    g_ulDutyCycle = 50;

    //
    // Set the period of PWM1.
    //
    PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulPWMClock / g_ulFrequency);

    //
    // Set the pulse width of PWM1.
    //
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_1,
                     ((ulPWMClock * g_ulDutyCycle)/100) / g_ulFrequency);

    //
    // Start the timers in generator 0.
    //
    PWMGenEnable(PWM_BASE, PWM_GEN_0);

}
Esempio n. 29
0
/* 
 * initializes task variables
 */
void initializeWarningTask() {
  //
  // Enable the peripherals used by this code. I.e enable the use of pin banks, etc.
  //
  SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);        // bank C
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);        // bank E
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);        // bank F
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);        // bank G


  // configure the pin C5 for 4mA output
  GPIOPadConfigSet(GPIO_PORTC_BASE,LED_RED, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
  GPIODirModeSet(GPIO_PORTC_BASE, LED_RED, GPIO_DIR_MODE_OUT);    

  // configure the pin C6 for 4mA output
  GPIOPadConfigSet(GPIO_PORTC_BASE,LED_GREEN, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
  GPIODirModeSet(GPIO_PORTC_BASE, LED_GREEN, GPIO_DIR_MODE_OUT);

  // configure the pin C7 for 4mA output
  GPIOPadConfigSet(GPIO_PORTC_BASE,LED_YELLOW, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
  GPIODirModeSet(GPIO_PORTC_BASE, LED_YELLOW, GPIO_DIR_MODE_OUT);

  // configure the pin E0 for input (sw3). NB: requires pull-up to operate
  GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,
      GPIO_PIN_TYPE_STD_WPU);
  GPIODirModeSet(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN);


  /*  This function call does the same result of the above pair of calls,
   *  but still requires that the bank of peripheral pins is enabled via
   *  SysCtrlPeripheralEnable()
   */
  //  GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, LED_RED);

  ///////////////////////////////////////////
  //  This section defines the PWM speaker characteristics
  ///////////////////////////////////////////

  //
  // Set the clocking to run directly from the crystal.
  //
  SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

  //
  // Set GPIO F0 and G1 as PWM pins.  They are used to output the PWM0 and
  // PWM1 signals.
  //
  GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
  GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);

  //
  // Compute the PWM period based on the system clock.
  //
  ulPeriod = SysCtlClockGet() / 65;

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

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

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

  // initialize the warning data pointers
  data.temperatureCorrected = &(globalDataMem.temperatureCorrected);
  data.systolicPressCorrected = &(globalDataMem.systolicPressCorrected);
  data.diastolicPressCorrected = &(globalDataMem.diastolicPressCorrected);
  data.pulseRateCorrected = &(globalDataMem.pulseRateCorrected);
  data.batteryState = &(globalDataMem.batteryState);

  // Load the TCB
  warningTask.runTaskFunction = &warningRunFunction;
  warningTask.taskDataPtr = &data;
}
Esempio n. 30
0
//*****************************************************************************
//
// This example demonstrates the use of PWM for playing audio.
//
//*****************************************************************************
int
main(void)
{
    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
    // Enable the peripherals used by the application.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

    //
    // Configure the GPIOs used to read the state of the on-board push buttons.
    //
    GPIOPinTypeGPIOInput(GPIO_PORTG_BASE,
                         (GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |
                          GPIO_PIN_7));
    GPIOPadConfigSet(GPIO_PORTG_BASE,
                     (GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |
                      GPIO_PIN_7), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    //
    // Initialize the OLED display and print out the directions.
    //
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("Audio Playback via", 10, 16, 15);
    RIT128x96x4StringDraw("Class-D Amplifier", 12, 24, 15);
    RIT128x96x4StringDraw("Press Up for Vol+", 12, 40, 15);
    RIT128x96x4StringDraw("Press Down for Vol-", 6, 48, 15);
    RIT128x96x4StringDraw("Press Left for PCM", 10, 56, 15);
    RIT128x96x4StringDraw("Press Right for ADPCM", 0, 64, 15);
    RIT128x96x4StringDraw("Press Select to stop", 4, 72, 15);

    //
    // Initialize the Class-D amplifier driver.
    //
    ClassDInit(SysCtlClockGet());

    //
    // Wait until the Class-D amplifier driver is done starting up.
    //
    while(ClassDBusy())
    {
    }

    //
    // Start playback of the PCM stream.
    //
    ClassDPlayPCM(g_pucPCMData, sizeof(g_pucPCMData));

    //
    // Set up and enable SysTick.
    //
    SysTickPeriodSet(SysCtlClockGet() / 200);
    SysTickEnable();
    SysTickIntEnable();

    //
    // Loop forever.
    //
    while(1)
    {
    }
}