示例#1
0
/*********************************************************************
 * @fn      HalTimer1Init
 *
 * @brief   Initialize Timer Service
 *
 * @param   None
 *
 * @return  None
 */
void HalTimer1Init (halTimerCBack_t cBack)
{
  //not used for now
  (void) cBack;

  //
  // Enable GPT0
  //  
  SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);
    
  //
  // Configure Timer0A for PWM use
  //
  TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |
                 GPTIMER_CFG_A_PWM);

  //
  // Set Duty cycle and enable
  //
  TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
  TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, PWM_PERIOD);
  TimerEnable(GPTIMER0_BASE, GPTIMER_A);

  //
  // Set duty cycle to 0
  //
  TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, 0); 
}
示例#2
0
extern "C" int main(void) {
    unsigned long ir_period;

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

	ConfigureUART();
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Unlock PF0 so we can change it to a GPIO input
    // Once we have enabled (unlocked) the commit register then re-lock it
    // to prevent further changes.  PF0 is muxed with NMI thus a special case.
    //
    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;

	// Interrupt on sw1
    GPIODirModeSet(IR_PORT, IR_PIN, GPIO_DIR_MODE_IN);
    GPIOPadConfigSet(IR_PORT, IR_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
	GPIOPinTypeGPIOInput(IR_PORT, IR_PIN);
	GPIOIntTypeSet(IR_PORT, IR_PIN, GPIO_FALLING_EDGE);
	GPIOIntRegister(IR_PORT, ir_input_isr);
	GPIOIntEnable(IR_PORT, IR_PIN );

	IntMasterEnable();

    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);
    GPIOPinConfigure(GPIO_PF1_T0CCP1);
    GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_1);

    // Configure timer
    ir_period = SysCtlClockGet() / (IR_CARRIER / 2);

	UARTprintf("ir_period:%d\n", ir_period);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_B_PWM);
    TimerLoadSet(TIMER0_BASE, TIMER_B, ir_period);
    TimerMatchSet(TIMER0_BASE, TIMER_B, ir_period / 2); // PWM
    TimerEnable(TIMER0_BASE, TIMER_B);

	unsigned long m = 0;
	while(1) {
		TimerMatchSet(TIMER0_BASE, TIMER_B, m++); // PWM
		if (m > ir_period) m = 0;
		int i = 0;
		while (i++ < 5000)
			if (!ir.empty())
				UARTprintf("%u", ir.pop_front());
	}
}
示例#3
0
void cfg_Timer()
{
  uint32_t Period=800000/*(40MHz/800.000=50Hz)*/,DutyCycle=Period/2;
  
  ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);   //40MHz
  
  /*********************CONFIG_PWM_1*********************************/
  SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
  GPIOPinConfigure(GPIO_PC4_WT0CCP0);
  GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_4);
  TimerConfigure(WTIMER0_BASE,  TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
  TimerLoadSet(WTIMER0_BASE, TIMER_A, Period);
  TimerMatchSet(WTIMER0_BASE, TIMER_A, DutyCycle);
  TimerEnable(WTIMER0_BASE, TIMER_A);
  /*********************CONFIG_PWM_1*********************************/

  /*********************CONFIG_PWM_2*********************************/
  SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1);
  //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
  GPIOPinConfigure(GPIO_PC6_WT1CCP0);
  GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_6);
  TimerConfigure(WTIMER1_BASE,  TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
  TimerLoadSet(WTIMER1_BASE, TIMER_A, Period);
  TimerMatchSet(WTIMER1_BASE, TIMER_A, DutyCycle);
  TimerEnable(WTIMER1_BASE, TIMER_A);
  /********************CONFIG_PWM_2********************************

  /*********************CONFIG_PWM_3*********************************/
  SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER2);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  GPIOPinConfigure(GPIO_PD0_WT2CCP0);
  GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0);
  TimerConfigure(WTIMER2_BASE,  TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
  TimerLoadSet(WTIMER2_BASE, TIMER_A, Period);
  TimerMatchSet(WTIMER2_BASE, TIMER_A, DutyCycle);
  TimerEnable(WTIMER2_BASE, TIMER_A);
  /*********************CONFIG_PWM_3*********************************/

  /*********************CONFIG_PWM_4*********************************/
  SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER3);
  //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  GPIOPinConfigure(GPIO_PD2_WT3CCP0);
  GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_2);
  TimerConfigure(WTIMER3_BASE,  TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
  TimerLoadSet(WTIMER3_BASE, TIMER_A, Period);
  TimerMatchSet(WTIMER3_BASE, TIMER_A, DutyCycle);
  TimerEnable(WTIMER3_BASE, TIMER_A);
  /*********************CONFIG_PWM_4*********************************/
}
示例#4
0
文件: main.c 项目: gluker/sonar
void hw_init(void){
	SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

	f_cpu = SysCtlClockGet();
	SysTickPeriodSet(0xffffffff);
	SysTickEnable();
//	UARTStdioInit();

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	GPIODirModeSet(SONAR_PORT, TRIG_PIN, GPIO_DIR_MODE_OUT);
	GPIODirModeSet(SONAR_PORT, SERVO_PIN, GPIO_DIR_MODE_OUT);

	GPIOPinTypeGPIOInput(SONAR_PORT, ECHO_PIN);
	GPIOIntTypeSet(SONAR_PORT, ECHO_PIN, GPIO_RISING_EDGE);
	GPIOPinIntEnable(SONAR_PORT,ECHO_PIN);
	IntEnable(INT_GPIOD);

	//Timer configuration
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
	const long timer_match = (f_cpu/1000000)*10;
	const long timer_out = (f_cpu/1000)*80;
	TimerLoadSet(TIMER0_BASE, TIMER_A, timer_out);
	TimerMatchSet(TIMER0_BASE, TIMER_A, timer_match);
	TimerEnable(TIMER0_BASE, TIMER_A);
	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	TimerIntClear(TIMER0_BASE,TIMER_A);
	IntEnable(INT_TIMER0A);

	IntMasterEnable();

}
示例#5
0
static void pwm_init(void) {
	uint32_t frequency = 50;

	uint32_t period1 = SysCtlClockGet() / frequency;
	uint32_t extender1 = period1 >> 16;
	period1 &= 0xFFFF;

	uint32_t period2 =  SysCtlClockGet() / frequency;
	uint32_t extender2 = period2 >> 16;
	period2 &= 0xFFFF;

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinConfigure(GPIO_PB2_T3CCP0);
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2);
	// Configure timer
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
	TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	HWREG(TIMER3_BASE + TIMER_O_CTL) |= (TIMER_CTL_TAPWML);
	//set period
	TimerPrescaleSet(TIMER3_BASE, TIMER_A, extender1);
	TimerLoadSet(TIMER3_BASE, TIMER_A, period1);
	//set default value A
	TimerPrescaleMatchSet(TIMER3_BASE, TIMER_A, extender2);
	TimerMatchSet(TIMER3_BASE, TIMER_A, period2);
	TimerEnable(TIMER3_BASE, TIMER_A);
}
示例#6
0
void control_laser_intensity(uint8_t intensity) {
	laser_intensity = intensity;
	if (intensity == 0) intensity = 1;

	// Set the PWM (Intensity).
	TimerMatchSet(LASER_TIMER, TIMER_A, laser_cycles - (laser_cycles * intensity / 255));
}
示例#7
0
/*********************************************************************************************************
** Function name:           SetFanPwm
** Descriptions:            
** input parameters:        
**                          
** Output parameters::      нч
** Returned value:          
**                          
** Created by:              
** Created Date:            
**--------------------------------------------------------------------------------------------------------
** Modified by:            
** Modified date:          
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void SetFanPwmOut(u8 u8PwmValue)
{
     // Set the Timer1B match value to load value / 3.
    //
    TimerMatchSet(WTIMER2_BASE, TIMER_B,
                  TimerLoadGet(WTIMER2_BASE, TIMER_B) *u8PwmValue/100);

}
示例#8
0
void pwm_out(uint32_t ui32Period, uint32_t duty_cycle)
{
    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
    TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
    TimerMatchSet(TIMER0_BASE, TIMER_A, duty_cycle); // PWM
    TimerEnable(TIMER0_BASE, TIMER_A);

}
示例#9
0
文件: main.c 项目: arduic/GitHub
//This function will set the PWM for the desired timer and thus desired pin on off for duty cycle from 0-0xFF note OFF not ON.
//We do not need to disable and enable the timer before calling timer match set it will just update the value note after 0xBF ESC is off
inline void PWMSet(unsigned long timer, unsigned long dutyLow){
	//TimerPrescaleMatchSet(timer,TIMER_A,(dutyLow << 8));
	TimerMatchSet(timer,TIMER_A,(dutyLow << 8));		//Shift the data 8 bit's because the clock is shifted 8 bits
	//SysCtlDelay((SysCtlClockGet() / (1000 * 3))*1);
	//unsigned long bob = TimerMatchGet(timer,TIMER_A);
	//unsigned long jim = TimerLoadGet(timer,TIMER_A);

}
示例#10
0
/*********************************************************************************************************
** Function name:           ConfigureFanPWM
** Descriptions:            
** input parameters:        
**                          
** Output parameters::      нч
** Returned value:          
**                          
** Created by:     zhangwen          
** Created Date:            
**--------------------------------------------------------------------------------------------------------
** Modified by:            
** Modified date:          
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void ConfigureFanPWM(u8 u8DefaulPwm)
{
    
  //
    // The Timer1 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER2);



    //
    // Configure the GPIO pin muxing for the Timer/CCP function.
    // This is only necessary if your part supports GPIO pin function muxing.
    // Study the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using
    //
    GPIOPinConfigure(GPIO_PD1_WT2CCP1);

    //
 

    //
    // Configure the ccp settings for CCP pin.  This function also gives
    // control of these pins to the SSI hardware.  Consult the data sheet to
    // see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_1);


    //
    // Configure Timer1B as a 16-bit periodic timer.
    //
    TimerConfigure(WTIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);

    //
    // Set the Timer1B load value to 50000.  For this example a 66% duty cycle
    // PWM signal will be generated.  From the load value (i.e. 50000) down to
    // match value (set below) the signal will be high.  From the match value
    // to 0 the timer will be low.
    //
    TimerLoadSet(WTIMER2_BASE, TIMER_B, 50000);

    //
    // Set the Timer1B match value to load value / 3.
    //
    TimerMatchSet(WTIMER2_BASE, TIMER_B,
                  TimerLoadGet(WTIMER2_BASE, TIMER_B) *u8DefaulPwm/100);

    //
    // Enable Timer1B.
    //
    TimerEnable(WTIMER2_BASE, TIMER_B);

    //
    // Loop forever while the Timer1B PWM runs.
}
示例#11
0
void high_to_low(void)
{

		TimerMatchSet(TIMER0_BASE, TIMER_B, TimerLoadGet(TIMER0_BASE, TIMER_B)/2);

		TimerEnable(TIMER0_BASE, TIMER_B);

		SysCtlDelay(SysCtlClockGet()/50);

		TimerDisable(TIMER0_BASE, TIMER_B);

		TimerMatchSet(TIMER0_BASE, TIMER_B, TimerLoadGet(TIMER0_BASE, TIMER_B)/4);

		TimerEnable(TIMER0_BASE, TIMER_B);

		SysCtlDelay(SysCtlClockGet()/50);

		TimerDisable(TIMER0_BASE, TIMER_B);

		TimerMatchSet(TIMER0_BASE, TIMER_B, TimerLoadGet(TIMER0_BASE, TIMER_B)/6);

		TimerEnable(TIMER0_BASE, TIMER_B);

		SysCtlDelay(SysCtlClockGet()/50);

		TimerDisable(TIMER0_BASE, TIMER_B);

		TimerMatchSet(TIMER0_BASE, TIMER_B, TimerLoadGet(TIMER0_BASE, TIMER_B)/8);

		TimerEnable(TIMER0_BASE, TIMER_B);

		SysCtlDelay(SysCtlClockGet()/50);

		TimerDisable(TIMER0_BASE, TIMER_B);

		TimerMatchSet(TIMER0_BASE, TIMER_B, TimerLoadGet(TIMER0_BASE, TIMER_B)/10);

		TimerEnable(TIMER0_BASE, TIMER_B);

		SysCtlDelay(SysCtlClockGet()/50);

		TimerDisable(TIMER0_BASE, TIMER_B);

	}
示例#12
0
void initLCD() {

	SysCtlPeripheralEnable(LCDPORTENABLE);
	GPIOPinTypeGPIOOutput(LCDPORT,
				0xff);

	// Please refer to the HD44780 datasheet for how these initializations work!
	SysCtlDelay((500e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, RS,  0x00 );

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDPORT, E, 0x00);

	SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);SysCtlDelay((20e-6)*CLKSPEED/3);GPIOPinWrite(LCDPORT, E, 0x00);

	SysCtlDelay((50e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x30 );
	GPIOPinWrite(LCDPORT, E, 0x02);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDPORT, E, 0x00);

	SysCtlDelay((10e-3)*CLKSPEED/3);

	GPIOPinWrite(LCDPORT, D4 | D5 | D6 | D7,  0x20 );
	GPIOPinWrite(LCDPORT, E, 0x02);SysCtlDelay((20e-6)*CLKSPEED/3); GPIOPinWrite(LCDPORT, E, 0x00);

	SysCtlDelay((10e-3)*CLKSPEED/3);

	LCDCommand(0x01);	// Clear the screen.
	LCDCommand(0x06);	// Cursor moves right.
	LCDCommand(0x0f);	// Cursor blinking, turn on LCD.

	// Now change contrast, by using PWM output on GPIO pin V0 (required configuring timer)
	// You could also use the pwm.h functions instead?
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
	GPIOPinConfigure(GPIO_PB2_T3CCP0);
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2);


	//GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2);
	//GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2,0);

	unsigned long ulPeriod = (SysCtlClockGet() / 50000)/2;
	unsigned long dutyCycle1 = (unsigned long)(ulPeriod-1)*0.7;

	TimerConfigure(TIMER3_BASE, (TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM));
	TimerControlLevel(TIMER3_BASE, TIMER_BOTH, 0);
	TimerLoadSet(TIMER3_BASE, TIMER_A, ulPeriod -1);
	TimerMatchSet(TIMER3_BASE, TIMER_A, dutyCycle1);
	TimerEnable(TIMER3_BASE, TIMER_A);

	LCDCommand(0x0c);
}
示例#13
0
void SetPWM(uint32_t ulBaseAddr, uint32_t ulTimer, uint32_t ulFrequency, int32_t ucDutyCycle)
{
	uint32_t ulPeriod;
	ulPeriod = ROM_SysCtlClockGet() / ulFrequency;
	TimerLoadSet(ulBaseAddr, ulTimer, ulPeriod);
	if (ucDutyCycle > 90)
		ucDutyCycle = 90;
	else if (ucDutyCycle < -90)
		ucDutyCycle = -90;
	TimerMatchSet(ulBaseAddr, ulTimer, (100 + ucDutyCycle) * ulPeriod / 200 - 1);
}
示例#14
0
void pwm1(unsigned long val1)
{
       /*if(val1 <= 1)
       {
    	   val1=0;
        }
       else
    	 val1=val1-1;
        */
		TimerMatchSet(TIMER0_BASE, TIMER_A, TimerLoadGet(TIMER0_BASE, TIMER_A)*val1/256);
		TimerEnable(TIMER0_BASE, TIMER_A);
}
示例#15
0
文件: motors.c 项目: dani6rg/IMU
/*
    Sets a given motor to a given percent value
    \param motor is the motor number (1-4)
    \param percent is the percentage to set (0-100)
    \return none
*/
void motorSet(int motor, float percent)
{   
    //sterilize input
    if (percent > 100) percent = 100;
    if (percent < 0) percent = 0;

    //prepare prescale and match values
    uint32_t cycles_per_ms = SysCtlClockGet() / 1000;
    //*debug: straight pwm leds- */uint32_t matchl = SysCtlClockGet() / MOTORUPDATE / 100 * percent;
    uint32_t matchl = cycles_per_ms + (uint32_t)(percent * (cycles_per_ms / 100));
    uint8_t matchh = matchl >> 16;
    matchl &= 0xFFFF;

    //write to correct pwm module
    switch (motor) {
        case 1: { TimerPrescaleMatchSet(TIMER1_BASE, TIMER_A, matchh); TimerMatchSet(TIMER1_BASE, TIMER_A, matchl); }
        case 2: { TimerPrescaleMatchSet(TIMER1_BASE, TIMER_B, matchh); TimerMatchSet(TIMER1_BASE, TIMER_B, matchl); }
        case 3: { TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, matchh); TimerMatchSet(TIMER2_BASE, TIMER_A, matchl); }
        case 4: { TimerPrescaleMatchSet(TIMER2_BASE, TIMER_B, matchh); TimerMatchSet(TIMER2_BASE, TIMER_B, matchl); }
    }
    
}
//*****************************************************************************
//
//! Set the output color.
//!
//! \param pulRGBColor points to a three element array representing the
//! relative intensity of each color.  Red is element 0, Green is element 1,
//! Blue is element 2. 0x0000 is off.  0xFFFF is fully on.
//!
//! This function should be called by the application to set the color
//! of the RGB LED.
//!
//! \return None.
//
//*****************************************************************************
void 
RGBColorSet(volatile unsigned long * pulRGBColor)
{
    unsigned long ulColor[3];
    unsigned long ulIndex;

    for(ulIndex=0; ulIndex < 3; ulIndex++)
    {
        g_ulColors[ulIndex] = pulRGBColor[ulIndex];
        ulColor[ulIndex] = (unsigned long) (((float) pulRGBColor[ulIndex]) *
                            g_fIntensity + 0.5f);

        if(ulColor[ulIndex] > 0xFFFF)
        {
            ulColor[ulIndex] = 0xFFFF;
        }
    }

    TimerMatchSet(RED_TIMER_BASE, RED_TIMER, ulColor[RED]);
    TimerMatchSet(GREEN_TIMER_BASE, GREEN_TIMER, ulColor[GREEN]);
    TimerMatchSet(BLUE_TIMER_BASE, BLUE_TIMER, ulColor[BLUE]);
}
示例#17
0
void Config_PWM(void)
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

#ifdef	PB2_T3CCP0
	// Configure timer
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
	GPIOPinConfigure(GPIO_PB2_T3CCP0);
	TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER3_BASE, TIMER_A, DEFAULT_FREQ);
	TimerMatchSet(TIMER3_BASE, TIMER_A, DEFAULT_FREQ); // PWM
	TimerControlLevel(TIMER3_BASE, TIMER_A, false);
	TimerEnable(TIMER3_BASE, TIMER_A);
#endif

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	GPIOPinConfigure(GPIO_PB6_T0CCP0);		//Right
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER0_BASE, TIMER_A, DEFAULT_FREQ);
	TimerMatchSet(TIMER0_BASE, TIMER_A, DEFAULT_FREQ); // PWM
	TimerControlLevel(TIMER0_BASE, TIMER_A, false);
	TimerEnable(TIMER0_BASE, TIMER_A);

#ifdef	PB4_T1CCP0
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
	GPIOPinConfigure(GPIO_PB4_T1CCP0);
	GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4);
	TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER1_BASE, TIMER_A, DEFAULT_FREQ);
	TimerMatchSet(TIMER1_BASE, TIMER_A, DEFAULT_FREQ); // PWM
	TimerControlLevel(TIMER1_BASE, TIMER_A, false);
	TimerEnable(TIMER1_BASE, TIMER_A);
#endif

	SetPWM(PWM_LEFT,DEFAULT_FREQ, 0);
	SetPWM(PWM_RIGHT,DEFAULT_FREQ, 0);
}
示例#18
0
文件: sound.c 项目: spamish/ENB350
//*****************************************************************************
//
//! Initializes the sound driver.
//!
//! \param ui32SysClock is the frequency of the system clock.
//!
//! This function initializes the sound driver, preparing it to output sound
//! data to the speaker.
//!
//! The system clock should be as high as possible; lower clock rates reduces
//! the quality of the produced sound.  For the best quality sound, the system
//! should be clocked at 120 MHz.
//!
//! \note In order for the sound driver to function properly, the sound driver
//! interrupt handler (SoundIntHandler()) must be installed into the vector
//! table for the timer 5 subtimer A interrupt.
//!
//! \return None.
//
//*****************************************************************************
void
SoundInit(uint32_t ui32SysClock)
{
    //
    // Enable the peripherals used by the sound driver.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5);

    //
    // Compute the PWM period based on the system clock.
    //
    g_sSoundState.ui32Period = ui32SysClock / 64000;

    //
    // Set the default volume.
    //
    g_sSoundState.i32Volume = 255;

    //
    // Configure the timer to run in PWM mode.
    //
    if((HWREG(TIMER5_BASE + TIMER_O_CTL) & TIMER_CTL_TBEN) == 0)
    {
        TimerConfigure(TIMER5_BASE, (TIMER_CFG_SPLIT_PAIR |
                                         TIMER_CFG_A_PWM |
                                         TIMER_CFG_B_PERIODIC));
    }
    TimerLoadSet(TIMER5_BASE, TIMER_A, g_sSoundState.ui32Period - 1);
    TimerMatchSet(TIMER5_BASE, TIMER_A, g_sSoundState.ui32Period);
    TimerControlLevel(TIMER5_BASE, TIMER_A, true);
    HWREG(TIMER5_BASE + TIMER_O_TAMR) |= TIMER_TAMR_TAMRSU;

    //
    // Configure the timer to generate an interrupt at every time-out event.
    //
    TimerIntEnable(TIMER5_BASE, TIMER_CAPA_EVENT);

    //
    // Enable the timer.  At this point, the timer will generate an interrupt
    // every 15.625 us.
    //
    TimerEnable(TIMER5_BASE, TIMER_A);
    IntEnable(INT_TIMER5A);

    //
    // Clear the sound flags.
    //
    g_sSoundState.ui32Flags = 0;
}
示例#19
0
//*****************************************************************************
//
//! This function trigger in a PE3 a pulse of 10 microseconds
//!
//! This function generate a pulse in the pin PE3 during 10 microseconds.
//!
//! If you want to use other pin, change the function.
//!
//! \return none.
//
//*****************************************************************************
void
TOFTrigger(){

	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

	TimerDisable(TIMER1_BASE,TIMER_A);
	uint32_t frecCTL = SysCtlClockGet();
	int32_t tick4us = (int32_t ) (frecCTL * 10e-6);
	TimerConfigure(TIMER1_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_ONE_SHOT);
	TimerLoadSet(TIMER1_BASE,TIMER_A,tick4us);
	TimerMatchSet(TIMER1_BASE,TIMER_A,0);
	TimerIntRegister(TIMER1_BASE,TIMER_A,HandleTrigger );
	TimerIntEnable(TIMER1_BASE,TIMER_TIMA_TIMEOUT);
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_3,GPIO_PIN_3);
	TimerEnable(TIMER1_BASE,TIMER_A);

}
示例#20
0
//*****************************************************************************
//
//! Sets the volume of the music/sound effect playback.
//!
//! \param ulPercent is the volume percentage, which must be between 0%
//! (silence) and 100% (full volume), inclusive.
//!
//! This function sets the volume of the sound output to a value between
//! silence (0%) and full volume (100%).
//!
//! \return None.
//
//*****************************************************************************
void
SoundVolumeSet(unsigned long ulPercent)
{
    //
    // Check the argument.
    //
    ASSERT(ulPercent <= 100);

    //
    // Set the timer match value based on the volume.
    //
    TimerMatchSet(TIMER2_BASE, TIMER_A, ulPercent * 26);

    //
    // Save the volume for future use (such as un-muting).
    //
    g_ucVolume = ulPercent;
}
示例#21
0
void bspBuzzerEnable(int freq)
{
  // Stop timer
  TimerDisable(GPT0_BASE, TIMER_A);
  
  if (freq > 0)
  {
    uint32_t load;
    
    load = (48000000 / freq );
    // Timer A; freq 48 MHz / TM_LOAD_XXXXHZ
    TimerLoadSet(GPT0_BASE, TIMER_A, load);  
    TimerMatchSet(GPT0_BASE, TIMER_A, load / 2 );    // 50 per cent duty cycle
    
    // Start timer
    TimerEnable(GPT0_BASE, TIMER_A);
  }
}
示例#22
0
/***************************************************************************************************
 * @fn      halTimer1SetChannelDuty
 *
 * @brief   Set duty for Timer1 PWM
 *
 * @param   channel - timer channel to control
 *          percent - dutycycle in promill
 *
 * @return  None
 ***************************************************************************************************/
void halTimer1SetChannelDuty (uint8 channel, uint16 promill)
{
  if(channel == 0)
  {
    uint32 timerAMatch = (PWM_PERIOD * (100-promill)) / 100;
    
    if(timerAMatch == PWM_PERIOD)
    {
      timerAMatch--;
    }
    
    //
    // The PWM counter counts down thus calculate actual match count based
    // on duty cycle as: period*(100-DucyCycle)/100
    //
    TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, timerAMatch); 
  }
}
示例#23
0
//*****************************************************************************
//
//! \biref The main example function
//!
//! \return  none
//
//*****************************************************************************
void OneSecondClock(void)
{
    SysCtlHClockSet(SYSCTL_XTAL_12MHZ | SYSCTL_OSC_MAIN);
    //
    // Set the timer clock
    //
    SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_TMR0_S_EXT12M);

    //
    // Enable tiemr0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TMR0);

    //
    // Clear the flag first
    //
    TimerIntClear(TIMER0_BASE, TIMER_INT_MATCH);
    while(TimerIntStatus(TIMER0_BASE, TIMER_INT_MATCH));

    //
    // Config as One shot mode
    //
    TimerInitConfig(TIMER0_BASE, TIMER_MODE_PERIODIC, 1000);
    TimerPrescaleSet(TIMER0_BASE, 91);
    TimerMatchSet(TIMER0_BASE, 0x1ffff);
    TimerIntEnable(TIMER0_BASE, TIMER_INT_MATCH);

    //
    // Start the timer
    //
    TimerStart(TIMER0_BASE);

    //
    // One shot mode test.
    //
    while(1)
    {
        //
        // wait until the timer data register reach equel to compare register
        //
        while(!TimerIntStatus(TIMER0_BASE, TIMER_INT_MATCH));
        TimerIntClear(TIMER0_BASE, TIMER_INT_MATCH);
    }
}
示例#24
0
static void pwm_set_width(uint32_t pulse_duration, uint8_t pulse_unit) {
	   uint32_t pwm_period;
	   switch(pulse_unit) {
		   case PULSE_100NS:
			   pwm_period = tics_100ns*pulse_duration;
			   break;
		   case PULSE_MS:
			   pwm_period = tics_ms*pulse_duration;
			   break;
		   case PULSE_US:
		   default:
			   pwm_period = tics_us*pulse_duration;
			   break;
	   }

	   uint16_t pwm_extender = pwm_period >> 16;
	   pwm_period &= 0xFFFF;
	   //uint8_t pwm_extender = 0;

	   TimerPrescaleMatchSet(TIMER3_BASE, TIMER_A, pwm_extender);
       TimerMatchSet(TIMER3_BASE, TIMER_A, pwm_period);
}
示例#25
0
文件: main.c 项目: trungkiena6/Tiva_C
int main (void) 
{ 
  // Set the clock  
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	// Set output
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1);
	
	// Configure PF1 as T0CCP1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	
	GPIOPinConfigure(GPIO_PB6_T0CCP0);
	GPIOPinTypeTimer(GPIO_PORTB_BASE,GPIO_PIN_6);
	
	// Configure Timer
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	
	TimerConfigure(TIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER0_BASE,TIMER_A,SysCtlClockGet());
	TimerMatchSet(TIMER0_BASE,TIMER_A,SysCtlClockGet()/2);
	TimerControlLevel(TIMER0_BASE,TIMER_A,false);
	TimerEnable(TIMER0_BASE,TIMER_A);
	
} 
示例#26
0
//*****************************************************************************
//
// Configure Timer1B as a 16-bit PWM with a duty cycle of 66%.
//
//*****************************************************************************
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);

    //
    // The Timer1 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

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

    //
    // Configure the GPIO pin muxing for the Timer/CCP function.
    // This is only necessary if your part supports GPIO pin function muxing.
    // Study the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using
    //
    GPIOPinConfigure(GPIO_PE4_CCP3);

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

    //
    // Configure the ccp settings for CCP pin.  This function also gives
    // control of these pins to the SSI hardware.  Consult the data sheet to
    // see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeTimer(GPIO_PORTE_BASE, GPIO_PIN_4);

    //
    // Display the example setup on the console.
    //
    UARTprintf("16-Bit Timer PWM ->");
    UARTprintf("\n   Timer = Timer1B");
    UARTprintf("\n   Mode = PWM");
    UARTprintf("\n   Duty Cycle = 66%%\n");
    UARTprintf("\nGenerating PWM on CCP3 (PE4) -> ");

    //
    // Configure Timer1B as a 16-bit periodic timer.
    //
    TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR |
                   TIMER_CFG_B_PWM);

    //
    // Set the Timer1B load value to 50000.  For this example a 66% duty
    // cycle PWM signal will be generated.  From the load value (i.e. 50000)
    // down to match value (set below) the signal will be high.  From the
    // match value to 0 the timer will be low.
    //
    TimerLoadSet(TIMER1_BASE, TIMER_B, 50000);

    //
    // Set the Timer1B match value to load value / 3.
    //
    TimerMatchSet(TIMER1_BASE, TIMER_B, TimerLoadGet(TIMER1_BASE, TIMER_B) / 3);

    //
    // Enable Timer1B.
    //
    TimerEnable(TIMER1_BASE, TIMER_B);

    //
    // Loop forever while the Timer1B PWM runs.
    //
    while(1)
    {
        //
        // Print out indication on the console that the program is running.
        //
        PrintRunningDots();
    }
}
示例#27
0
文件: xtimertest2.c 项目: 0xc0170/cox
//*****************************************************************************
//
//! \brief xtimer 001 test execute main body.
//!
//! \return None.
//
//*****************************************************************************
static void xTimer001Execute(void)
{
    unsigned long ulTemp;
    unsigned long ulBase;
    int i, j ;
    
    //
    // One shot mode test.
    //
    for(i = 0; i < 4; i++)
    {
        ulBase = ulTimerBase[i];
        
        //
        // Clear the flag first
        //
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        while(TimerIntStatus(ulBase, TIMER_INT_MATCH));  
        
        // 
        // Config as One shot mode
        //        
        TimerInitConfig(ulBase, TIMER_MODE_ONESHOT, 1000);
        
        TimerIntEnable(ulBase, TIMER_INT_MATCH);
        xIntEnable(ulTimerIntID[i]);
        xTimerIntCallbackInit(ulBase, TimerCallbackFunc[i]); 
        TimerStart(ulBase);
        
        //
        // wait until the timer data register reach equel to compare register
        //
        TestAssertQBreak("a","One shot mode Intterrupt test fail", -1);
        xIntDisable(ulTimerIntID[i]);
    }  
    
    //
    // Periodic mode
    //
    for(i = 0; i < 4; i++)
    {
        ulBase = ulTimerBase[i];
        ulTemp = 0;
        
        //
        // Clear the flag first
        //
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        
        //
        // Config as periodic mode
        //
        TimerInitConfig(ulBase, TIMER_MODE_PERIODIC, 1000);    
        TimerIntEnable(ulBase, TIMER_INT_MATCH);
        TimerStart(ulBase);
        
        // 
        // wait the periodic repeat 5 times 
        //
        for (j = 0; j < 5; j++)
        {
            while(!TimerIntStatus(ulBase, TIMER_INT_MATCH));      
            ulTemp++;
            if(ulTemp == 5)
            {
                break;
            }
            TimerIntClear(ulBase, TIMER_INT_MATCH);
        }
        TestAssert(ulTemp == 5,
                   "xtimer mode \" periodic test\" error!");
        TimerStop(ulBase);       
    }
    
    //
    // Toggle mode test
    //
    for(i = 0; i < 4; i++)
    {
        ulBase = ulTimerBase[i];
        ulTemp = 0;
        
        //
        // Clear the Int flag first
        //
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        
        //
        // Config as toggle mode
        //
        TimerInitConfig(ulBase, TIMER_MODE_PERIODIC, 1000);    
        TimerIntEnable(ulBase, TIMER_INT_MATCH);
        TimerStart(ulBase);
        
        // 
        // wait the toggle repeat 5 times 
        //
        for (j = 0; j < 5; j++)
        {
            while(!TimerIntStatus(ulBase, TIMER_INT_MATCH));      
            ulTemp++;
            if(ulTemp == 5)
            {
                break;
            }
            TimerIntClear(ulBase, TIMER_INT_MATCH);
        }
        TestAssert(ulTemp == 5,
                   "xtimer mode \" Toggle mode test\" error!");
        TimerStop(ulBase);       
    }
    
    //
    // Continuous mode test.
    //
    for(i = 0; i < 4; i++)
    {
        ulBase = ulTimerBase[i];
        ulTemp = 0;
        
        //
        // Clear the flag first
        //
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        while(TimerIntStatus(ulBase, TIMER_INT_MATCH));  
        
        // 
        // Config as One shot mode
        //        
        TimerInitConfig(ulBase, TIMER_MODE_CONTINUOUS, 10000);
        TimerMatchSet(ulBase, 10);
        TimerIntEnable(ulBase, TIMER_INT_MATCH);
        TimerStart(ulBase);
        
        //
        // Delay some time to wait the count register reach to 200.
        //
        xSysCtlDelay(100);
        if(TimerIntStatus(ulBase, TIMER_INT_MATCH) == xtrue)
        {
            ulTemp++;
        }
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        TimerMatchSet(ulBase, 2000);
        
        //
        // Wait until reach the 1000
        //
        //while(!TimerIntStatus(ulBase, TIMER_INT_MATCH));       
        xSysCtlDelay(10000);
        if(TimerIntStatus(ulBase, TIMER_INT_MATCH) == xtrue)
        {
            ulTemp++;
        }
        TimerIntClear(ulBase, TIMER_INT_MATCH);
        
        TestAssert(ulTemp == 2,
           "xtimer mode \" Continuous mode test\" error!");
        TimerStop(ulBase);     
        xIntDisable(ulTimerIntID[i]);
   
    }  
    
}
示例#28
0
文件: main.c 项目: arduic/GitHub
/**********************************************************************************************
 *								Main
 *********************************************************************************************/
void main(void) {

	//After tomorrow's test flight. FOR THE LOVE OF GOD MOVE THESE INITALIZATIONS TO FUNCTIONS
	/**********************************************************************************************
	 *								Local Variables
	 *********************************************************************************************/

	unsigned long ultrasonic = 0;

	// Enable lazy stacking for interrupt handlers.  This allows floating-point
	// instructions to be used within interrupt handlers, but at the expense of
	// extra stack usage.
	FPULazyStackingEnable();

	//Set the clock speed to 80MHz aka max speed
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

	/*unsigned long test[2];
	test[0] = 180;
	test[1] = 10;
	short bob[1];
	bob[0] = ((char)test[0]<<8)|(char)test[1];
	float jimmy = (short)(((char)test[0]<<8)|(char)test[1]);
	jimmy /= 26;*/

	/**********************************************************************************************
	 *								Peripheral Initialization Awake
	 *********************************************************************************************/
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);	//Turn on GPIO communication on F pins for switches
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);	//Turn on GPIO for ADC
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);	//Turn on GPIO for the PWM comms
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);	//Turn on GPIO for LED test
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);   	//Turn on GPIO for UART
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);	//Turn on Timer for PWM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);	//Turn on Timer for PWM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);	//Turn on Timer for PWM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);	//Turn on Timer for PWM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);		//Turn on I2C communication I2C slot 0
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);	//Turn on the UART com
	SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG);		//Turn on the watchdog timer. This is a risky idea but I think it's for the best.


	/**********************************************************************************************
	 *								Peripheral Initialization Sleep
	 *********************************************************************************************/
	/*SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF);	//This sets what peripherals are still enabled in sleep mode while UART would be nice, it would require the clock operate at full speed which is :P
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOB);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOA);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER0);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER1);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER2);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER3);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_SSI0);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_I2C1);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_ADC);
	SysCtlPeripheralClockGating(true); 		//I'm not sure about this one maybe remove it
	 */

	/**********************************************************************************************
	 *										PWM Initialization
	 *********************************************************************************************/
	SysCtlDelay((SysCtlClockGet() / (1000 * 3))*100);		//This shouldn't be needed will test to remove
	//PWM pin Setup
	//PWM 0 on GPIO PB6, PWM 1 on pin 4... etc
	GPIOPinConfigure(GPIO_PB6_T0CCP0);	//Pitch -		yaw +
	GPIOPinConfigure(GPIO_PB4_T1CCP0);	//Pitch +		yaw +
	GPIOPinConfigure(GPIO_PB0_T2CCP0);	//Roll -		yaw -
	GPIOPinConfigure(GPIO_PB2_T3CCP0);	//Roll +		yaw -
	GPIOPinTypeTimer(GPIO_PORTB_BASE, (GPIO_PIN_6|GPIO_PIN_4|GPIO_PIN_0|GPIO_PIN_2));

	//Prescale the timers so they are slow enough to work with the ESC
	TimerPrescaleSet(TIMER0_BASE,TIMER_A,2);
	TimerPrescaleSet(TIMER1_BASE,TIMER_A,2);
	TimerPrescaleSet(TIMER2_BASE,TIMER_A,2);
	TimerPrescaleSet(TIMER3_BASE,TIMER_A,2);

	//Basic LED Out Test	Not sure why this is here look into			This just turns on an LED that I don't have plugged in. should remove later
	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3);
	GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0xFF);

	//GPIOPinTypeGPIOOutputOD(GPIO_PORTB_BASE,GPIO_PIN_0);


	//Timers Setup for PWM and the load for the countdown
	TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1);
	TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod -1);
	TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER2_BASE, TIMER_A, (ulPeriod -1));
	TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER3_BASE, TIMER_A, ulPeriod -1);

	//TimerPrescaleSet(TIMER2_BASE, TIMER_A, extender1);
	//TimerLoadSet(TIMER2_BASE, TIMER_A, period1);
	//Set the match which is when the thing will pull high
	TimerMatchSet(TIMER0_BASE, TIMER_A, 254);  //Duty cycle = (1-%desired)*1000 note this means this number is percent low not percent high
	TimerMatchSet(TIMER1_BASE, TIMER_A, 254);
	TimerMatchSet(TIMER2_BASE, TIMER_A, 254);
	TimerMatchSet(TIMER3_BASE, TIMER_A, 254);

	//TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, extender2);
	//TimerMatchSet(TIMER2_BASE, TIMER_A, period2);

	//Enable the timers
	TimerEnable(TIMER0_BASE, TIMER_A);
	TimerEnable(TIMER1_BASE, TIMER_A);
	TimerEnable(TIMER2_BASE, TIMER_A);
	TimerEnable(TIMER3_BASE, TIMER_A);


	/**********************************************************************************************
	 *									onboard	Chip interrupt Initialization
	 *********************************************************************************************/
	//These two buttons are used to reset the bluetooth module in case of disconnection
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);	//RGB LED's
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00);
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;				//Sw1 (PF4) is unaviable unless you make it only a GPIOF input via these commands
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x1;
	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4);	//Onboard buttons (PF0=Sw2,PF4=Sw1
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);		//This will make the buttons falling edge (a press pulls them low)
	//void (*functionPtr)(void) = &onBoardInteruptHandle;
	GPIOPortIntRegister(GPIO_PORTF_BASE, onBoardInteruptHandle);	//set function to handle interupt
	GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4,GPIO_FALLING_EDGE);		//Set the interrupt as falling edge
	GPIOPinIntEnable(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4);	//Enable the interrupt
	//IntMasterEnable();
	IntEnable(INT_GPIOF);

	/**********************************************************************************************
	 *								UART Initialization
	 *********************************************************************************************/
	//Unlock PD7
	HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;
	HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80;

	GPIOPinConfigure(GPIO_PD7_U2TX);			//Set PD7 as TX
	GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_7);

	GPIOPinConfigure(GPIO_PD6_U2RX);			//Set PD6 as RX
	GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6);

	UARTConfigSetExpClk(UART2_BASE,SysCtlClockGet(),115200,UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE);  //I believe the Xbee defaults to no parity I do know it's 9600 baud though, changed to 115200 for bluetooth reasons

	UARTFIFOLevelSet(UART2_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8);	//Set's how big the fifo needs to be in order to call the interrupt handler, 2byte
	UARTIntRegister(UART2_BASE,Uart2IntHandler);	//Regiester the interrupt handler
	UARTIntClear(UART2_BASE, UART_INT_TX | UART_INT_RX);	//Clear the interrupt
	UARTIntEnable(UART2_BASE, UART_INT_TX | UART_INT_RX);	//Enable the interrupt to trigger on both TX and RX event's. Could possibly remove TX

	UARTEnable(UART2_BASE);	//Enable UART
	IntEnable(INT_UART2);	//Second way to enable handler not sure if needed using anyway

	/**********************************************************************************************
	 *								I2C Initialization
	 *********************************************************************************************/
	//Serious credit to the man who made the Arduino version of this. he gave me addresses and equations. Sadly Arduino obfuscates what really is happening
	//Link posted on blog page
	//gyro address = 0x68 not 0x69
	GPIOPinConfigure(GPIO_PA7_I2C1SDA);
	GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);	//Set GPA7 as SDA

	GPIOPinConfigure(GPIO_PA6_I2C1SCL);
	GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);	//Set GPA6 as SCL

	I2CMasterInitExpClk(I2C1_MASTER_BASE,SysCtlClockGet(),false);	//I think it operates at 100kbps
	I2CMasterEnable(I2C1_MASTER_BASE);
	//Initalize the accelerometer			Address = 0x53
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02);
	UARTSend(0xAB);
	I2CTransmit(0x53,0x2D,0x00);
	I2CTransmit(0x53,0x2D,0x10);
	I2CTransmit(0x53,0x2D,0x08);

	//Initalize the gyroscope				Address = 0x68
	I2CTransmit(0x68,0x3E,0x00);
	I2CTransmit(0x68,0x15,0x07);
	I2CTransmit(0x68,0x16,0x1E);
	I2CTransmit(0x68,0x17,0x00);
	UARTSend(0xAC);

	/**********************************************************************************************
	 *								SysTick Initialization
	 *********************************************************************************************/
	SysTickIntRegister(SysTickIntHandler);
	SysTickIntEnable();

	SysTickPeriodSet((SysCtlClockGet() / (1000 * 3))*timeBetweenCalculations);	//This sets the period for the delay. the last num is the num of milliseconds
	SysTickEnable();

	/**********************************************************************************************
	 *								Watchdog Initialization
	 *********************************************************************************************/
	WatchdogReloadSet(WATCHDOG_BASE, 0xFEEFEEFF);	//Set the timer for a reset
	WatchdogIntRegister(WATCHDOG_BASE,WatchdogIntHandler);			//Enable interrupt
	WatchdogIntClear(WATCHDOG_BASE);
	WatchdogIntEnable(WATCHDOG_BASE);
	WatchdogEnable(WATCHDOG_BASE);	//Enable the actual timer
	IntEnable(INT_WATCHDOG);

	/**********************************************************************************************
	 *								Preflight motor inialization maybe not necessary not going to test
	 *********************************************************************************************/

	PWMSet(TIMER0_BASE,998);
	PWMSet(TIMER1_BASE,998);
	PWMSet(TIMER2_BASE,998);
	PWMSet(TIMER3_BASE,998);
	recievedCommands[0]=253;
	SysCtlDelay((SysCtlClockGet() / (1000 * 3))*100);	//Very important to ensure motor see's a start high (998 makes 0 sense but it works so shhhh don't tell anyone)
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06);

	while(1){
		WatchdogReloadSet(WATCHDOG_BASE, 0xFEEFEEFF);	//Feed the dog a new time

		//UARTSend(recievedCommands[0]);
		//SysCtlDelay(50000);
		//Set 4 PWM Outputs

		//Get Acc data
		I2CRead(0x53,0x32,6,quadAcc);			//Address blah blah 2 for each axis
		rawAccToG(quadAcc,RwAcc);
		/*GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x04);		//Blue

		//Get Gyro data
		/**************************************
		  Gyro ITG-3200 I2C
		  registers:
		  temp MSB = 1B, temp LSB = 1C
		  x axis MSB = 1D, x axis LSB = 1E
		  y axis MSB = 1F, y axis LSB = 20
		  z axis MSB = 21, z axis LSB = 22
		 *************************************/
		I2CRead(0x68,0x1B,8,quadGyro);			//Address blah blah 2 for each axis + 2 for temperature. why. because why not
		rawGyroToDegsec(quadGyro,Gyro_ds);
		//GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02);		//Red

		//Get the actual angles in XYZ. Store them in RwEst
		//getInclination(RwAcc, RwEst, RwGyro, Gyro_ds, Awz);
		//After this function is called RwEst will hold the roll pitch and yaw
		//RwEst will be returned in PITCH, ROLL, YAW 0, 1, 2 remember this order very important. Little obvious but yaw is worthless

		/*if(RwEst[1]>0.5){
			GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06);		//Red Blue, Correct data read in
		}else{
			GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x0A);		//Red Green, The correct data is not there
		}*/
		/*GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06);		//Red Blue, Correct data read in
		float test=RwAcc[0]*100;		//These two commands work
		char temp = (char)test;
		//UARTSend((char)(RwAcc[0])*100);	//This one does not
		UARTSend(temp);
		//UARTSend((char)(RwAcc[1])*100);

		UARTSend(0xAA);
		SysCtlDelay((SysCtlClockGet() / (1000 * 3))*1);
		 */
	}

}
示例#29
0
//*****************************************************************************
//
// This example application demonstrates the use of the timers to generate
// periodic interrupts.
//
//*****************************************************************************
int
main(void)
{
		unsigned long ulPeriod, dutyCycle;	// En ejemplo

    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

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

// Agregado Ejemplo	
		// 40 MHz system clock
    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL| SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);	
	
		ulPeriod = 1000;
    dutyCycle = 250;

    // Turn off LEDs 
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);

		// Configure PB6 as T0CCP0
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinConfigure(GPIO_PB6_T0CCP0);
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);

		// Configure timer
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
    TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1);
    TimerMatchSet(TIMER0_BASE, TIMER_A, dutyCycle); // PWM
    TimerEnable(TIMER0_BASE, TIMER_A);
// Fin Agregado
	
    //
    // Initialize the UART and write status.
    //
    ConfigureUART();

    UARTprintf("\033[2JTimers example\n");
    UARTprintf("T1: 0  T2: 0");

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
//    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Enable the GPIO pins for the LED (PF1 & PF2).
    //
//    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_1);


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

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

    //
    // Configure the two 32-bit periodic timers.
    //
//    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
//    ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
//    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet());
//    ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / 2);

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

    //
    // Enable the timers.
    //
//    ROM_TimerEnable(TIMER0_BASE, TIMER_A);
//    ROM_TimerEnable(TIMER1_BASE, TIMER_A);

    //
    // Loop forever while the timers run.
    //
    while(1)
    {
    }
}
示例#30
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
  
  static struct etimer timer;
  static int count;
  PROCESS_BEGIN();
/*  i2c_init(I2C_SCL_PORT, I2C_SCL_PIN, I2C_SDA_PORT, I2C_SDA_PIN, 
             I2C_SCL_NORMAL_BUS_SPEED);*/

  etimer_set(&timer, CLOCK_CONF_SECOND * 1);
  count = 0;
  relay_enable(PORT_D,LED_RELAY_PIN);
 
   while(1) {

    PROCESS_WAIT_EVENT();

    if(ev == PROCESS_EVENT_TIMER) {
        
      if(count %2 == 0){
		//relay_on(PORT_D,LED_RELAY_PIN);
	int delayIndex;

  	unsigned int pwmDutyCycle = 0x0000;

 

    //

    // Initialize the interrupt counter.

    //

    int g_ui32Counter = 0;

 

   

    //

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

    // (no ext 32k osc, no internal osc)

    //

    SysCtrlClockSet(false, false, 32000000);

 

    //

    // Set IO clock to the same as system clock

    //

    SysCtrlIOClockSet(32000000);   

   

    //

    // The Timer0 peripheral must be enabled for use.

    //

    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);   

 

    //

    // 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 example setup on the console.

    //

    UARTprintf("16-Bit Timer PWM ->");

    UARTprintf("\n   Timer = Timer0B");

    UARTprintf("\n   Mode = PWM with variable duty cycle");

 

    //

    // Configure GPTimer0A as a 16-bit PWM Timer.

    //

    TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR |

                   GPTIMER_CFG_A_PWM | GPTIMER_CFG_B_PWM);

 

    //

    // Set the GPTimer0B load value to 1sec by setting the timer load value

    // to SYSCLOCK / 255. This is determined by:

    //      Prescaled clock = 16Mhz / 255

    //      Cycles to wait = 1sec * Prescaled clock

    TimerLoadSet(GPTIMER0_BASE, GPTIMER_A, SysCtrlClockGet() / 4000);       

 

    TimerControlLevel(GPTIMER0_BASE, GPTIMER_A, false);

   

    // Configure GPIOPortA.0 as the Timer0_InputCapturePin.1

    IOCPinConfigPeriphOutput(GPIO_A_BASE, GPIO_PIN_0, IOC_MUX_OUT_SEL_GPT0_ICP1);

       

    // Tell timer to use GPIOPortA.0

    // Does Direction Selection and PAD Selection

    GPIOPinTypeTimer(GPIO_A_BASE, GPIO_PIN_0);

    

    //

    // Enable processor interrupts.

    //

    IntMasterEnable();    

 

    //

    // Enable GPTimer0B.

    //

    TimerEnable(GPTIMER0_BASE, GPTIMER_A);   

 

    UARTprintf("\n");

    //

    // Loop forever while the Timer0B runs.

    //

    while(1)

    {

      for (delayIndex = 0; delayIndex < 100000; delayIndex++);

     

      pwmDutyCycle += 0x0F;

      pwmDutyCycle &= 0xFFFF;

     

      TimerMatchSet(GPTIMER0_BASE, GPTIMER_A, pwmDutyCycle);

     

      UARTprintf("PWM DC Value: %04X -- %04X -- %04X\r",

                      pwmDutyCycle,

                      TimerValueGet(GPTIMER0_BASE, GPTIMER_A),

                      TimerMatchGet(GPTIMER0_BASE, GPTIMER_A) );

     

    	}

	



		
		  //SENSORS_ACTIVATE(cc2538_temp_sensor);
                  // printf( "%d is temp\n",cc2538_temp_sensor.value); 
		

      	}
      	else {  
       		//relay_off(PORT_D,LED_RELAY_PIN);
      	} 
/*	if(count %2 == 0)
	{	
		relay_toggle(PORT_D,LED_RELAY_PIN);
		relay_status(PORT_D,LED_RELAY_PIN);
	}
*/
	count ++;
	etimer_reset(&timer);
    }
  }
  
  
  PROCESS_END();
}