//***************************************************************************** // //! Enable the RGB LED with already configured timer settings //! //! This function or RGBDisable should be called during application //! initialization to configure the GPIO pins to which the LEDs are attached. //! This function enables the timers and configures the GPIO pins as timer //! outputs. //! //! \return None. // //***************************************************************************** void RGBEnable(void) { // // Enable timers to begin counting // TimerEnable(RED_TIMER_BASE, TIMER_BOTH); TimerEnable(GREEN_TIMER_BASE, TIMER_BOTH); TimerEnable(BLUE_TIMER_BASE, TIMER_BOTH); // // Reconfigure each LED's GPIO pad for timer control // GPIOPinConfigure(GREEN_GPIO_PIN_CFG); GPIOPinTypeTimer(GREEN_GPIO_BASE, GREEN_GPIO_PIN); GPIOPadConfigSet(GREEN_GPIO_BASE, GREEN_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD); GPIOPinConfigure(BLUE_GPIO_PIN_CFG); GPIOPinTypeTimer(BLUE_GPIO_BASE, BLUE_GPIO_PIN); GPIOPadConfigSet(BLUE_GPIO_BASE, BLUE_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD); GPIOPinConfigure(RED_GPIO_PIN_CFG); GPIOPinTypeTimer(RED_GPIO_BASE, RED_GPIO_PIN); GPIOPadConfigSet(RED_GPIO_BASE, RED_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD); }
/* 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); }
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*********************************/ }
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); }
// WTimer1A is used to measure the width of the pulses // WTimer1B is used to turn off motors if the connection to the RX is lost void initRX(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1); // Enable Wide Timer1 peripheral SysCtlDelay(2); // Insert a few cycles after enabling the peripheral to allow the clock to be fully activated SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // Enable GPIOC peripheral SysCtlDelay(2); // Insert a few cycles after enabling the peripheral to allow the clock to be fully activated GPIOPinConfigure(GPIO_PC6_WT1CCP0); // Use alternate function GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_6); // Use pin with timer peripheral // Split timers and enable timer A event up-count timer and timer B as a periodic timer TimerConfigure(WTIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP | TIMER_CFG_B_PERIODIC); // Configure WTimer1A TimerControlEvent(WTIMER1_BASE, TIMER_A, TIMER_EVENT_BOTH_EDGES); // Interrupt on both edges TimerIntRegister(WTIMER1_BASE, TIMER_A, CaptureHandler); // Register interrupt handler TimerIntEnable(WTIMER1_BASE, TIMER_CAPA_EVENT); // Enable timer capture A event interrupt IntPrioritySet(INT_WTIMER1A, 0); // Configure Wide Timer 1A interrupt priority as 0 IntEnable(INT_WTIMER1A); // Enable Wide Timer 1A interrupt // Configure WTimer1B timerLoadValue = SysCtlClockGet() / 10 - 1; // Set to interrupt every 100ms TimerLoadSet(WTIMER1_BASE, TIMER_B, timerLoadValue); TimerIntRegister(WTIMER1_BASE, TIMER_B, TimeoutHandler); // Register interrupt handler TimerIntEnable(WTIMER1_BASE, TIMER_TIMB_TIMEOUT); // Enable timer timeout interrupt IntPrioritySet(INT_WTIMER1B, 0); // Configure Wide Timer 1B interrupt priority as 0 IntEnable(INT_WTIMER1B); // Enable Wide Timer 1B interrupt TimerEnable(WTIMER1_BASE, TIMER_BOTH); // Enable both timers validRXData = false; }
void setup_pwm() { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinConfigure(GPIO_PB6_T0CCP0); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); }
// *************** GPIO_Init *************** void GPIO_Init( GPIO_PORT_T port, GPIO_PIN_T pins, unsigned long dir_mode, unsigned long strength, unsigned long pin_type ) { if( 0 == GPIO_PortStatusFlag[port] ) { SysCtlPeripheralEnable( GPIO_Peripheral[port] ); GPIO_PortStatusFlag[port] = 1; } switch ( pin_type ) { case CCP: { GPIOPinTypeTimer ( GPIO_PortBase[port], pins ); break; } case PWM: { break; } default: { // regular GPIOs GPIOPadConfigSet( GPIO_PortBase[port], pins, strength, pin_type ); GPIODirModeSet( GPIO_PortBase[port], pins, dir_mode ); break; } } }
/********************************************************************************************************* ** 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. }
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); }
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); }
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()); } }
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); }
void Tach_Init(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0); /* Setup Timer0A Counter in edge-time-capture mode. */ TimerDisable(TIMER0_BASE, TIMER_A); //TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_CAP_TIME | TIMER_CFG_B_PERIODIC); TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT | TIMER_TIMA_TIMEOUT); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); TimerLoadSet(TIMER0_BASE, TIMER_A, 0xFFFF); IntEnable(INT_TIMER0A); // Activate timer TimerEnable(TIMER0_BASE, TIMER_A); }
void init(){ // Init OLED RIT128x96x4Init(1000000); // Set the clock to 50 MHz SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // Select 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); // Navigation Switches 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); // CAN Connection SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); GPIOPinTypeCAN(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1); CANInit(CAN0_BASE); CANBitRateSet(CAN0_BASE, 8000000, 250000); CANIntEnable(CAN0_BASE, CAN_INT_MASTER); IntEnable(INT_CAN0); CANEnable(CAN0_BASE); // CAN Objects transmit.ulMsgID= 0x200; transmit.ulMsgIDMask= 0; transmit.ulMsgLen= 2*sizeof(unsigned long); // IR Receiver SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_4); // Timer SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_A_CAP_TIME); TimerControlEvent(TIMER0_BASE, TIMER_A, TIMER_EVENT_NEG_EDGE); TimerLoadSet(TIMER0_BASE, TIMER_A, TIME_WIDTH); TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT | TIMER_TIMA_TIMEOUT); TimerEnable(TIMER0_BASE, TIMER_A); IntEnable(INT_TIMER0A); }
/**************************************************************************//** * @brief This function initializes the ALS. The sensor is powered up and the * onboard ADC is configured. * * * @return None ******************************************************************************/ void alsInit(void) { // // Set ALS power pin (output high) // GPIOPinTypeGPIOOutput(BSP_ALS_PWR_BASE, BSP_ALS_PWR); GPIOPinWrite(BSP_ALS_PWR_BASE, BSP_ALS_PWR, BSP_ALS_PWR); // // Configure ALS output pin as hw controlled, no drive (same as for timer) // GPIOPinTypeTimer(BSP_ALS_OUT_BASE, BSP_ALS_OUT); // // Configure ADC, Internal reference, 512 decimation rate (12bit) // SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL); }
//***************************************************************************** // //! Enables the sound output. //! //! This function enables the sound output, preparing it to play music or sound //! effects. //! //! \return None. // //***************************************************************************** void SoundEnable(void) { // // Set the timer to produce 40 kHz, which is well beyond the limits of // human hearing. // TimerLoadSet(TIMER2_BASE, TIMER_A, (g_ulSystemClock / 40000) - 1); // // Restore the output volume. // SoundVolumeSet(g_ucVolume); // // Enable the PWM output timer. // TimerEnable(TIMER2_BASE, TIMER_A); // // Configure the speaker GPIO pin as a timer PWM pin. // GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_7); }
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); }
//***************************************************************************** // // 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) { } }
// After a certain number of edges are captured, the application prints out // the results and compares the elapsed time between edges to the expected // value. // // Note that the "B" timer is used because on some devices the "A" timer does // not work correctly with the uDMA controller. Refer to the chip errata for // details. // //***************************************************************************** int main(void) { unsigned long ulIdx; unsigned short usTimerElapsed; //unsigned short usTimerErr; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the UART and write a status message. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_EVEN)); //UARTStdioInit(0); //UARTprintf("\033[2JuDMA edge capture timer example\n\n"); //UARTprintf("This example requires that PD0 and PD7 be jumpered together" // "\n\n"); // // Create a signal source that can be used as an input for the CCP1 pin. // SetupSignalSource(); // // Enable the GPIO port used for the CCP1 input. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the Timer0 CCP1 function to use PD7 // GPIOPinConfigure(GPIO_PB2_CCP3); GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2); // // Set up Timer0B for edge-timer mode, positive edge // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_CAP_TIME); TimerControlEvent(TIMER1_BASE, TIMER_B, TIMER_EVENT_BOTH_EDGES); TimerLoadSet(TIMER1_BASE, TIMER_B, 0xffff); // // Enable the uDMA peripheral // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Put the attributes in a known state for the uDMA Timer0B channel. These // should already be disabled by default. // ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_TMR1B, UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK); // // Configure DMA channel for Timer0B to transfer 16-bit values, 1 at a // time. The source is fixed and the destination increments by 16-bits // (2 bytes) at a time. // ROM_uDMAChannelControlSet(UDMA_CHANNEL_TMR1B | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1); // // Set up the transfer parameters for the Timer0B primary control // structure. The mode is set to basic, the transfer source is the // Timer0B register, and the destination is a memory buffer. The // transfer size is set to a fixed number of capture events. // ROM_uDMAChannelTransferSet(UDMA_CHANNEL_TMR1B | UDMA_PRI_SELECT, UDMA_MODE_BASIC, (void *)(TIMER1_BASE + TIMER_O_TBR), g_usTimerBuf, MAX_TIMER_EVENTS); // // Enable the timer capture event interrupt. Note that this signal is // used to trigger the DMA request and not an actual interrupt. // Start the capture timer running and enable its interrupt channel. // The timer interrupt channel is used by the uDMA controller. // //UARTprintf("Starting timer and uDMA\n"); TimerIntEnable(TIMER1_BASE, TIMER_CAPB_EVENT); TimerEnable(TIMER1_BASE, TIMER_B); IntEnable(INT_TIMER1B); // // Now enable the DMA channel for Timer0B. It should now start performing // transfers whenever there is a rising edge detected on the CCP1 pin. // ROM_uDMAChannelEnable(UDMA_CHANNEL_TMR1B); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Wait for the transfer to complete. // //UARTprintf("Waiting for transfers to complete\n"); while(!g_bDoneFlag) { } // // Check for the expected number of occurrences of the interrupt handler, // and that there are no DMA errors // if(g_uluDMAErrCount != 0) { //UARTprintf("\nuDMA errors were detected!!!\n\n"); } if(g_ulTimer0BIntCount != 1) { //UARTprintf("\nUnexpected number of interrupts occurrred (%d)!!!\n\n", // g_ulTimer0BIntCount); } // // Display the timer values that were captured using the edge capture timer // with uDMA. Compare the difference between stored values to the PWM // period and make sure they match. This verifies that the edge capture // DMA transfers were occurring with the correct timing. // //UARTprintf("\n Captured\n"); //UARTprintf("Event Value Difference Status\n"); //UARTprintf("----- -------- ---------- ------\n"); const unsigned char nbColonnes = '1'; UARTSend(&nbColonnes,1); for(ulIdx = 1; ulIdx < MAX_TIMER_EVENTS; ulIdx++) { // // Due to timer erratum, when the timer rolls past 0 as it counts // down, it will trigger an additional DMA transfer even though there // was not an edge capture. This will appear in the data buffer as // a duplicate value - the value will be the same as the prior capture // value. Therefore, in this example we skip past the duplicated // value. // if(g_usTimerBuf[ulIdx] == g_usTimerBuf[ulIdx - 1]) { const unsigned char dup = '$'; UARTSend(&dup,1); //UARTprintf(" %2u 0x%04X skipped duplicate\n", ulIdx, // g_usTimerBuf[ulIdx]); continue; } // // Compute the difference between adjacent captured values, and then // compare that to the expected timeout period. // usTimerElapsed = g_usTimerBuf[ulIdx - 1] - g_usTimerBuf[ulIdx]; //usTimerErr = usTimerElapsed > TIMEOUT_VAL ? // usTimerElapsed - TIMEOUT_VAL : // TIMEOUT_VAL - usTimerElapsed; // // Print the captured value and the difference from the previous // unsigned char data[10]; itoa(usTimerElapsed,data); UARTSend(data,10); //UARTprintf(" %2u 0x%04X %8u ", ulIdx, g_usTimerBuf[ulIdx], // usTimerElapsed); // // Print error status based on the deviation from expected difference // between samples (calculated above). Allow for a difference of up // to 1 cycle. Any more than that is considered an error. // //if(usTimerErr > 1) //{ // UARTprintf(" ERROR\n"); //} //else //{ // UARTprintf(" OK\n"); //} } const unsigned char fin = '\n'; UARTSend(&fin,1); // // End of application // while(1) { } }
int main(void) { volatile unsigned long ulLoop; // // 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_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1 | SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Enable the GPIO pins for the LED (PF2 & PF3). // //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_3); ROM_IntMasterEnable(); // // Initialize the UART. // ROM_GPIOPinConfigure (GPIO_PA0_U0RX); ROM_GPIOPinConfigure (GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTEchoSet(true); // // Enable the UART interrupt. // // /// Initialize PWM // GPIOPinConfigure(GPIO_PF1_T0CCP1); GPIOPinConfigure(GPIO_PF2_T1CCP0); GPIOPinConfigure(GPIO_PF3_T1CCP1); GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_1 | GPIO_PIN_1); // // Configure Timer as a 16-bit periodic timer. // TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM); // Configure period is 10 KHz TimerLoadSet(TIMER0_BASE, TIMER_B, 16000); TimerLoadSet(TIMER1_BASE, TIMER_A, 16000); TimerLoadSet(TIMER1_BASE, TIMER_B, 16000); // // Set the Timer match value to load value (100% ON) . // TimerMatchSet(TIMER0_BASE, TIMER_B, PWM_CTR.CH1); TimerMatchSet(TIMER1_BASE, TIMER_A, PWM_CTR.CH2); TimerMatchSet(TIMER1_BASE, TIMER_B, PWM_CTR.CH3); TimerEnable(TIMER0_BASE, TIMER_B); TimerEnable(TIMER1_BASE, TIMER_BOTH); // // Hello! // UARTprintf("LED PWM Control Demo\n"); // // We are finished. Hang around doing nothing. // while (1) { } }
/********************************************************************************************** * 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); */ } }
/*---------------------------------------------------------------------------*/ 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(); }
//***************************************************************************** // // 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(); } }
int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //Configure System Clock //SSD SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Enable Port D SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable Port B GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,0x0F); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,0xFF); //S1 and S2 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Enable Port F //Mode 1 SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Enable ADC0 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //Enable Port E GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); //Select ADC Function of PE 1 ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0); //Configure ADC0 Sequencer ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END); //Configure the step of the sequencer //Mode 2 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); //Enable TIMER1 Module GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_4); //Set PF4 as Input GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //Configuring the PF4 GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_BOTH_EDGES); //Setting Interrupt to trigger on both edges TimerConfigure(TIMER1_BASE,TIMER_CFG_PERIODIC); //Configure TIMER1 into a Continuous Mode TimerIntRegister(TIMER1_BASE, TIMER_A, fast); //Register interrupt if PF4 pressed for more than 1s //Mode 3 SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); //Enable TIMER4 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); //Enable WTIMER0 Module SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); //Enable Port C GPIOPinConfigure(GPIO_PC4_WT0CCP0); GPIOPinTypeTimer(GPIO_PORTC_BASE,GPIO_PIN_4); //Set PC4 as a Timer Capture pin TimerIntRegister(TIMER4_BASE,TIMER_A,freqfind); //Register a timer interrupt for TIMER4 TimerConfigure(TIMER4_BASE,TIMER_CFG_PERIODIC); //Configure Timer4 in continuous mode TimerConfigure(WTIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_CAP_COUNT); TimerControlEvent(WTIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE); //Configure WTIMER0 for Positive Edge Capture IntMasterEnable(); GPIOPinWrite(GPIO_PORTB_BASE,0xFF,0x00); //Initialize SSD to 0x00 GPIOPinWrite(GPIO_PORTD_BASE, 0x0F, 0x00); //Turn off all the digits of the SSD SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Enable TIMER0 Module TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC); //Configure TIMER0 into a Continuous Mode TimerIntRegister(TIMER0_BASE, TIMER_A, ssdmux); //Register ISR for TIMER0 Interrupt to update SSD TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet()/3000); //Set the refresh rate of the SSD IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT); //Enable the timer interrupt TimerEnable(TIMER0_BASE,TIMER_A); //Start the timer HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE|GPIO_O_CR) = GPIO_PIN_0; //Unlock PF0 from the NMI mode HWREG(GPIO_PORTF_BASE|GPIO_O_LOCK) = 0; ssdset(0); mode1set(); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); //Setting PF0 to Input GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //Configuring the pins GPIOIntRegister(GPIO_PORTF_BASE, modeselect); //Register Interrupt for Port F with ISR modeselect() GPIOIntClear(GPIO_PORTF_BASE, GPIO_PIN_0); //Clear any existing interrupts GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE); //Setting Interrupt to trigger on falling edges GPIOIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0); //Enable the GPIO Interrupts on Port F IntEnable(INT_GPIOF); //Enable Interrupts on Port F while(1){ switch(mode) //Select operation according to mode { case 1: mode1(); break; case 2: ssdsetHex(hex_count); if(fast_flag) { mode2(); SysCtlDelay(SysCtlClockGet()/300); } break; case 3: mode3(); break; case 4: mode1(); break; case 5: ssdsetHex(hex_count); if(fast_flag) { mode2(); SysCtlDelay(SysCtlClockGet()/300); } break; } SysCtlDelay(SysCtlClockGet()/3000); } return 0; }
int main(void) { /* FIFO Buffer */ unsigned long temp[1]; /*Set the clocking to directly run from the crystal at 8MHz*/ SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); /*Enable ADC Peripheral*/ SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //Enable Timers. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); /* Set the clock for the GPIO Port B */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); /* Set the type of the GPIO Pin */ GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_5); /* UART configuration */ InitConsole(); //Setting the timer for PWM TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM); TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM); /*Configure ADC Peripheral*/ ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); /*Configure ADC Sequence*/ ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END); /*Enable ADC sequence*/ ADCSequenceEnable(ADC0_BASE, 3); /*Clear ADC Interrupt*/ ADCIntClear(ADC0_BASE, 3); IntMasterEnable(); TimerLoadSet(TIMER2_BASE, TIMER_B, 500); TimerLoadSet(TIMER1_BASE, TIMER_A, 500); TimerLoadSet(TIMER0_BASE, TIMER_A, 500); unsigned long i,k,counter=0,i1=0; long num1,y=0,num2,num3,j=0,sum1=0,sum2=0,sum3=0; while(1) { for(i=0;i<15648;i++) { if(i%24 == 0) { ADCProcessorTrigger(ADC0_BASE, 3); while(!ADCIntStatus(ADC0_BASE, 3, false)) { } ADCIntClear(ADC0_BASE, 3); ADCSequenceDataGet(ADC0_BASE, 3, temp); x[i/24]=temp[0]; } } num1=0; num2=0; num3=0; n1=_IQ17(0); n2=_IQ17(0); n3=_IQ17(0); for(k=0;k<652;k++) { l1= _IQ17(b1[k]); l2= _IQ17(b2[k]); l3= _IQ17(b3[k]); m= _IQ17(x[651-k]); n1=n1 + _IQ17mpy(l1,m); n2=n2 + _IQ17mpy(l2,m); n3=n3 + _IQ17mpy(l3,m); } num1=_IQ17int(n1); num2=_IQ17int(n2); num3=_IQ17int(n3); sum1+=num1*num1; sum2+=num2*num2; sum3+=num3*num3; j++; if(j==15) { sum1=sum1/500; sum2=sum2/500; sum3=sum3/500; r1=isqrt(sum1); r2=isqrt(sum2); r3=isqrt(sum3); sum1=sum2=0; j=0; } r01=r1*r1*r1; r02=r2*r2*r2; r03=r3*r3*r3; if(r01>0) { TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM); pwm1(256-r01); } else { TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC); } if(r02>0) { TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM); pwm2(256-r02); } else { TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC); } if(r03>0) { TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM); pwm3(256-r03); } else { TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PERIODIC); } } }