Exemple #1
0
void control_init() {
  //// laser control
  // Setup Timer0 for a 488.28125Hz "phase correct PWM" wave (assuming a 16Mhz clock)
  // Timer0 can pwm either PD5 (OC0B) or PD6 (OC0A), we use PD6
  // TCCR0A and TCCR0B are the registers to setup Timer0
  // see chapter "8-bit Timer/Counter0 with PWM" in Atmga328 specs
  // OCR0A sets the duty cycle 0-255 corresponding to 0-100%
  // also see: http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

	GPIOPinTypeGPIOOutput(LASER_EN_PORT, LASER_EN_MASK);
	GPIOPinWrite(LASER_EN_PORT, LASER_EN_MASK, LASER_EN_INVERT);

	// Configure timer
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(LASER_TIMER, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_ONE_SHOT);
	TimerControlLevel(LASER_TIMER, TIMER_A, 1);

	// PPI = PWMfreq/(feedrate/MM_PER_INCH/60)

	// Set PPI Pulse timer
	ppi_cycles = SysCtlClockGet() / 1000 * CONFIG_LASER_PPI_PULSE_MS;
	ppi_divider = ppi_cycles >> 16;
	ppi_cycles /= (ppi_divider + 1);
	TimerPrescaleSet(LASER_TIMER, TIMER_B, ppi_divider);
	TimerLoadSet(LASER_TIMER, TIMER_B, ppi_cycles);

	// Setup ISR
	TimerIntRegister(LASER_TIMER, TIMER_B, laser_isr);
	TimerIntEnable(LASER_TIMER, TIMER_TIMB_TIMEOUT);
    IntPrioritySet(INT_TIMER0B, CONFIG_LASER_PRIORITY);

	// Set PWM refresh rate
	laser_cycles = SysCtlClockGet() / CONFIG_LASER_PWM_FREQ; /*Hz*/
	laser_divider = laser_cycles >> 16;
	laser_cycles /= (laser_divider + 1);

	// Setup Laser PWM Timer
	TimerPrescaleSet(LASER_TIMER, TIMER_A, laser_divider);
	TimerLoadSet(LASER_TIMER, TIMER_A, laser_cycles);
	TimerPrescaleMatchSet(LASER_TIMER, TIMER_A, laser_divider);
	laser_intensity = 0;

	// Set default value
	control_laser_intensity(0);
	control_laser(0, 0);

	TimerEnable(LASER_TIMER, TIMER_A);

	// ToDo: Map the timer ccp pin sensibly
	GPIOPinConfigure(GPIO_PB6_T0CCP0);
	GPIOPinTypeTimer(LASER_PORT, (1 << LASER_BIT));

	//// air and aux assist control
	GPIOPinTypeGPIOOutput(ASSIST_PORT, ASSIST_MASK);
	control_air_assist(false);
	control_aux1_assist(false);
}
Exemple #2
0
/*
    Initializes PWM timers for ESC control
    \param none
    
    Motor 1: PB4 using TIMER1_A
    Motor 2: PB5 using TIMER1_B
    Motor 3: PB0 using TIMER2_A
    Motor 4: PB1 using TIMER2_B

    \return none
*/
void initPWM()
{
    // Configure output pins
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    GPIOPinConfigure(GPIO_PB4_T1CCP0);
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_4);
    GPIOPinConfigure(GPIO_PB5_T1CCP1);
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5);  

    GPIOPinConfigure(GPIO_PB0_T2CCP0);
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0);
    GPIOPinConfigure(GPIO_PB1_T2CCP1);
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_1); 

    // Configure the two timers as half width (16bit) pwm (though we get 24 bits with the "prescale")
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);  
    TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM);
    TimerControlLevel(TIMER1_BASE, TIMER_BOTH, true);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);  
    TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM);
    TimerControlLevel(TIMER2_BASE, TIMER_BOTH, true);

    //calculate pulse repetition rate
    uint32_t cycles_per_interval = SysCtlClockGet() / MOTORUPDATE /*Hz*/;
    uint32_t periodl = cycles_per_interval;
    uint8_t periodh = periodl >> 16;
    periodl &= 0xFFFF;


    //set pulse repetition rate
    TimerPrescaleSet(TIMER1_BASE, TIMER_A, periodh);
    TimerLoadSet(TIMER1_BASE, TIMER_A, periodl);
    TimerPrescaleSet(TIMER1_BASE, TIMER_B, periodh);
    TimerLoadSet(TIMER1_BASE, TIMER_B, periodl);

    TimerPrescaleSet(TIMER2_BASE, TIMER_A, periodh);
    TimerLoadSet(TIMER2_BASE, TIMER_A, periodl);
    TimerPrescaleSet(TIMER2_BASE, TIMER_B, periodh);
    TimerLoadSet(TIMER2_BASE, TIMER_B, periodl); 

    //set all motors to zero
    motorSet(1,0);
    motorSet(2,0);
    motorSet(3,0);
    motorSet(4,0);

    //enable timers
    TimerEnable(TIMER1_BASE, TIMER_A);
    TimerEnable(TIMER1_BASE, TIMER_B);
    TimerEnable(TIMER2_BASE, TIMER_A);
    TimerEnable(TIMER2_BASE, TIMER_B);
}
Exemple #3
0
//计时器0初始化
void Init_Timer_A(void)
{
	//使能TIMER0模块
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

	//禁止定时器A
	//TimerDisable(unsigned long ulBase, unsigned long ulTimer)
	TimerDisable(TIMER0_BASE,TIMER_A);

	//配置TIMER0模块工作在双16位定时器,周期工作模式
	//TimerConfigure(unsignedlongulBase,unsignedlongulConfig)
	TimerConfigure(TIMER0_BASE,TIMER_CFG_16_BIT_PAIR|TIMER_CFG_A_PERIODIC);

	//配置8位分频器
	//TimerPrescaleSet(unsigned long ulBase, unsigned long ulTimer, unsigned long ulValue)
	TimerPrescaleSet(TIMER0_BASE,TIMER_A,100);

	//配置定时器周期
	//TimerLoadSet(unsigned long ulBase, unsigned long ulTimer, unsigned long ulValue)
	TimerLoadSet(TIMER0_BASE,TIMER_A,50000);

	//使能时钟溢出中断
	//TimerIntEnable(unsigned long ulBase,unsigned long ulIntFlags)
	TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);

	//在NVIC中使能时钟中断
	IntEnable(INT_TIMER0A);

	//使能TIMER A
	//TimerEnable(unsigned long ulBase, unsigned long ulTimer)
	TimerEnable(TIMER0_BASE,TIMER_A);
}
Exemple #4
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);
}
Exemple #5
0
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! \param ui32SysClock is the frequency of the system clock.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC 0 sample sequence 3
//! - Timer 5 subtimer B
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(uint32_t ui32SysClock)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ui32TSState = TS_STATE_INIT;

    //
    // There is no touch screen handler initially.
    //
    g_pfnTSHandler = 0;

    //
    // Enable the peripherals used by the touch screen interface.
    //
   SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
   SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5);

    //
    // Configure the ADC sample sequence used to read the touch screen reading.
    //
   ADCHardwareOversampleConfigure(ADC0_BASE, 4);
   ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
   ADCSequenceStepConfigure(ADC0_BASE, 3, 0,
                                 TS_YP_ADC | ADC_CTL_END | ADC_CTL_IE);
   ADCSequenceEnable(ADC0_BASE, 3);

    //
    // Enable the ADC sample sequence interrupt.
    //
   ADCIntEnable(ADC0_BASE, 3);
   IntEnable(INT_ADC0SS3);

    //
    // Configure the timer to trigger the sampling of the touch screen
    // every 2.5 milliseconds.
    //
    if((HWREG(TIMER5_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0)
    {
       TimerConfigure(TIMER5_BASE, (TIMER_CFG_SPLIT_PAIR |
                                         TIMER_CFG_A_PWM |
                                         TIMER_CFG_B_PERIODIC));
    }
   TimerPrescaleSet(TIMER5_BASE, TIMER_B, 255);
   TimerLoadSet(TIMER5_BASE, TIMER_B, ((ui32SysClock / 256) / 400) - 1);
    TimerControlTrigger(TIMER5_BASE, TIMER_B, true);

    //
    // Enable the timer.  At this point, the touch screen state machine will
    // sample and run every 2.5 ms.
    //
   TimerEnable(TIMER5_BASE, TIMER_B);
}
//*****************************************************************************
//
//! Starts playback of a song.
//!
//! \param pusSong is a pointer to the song data structure.
//! \param ulLength is the length of the song data structure in bytes.
//!
//! This function starts the playback of a song or sound effect.  If a song
//! or sound effect is already being played, its playback is canceled and the
//! new song is started.
//!
//! \return None.
//
//*****************************************************************************
void
SoundPlay(const unsigned short *pusSong, unsigned long ulLength)
{
    //
    // Stop the playback of any previous song or sound effect.
    //
    g_pusMusic = 0;

    //
    // Save the length of the song and start the song counter at zero.
    //
    g_usMusicLength = ulLength;
    g_usMusicCount = 0;

    //
    // Save the pointer to the song data.  At this point, the interrupt handler
    // could be called and commence the actual playback.
    //
    g_pusMusic = pusSong;

    //
    // Unmute the audio volume.
    //
    SoundEnable();

    //
    // See if the periodic timer has been initialized.
    //
    if(TimerPrescaleGet(TIMER2_BASE, TIMER_B) != 3)
    {
        //
        // Set the prescale on the periodic timer to 4.
        //
        TimerPrescaleSet(TIMER2_BASE, TIMER_B, 3);

        //
        // Set the periodic timer to produce an interrupt at 200 Hz.
        //
        TimerLoadSet(TIMER2_BASE, TIMER_B, (g_ulSystemClock / (200 * 4)) - 1);

        //
        // Enable the periodic timer.
        //
        TimerEnable(TIMER2_BASE, TIMER_B);

        //
        // Enable the periodic timer's interrupt.
        //
        TimerIntEnable(TIMER2_BASE, TIMER_TIMB_TIMEOUT);
        IntEnable(INT_TIMER2B);
    }
}
Exemple #7
0
/*
 * Initializes timer to trigger an overflow interrupt every 1/SHT1X_CLOCK_HZ seconds.
 * The function also configures uDMA to trigger timer's interrupt handler.
 *
 * If uDMA is enabled and its transaction is in progress it blocks normal interrupt
 * flow of the timer.
 */
void sht1x_timer_init(void)
{
	SysCtlPeripheralEnable(SHT1X_TIMER_PERIPH);

	IntDisable(SHT1X_TIMER_INTERRUPT);
	TimerIntDisable(SHT1X_TIMER_BASE, TIMER_TIMA_TIMEOUT);
	TimerDisable(SHT1X_TIMER_BASE, SHT1X_TIMER);

	TimerConfigure(SHT1X_TIMER_BASE, TIMER_CFG_A_PERIODIC);
	TimerPrescaleSet(SHT1X_TIMER_BASE, SHT1X_TIMER, 0);
	TimerClockSourceSet(SHT1X_TIMER_BASE, TIMER_CLOCK_SYSTEM);
	TimerLoadSet(SHT1X_TIMER_BASE, SHT1X_TIMER, SHT1X_CLK_NR);

	TimerDMAEventSet(SHT1X_TIMER_BASE, TIMER_DMA_TIMEOUT_A);

	TimerIntClear(SHT1X_TIMER_BASE, TIMER_TIMA_TIMEOUT);
	IntEnable(SHT1X_TIMER_INTERRUPT);
}
Exemple #8
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);
    }
}
/*  TIMER_init - initial timer module
*/
void TIMER_init(TIMER_t *timer)
{
	/* Configure timers mode */
	TimerConfigure(timer->base, timer->config);
	if (timer->event_config != 0xffffffff)
		TimerControlEvent(timer->base, timer->ntimer, timer->event_config);
	TimerPrescaleSet(timer->base, timer->ntimer, timer->prescale);
	TimerLoadSet(timer->base, timer->ntimer, timer->value);
	if (timer->handler) {
		TimerIntEnable(timer->base, timer->intermod);
		/* Registe timer handler */
		TimerIntRegister(timer->base, timer->ntimer, timer->handler);
		/* Setup the interrupt for the timer timeouts */
		IntEnable(timer->interrupt);
		/* Enable the timer */
/* 		TimerEnable(timer->base, timer->ntimer); */
	}

}		/* -----  end of function TIMER_init  ----- */
Exemple #10
0
// ************ OS_Init ******************
// initialize operating system, disable interrupts until OS_Launch
// initialize OS controlled I/O: serial, ADC, systick, select switch and timer2
// input: none
// output: non
void OS_Init(void) {

  int i; // Used for indexing

  // Disable interrupts
  OS_DisableInterrupts();

  // Setting the clock to 50 MHz
  SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

  // Initialze peripherals
  UART0_Init();
  ADC_Open();
  Output_Init();

  // Select switch
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
  GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
  GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_RISING_EDGE);
  GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1);

  // Down switch
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
  GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_1);
  GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
  GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_RISING_EDGE);
  GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_1);

  // Initialize Timer2A and Timer2B: Periodic Background Threads
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
  TimerDisable(TIMER2_BASE, TIMER_A | TIMER_B);
  TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
  
  // Initialize Timer0B: Used for time keeping
  TimerDisable(TIMER0_BASE, TIMER_B);
  TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
  TimerIntDisable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
  TimerLoadSet(TIMER0_BASE, TIMER_B, 65535);
  TimerPrescaleSet(TIMER0_BASE, TIMER_B, 5); // One unit is 100ns
  TimerEnable(TIMER0_BASE, TIMER_B);

  // Initialize Timer1A: Used for sleep decrementing
  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
  TimerDisable(TIMER1_BASE, TIMER_A);
  TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
  TimerIntDisable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
  TimerLoadSet(TIMER1_BASE, TIMER_A, 50000); // Every interrupt is 1ms

  // Setting priorities for all interrupts
  // To add more, look up correct names in inc\hw_ints.h

  IntPrioritySet(FAULT_PENDSV, (0x07 << 5));
  IntPrioritySet(FAULT_SYSTICK, (0x06 << 5));

  IntPrioritySet(INT_TIMER1A, (0x02 << 5));
  IntPrioritySet(INT_UART0, (0x03 << 5));
  IntPrioritySet(INT_ADC0SS0, (0x01 << 5));
  IntPrioritySet(INT_ADC0SS3, (0x01 << 5));

  // Initializing TCBs
  for(i = 0; i < MAXTHREADS; i++) {
    tcbs[i].valid = INVALID;
    tcbs[i].blockedState = '\0';
  }

  RunPt = &tcbs[0]; // Thread 0 will run first
}
Exemple #11
0
/**********************************************************************************************
 *								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);
		 */
	}

}