static void Config_PWM(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIOPinConfigure(GPIO_PB6_T0CCP0); ROM_GPIOPinConfigure(GPIO_PB2_T3CCP0); ROM_GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_6); // Configure timer ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, DEFAULT); ROM_TimerMatchSet(TIMER0_BASE, TIMER_A, DEFAULT); // PWM ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM); ROM_TimerLoadSet(TIMER3_BASE, TIMER_A, DEFAULT); ROM_TimerMatchSet(TIMER3_BASE, TIMER_A, DEFAULT); // PWM ROM_TimerControlLevel(TIMER3_BASE, TIMER_A, true); ROM_TimerEnable(TIMER3_BASE, TIMER_A); ROM_SysCtlPeripheralEnable(DRV_ENABLE_LEFT_CHN_PERIPHERAL); ROM_SysCtlPeripheralEnable(DRV_ENABLE_RIGHT_CHN_PERIPHERAL); ROM_GPIOPinTypeGPIOOutput(DRV_ENABLE_LEFT_CHN_PORT, DRV_ENABLE_LEFT_CHN_PIN); ROM_GPIOPinTypeGPIOOutput(DRV_ENABLE_RIGHT_CHN_PORT, DRV_ENABLE_RIGHT_CHN_PIN); ROM_GPIOPinWrite(DRV_ENABLE_LEFT_CHN_PORT, DRV_ENABLE_LEFT_CHN_PIN, 0); ROM_GPIOPinWrite(DRV_ENABLE_RIGHT_CHN_PORT, DRV_ENABLE_RIGHT_CHN_PIN, 0); }
//***************************************************************************** // // This example application demonstrates the use of the timers to generate // periodic interrupts. // //***************************************************************************** int main(void) { // // 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 status. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JTimers example\n"); UARTprintf("T1: 0 T2: 0"); // // 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) { } }
// Main ---------------------------------------------------------------------------------------------- int main(void){ // Enable lazy stacking 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); // Initialize the UART and write status. ConfigureUART(); UARTprintf("Timers example\n"); // Enable LEDs ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); // Enable the peripherals used by this example. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // 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_TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet()*2); // Blue should blink 2 times as much as red ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, ROM_SysCtlClockGet()*3); // Green should blink 3 times as much as red // Setup the interrupts for the timer timeouts. ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER1A); ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // Enable the timers. ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_TimerEnable(TIMER1_BASE, TIMER_A); ROM_TimerEnable(TIMER2_BASE, TIMER_A); // Loop forever while the timers run. while(1){} }
void BPMTimerSetUp() { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // timer 0 SysCtlDelay(3); // // Enable processor interrupts. // //IntPrioritySet(INT_TIMER0A_TM4C123, 2); // // Configure the two 32-bit periodic timers. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/500); //ROM_SysCtlClockGet()/100000 //ROM_SysCtlClockGet()/500 // Setup the interrupts for the timer timeouts. ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Enable the timers. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
//***************************************************************************** // // Initialize the IO used in this demo // //***************************************************************************** void io_init(void) { // // Configure Port F0 for as an output for the status LED. // ROM_GPIOPinTypeGPIOOutput(LED_PORT_BASE, LED_PIN); // // Initialize LED to OFF (0) // ROM_GPIOPinWrite(LED_PORT_BASE, LED_PIN, 0); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // // Configure the timer used to pace the animation. // ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); // // Setup the interrupts for the timer timeouts. // ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // // Set the timer for the current animation speed. This enables the // timer as a side effect. // io_set_timer(g_ulAnimSpeed); }
void init() { ROM_FPUEnable(); ROM_FPULazyStackingEnable(); ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIO_PORTB_DIR_R = 0x00; GPIO_PORTB_DEN_R = 0xff; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 1000000); ROM_SysTickEnable(); ROM_SysTickIntEnable(); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); reset(); }
// Main ---------------------------------------------------------------------------------------------- int main(void){ // Enable lazy stacking ROM_FPULazyStackingEnable(); // Set the clocking to run directly from the crystal. ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // Initialize the UART and write status. ConfigureUART(); UARTprintf("--Countdown Example--\n"); // Initialize LEDs ConfigureLEDs(); // Enable the peripherals used by this example. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // 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_TimerConfigure(TIMER2_BASE, TIMER_CFG_ONE_SHOT); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet()/20); ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, ROM_SysCtlClockGet()/10); // Setup the interrupts for the timer timeouts. ROM_IntEnable(INT_TIMER0A); ROM_IntEnable(INT_TIMER1A); ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // Enable the timers. ROM_TimerEnable(TIMER0_BASE, TIMER_A); UARTprintf("Time Left: \n"); // Loop forever while the timers run. while(1){} }
int cppmain() { init(); resetMicros(); enableMessaging(); // Set up the pins int i; for (i = 0; i < 12; i++) pinMode(legPins[i], OUTPUT_SERVO); pinMode(BLUE_LED, OUTPUT); // We will use WTIMER0 for the interrupts ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER0); ROM_TimerConfigure(WTIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); // Set up the stag walking timer interrupt ROM_TimerPrescaleSet(WTIMER0_BASE, TIMER_A, 79999); // 1 ms per tick TimerIntRegister(WTIMER0_BASE, TIMER_A, stagInterrupt); ROM_TimerLoadSet(WTIMER0_BASE, TIMER_A, 50); // 50 ms per cylce ROM_TimerIntEnable(WTIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER0_BASE, TIMER_A); ROM_IntPrioritySet(INT_WTIMER0A, 0x20); // Set general sensor/status interrupt ROM_TimerPrescaleSet(WTIMER0_BASE, TIMER_B, 79999); // 1 ms per tick TimerIntRegister(WTIMER0_BASE, TIMER_B, statusInterrupt); ROM_TimerLoadSet(WTIMER0_BASE, TIMER_B, 500); // 500 ms per cycle ROM_TimerIntEnable(WTIMER0_BASE, TIMER_TIMB_TIMEOUT); ROM_TimerEnable(WTIMER0_BASE, TIMER_B); ROM_IntPrioritySet(INT_WTIMER0A, 0x40); uint16_t msgLength; uint16_t msgFlags; MessageType msgType; // Main message handing loop bool z = true; while (1) { digitalWrite(BLUE_LED, z); z = !z; switch (getMessage(&msgType, &msgLength, &msgFlags, g_msgBody)) { case 0: // Success handleMessage(msgType, msgLength, g_msgBody); break; case 1: // Timeout //sendError(TIMEOUT_ERROR); break; case 2: // CRC Error sendError(CRC_ERROR); break; } //delay(10000); } }
void timerInit() { #if F_CPU >= 80000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 50000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 40000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 25000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_8|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 16200000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); //NOT PLL #elif F_CPU >= 16100000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_INT| SYSCTL_OSC_MAIN); //NOT PLL, INT OSC #elif F_CPU >= 16000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_12_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 10000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_20|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 8000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_25|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #else ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #endif // // SysTick is used for delay() and delayMicroseconds() // // ROM_SysTickPeriodSet(0x00FFFFFF); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); // //Initialize Timer5 to be used as time-tracker since beginning of time // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5); //not tied to launchpad pin ROM_TimerConfigure(TIMER5_BASE, TIMER_CFG_PERIODIC_UP); ROM_TimerLoadSet(TIMER5_BASE, TIMER_A, ROM_SysCtlClockGet()/1000); ROM_IntEnable(INT_TIMER5A); ROM_TimerIntEnable(TIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER5_BASE, TIMER_A); ROM_IntMasterEnable(); }
// Start the timers and interrupt frequency void servoStart(void) { ROM_SysCtlPeripheralEnable(SERVO_TIMER_PERIPH); ROM_IntMasterEnable(); ROM_TimerConfigure(SERVO_TIMER, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(SERVO_TIMER, SERVO_TIMER_A, (ROM_SysCtlClockGet() / 1000000) * SERVO_TIMER_RESOLUTION); ROM_IntEnable(SERVO_TIMER_INTERRUPT); ROM_TimerIntEnable(SERVO_TIMER, SERVO_TIMER_TRIGGER); ROM_TimerEnable(SERVO_TIMER, SERVO_TIMER_A); }
void delay_init() { //configure timer1 for one shot intervals and assign interrupt routine ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_TimerConfigure(TIMER1_BASE,TIMER_CFG_ONE_SHOT); ROM_TimerControlStall(TIMER1_BASE, TIMER_A, true); TimerIntRegister(TIMER1_BASE, TIMER_A, delay_isr); }
void initializeTimer(void) { timerSeconds = 0; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // invoke timer once a second ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
//***************************************************************************** // //! 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. // ROM_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) { ROM_TimerConfigure(TIMER5_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PERIODIC)); } ROM_TimerLoadSet(TIMER5_BASE, TIMER_A, g_sSoundState.ui32Period - 1); ROM_TimerMatchSet(TIMER5_BASE, TIMER_A, g_sSoundState.ui32Period); ROM_TimerControlLevel(TIMER5_BASE, TIMER_A, true); // // Update the timer values on timeouts and not immediately. // TimerUpdateMode(TIMER5_BASE, TIMER_A, TIMER_UP_LOAD_TIMEOUT | TIMER_UP_MATCH_TIMEOUT); // // Configure the timer to generate an interrupt at every time-out event. // ROM_TimerIntEnable(TIMER5_BASE, TIMER_CAPA_EVENT); // // Enable the timer. At this point, the timer generates an interrupt // every 15.625 us. // ROM_TimerEnable(TIMER5_BASE, TIMER_A); ROM_IntEnable(INT_TIMER5A); // // Clear the sound flags. // g_sSoundState.ui32Flags = 0; }
ServoClass::ServoClass() { ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); // Initialize variables of the class g_ulPeriod = 0; for(int il_iter = 0; il_iter < SERVOS_PER_TIMER; il_iter++) { g_ulServoPins[il_iter] = INVALID_SERVO_PIN; g_ulServoPulse[il_iter] = DEFAULT_SERVO_PULSE_WIDTH; } g_iServoNo = 0; g_ulPulseWidth = 0; g_ulTicksPerMicrosecond = 0; setRefresh(); // for(int il_iter = 0; il_iter < SERVOS_PER_TIMER; il_iter++) // { // if (g_ulServoPins[il_iter] != INVALID_SERVO_PIN) // { // pinMode(g_ulServoPins[il_iter], OUTPUT); // digitalWrite(g_ulServoPins[il_iter], LOW); // } // } // Enable TIMER ROM_SysCtlPeripheralEnable(SERVO_TIMER_PERIPH); // Enable processor interrupts. ROM_IntMasterEnable(); // Configure the TIMER ROM_TimerConfigure(SERVO_TIMER, SERVO_TIME_CFG); // Calculate the number of timer counts/microsecond g_ulTicksPerMicrosecond = ROM_SysCtlClockGet() / 1000000; g_ulPeriod = g_ulTicksPerMicrosecond * REFRESH_INTERVAL; // 20ms = Standard Servo refresh delay // Initially load the timer with 20ms interval time ROM_TimerLoadSet(SERVO_TIMER, SERVO_TIMER_A, g_ulPeriod); // Setup the interrupt for the TIMER1A timeout. ROM_IntEnable(SERVO_TIMER_INTERRUPT); ROM_TimerIntEnable(SERVO_TIMER, SERVO_TIMER_TRIGGER); // Enable the timer. ROM_TimerEnable(SERVO_TIMER, SERVO_TIMER_A); }
void InitTimer(void) { uint32_t ui32SysClock = ROM_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); printf("Clock=%dMHz\n", ui32SysClock/1000000) ; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, -1); ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
//***************************************************************************** // //! 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. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5); // // Configure the ADC sample sequence used to read the touch screen reading. // ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 4); ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, TS_YP_ADC | ADC_CTL_END | ADC_CTL_IE); ROM_ADCSequenceEnable(ADC0_BASE, 3); // // Enable the ADC sample sequence interrupt. // ROM_ADCIntEnable(ADC0_BASE, 3); ROM_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) { ROM_TimerConfigure(TIMER5_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PERIODIC)); } ROM_TimerPrescaleSet(TIMER5_BASE, TIMER_B, 255); ROM_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. // ROM_TimerEnable(TIMER5_BASE, TIMER_B); }
//***************************************************************************** // //! Initializes the Timer and GPIO functionality associated with the RGB LED //! //! \param ui32Enable enables RGB immediately if set. //! //! This function must be called during application initialization to //! configure the GPIO pins to which the LEDs are attached. It enables //! the port used by the LEDs and configures each color's Timer. It optionally //! enables the RGB LED by configuring the GPIO pins and starting the timers. //! //! \return None. // //***************************************************************************** void RGBInit(uint32_t ui32Enable) { // // Enable the GPIO Port and Timer for each LED // ROM_SysCtlPeripheralEnable(RED_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(RED_TIMER_PERIPH); ROM_SysCtlPeripheralEnable(GREEN_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(GREEN_TIMER_PERIPH); ROM_SysCtlPeripheralEnable(BLUE_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(BLUE_TIMER_PERIPH); // // Configure each timer for output mode // HWREG(GREEN_TIMER_BASE + TIMER_O_CFG) = 0x04; HWREG(GREEN_TIMER_BASE + TIMER_O_TAMR) = 0x0A; HWREG(GREEN_TIMER_BASE + TIMER_O_TAILR) = 0xFFFF; HWREG(BLUE_TIMER_BASE + TIMER_O_CFG) = 0x04; HWREG(BLUE_TIMER_BASE + TIMER_O_TBMR) = 0x0A; HWREG(BLUE_TIMER_BASE + TIMER_O_TBILR) = 0xFFFF; HWREG(RED_TIMER_BASE + TIMER_O_CFG) = 0x04; HWREG(RED_TIMER_BASE + TIMER_O_TBMR) = 0x0A; HWREG(RED_TIMER_BASE + TIMER_O_TBILR) = 0xFFFF; // // Invert the output signals. // HWREG(RED_TIMER_BASE + TIMER_O_CTL) |= 0x4000; HWREG(GREEN_TIMER_BASE + TIMER_O_CTL) |= 0x40; HWREG(BLUE_TIMER_BASE + TIMER_O_CTL) |= 0x4000; if(ui32Enable) { RGBEnable(); } // // Setup the blink functionality // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER5); ROM_TimerConfigure(WTIMER5_BASE, TIMER_CFG_B_PERIODIC | TIMER_CFG_SPLIT_PAIR); ROM_TimerLoadSet64(WTIMER5_BASE, 0xFFFFFFFFFFFFFFFF); ROM_IntEnable(INT_WTIMER5B); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMB_TIMEOUT); }
//函数创建区 //----------------------------------------Start------------------------------------------- void Init_Timer() { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/100);//10ms周期中断,由100决定 如果为1为1s定时 GPIOIntRegister(INT_TIMER0A, Timer0AIntHandler); ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); ROM_IntMasterEnable(); }
void buzzer_init(void) { BUZZER_GPIO_PERIPHERAL_ENABLE(); BUZZER_TIMER_PERIPHERAL_ENABLE(); ROM_GPIOPinConfigure(BUZZER_TIMER_PIN_AF); ROM_GPIOPinTypeTimer(BUZZER_PORT, BUZZER_PIN); ROM_TimerConfigure(BUZZER_TIMER, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM); // ROM_TimerPrescaleSet(BUZZER_TIMER, BUZZER_TIMER_CHANNEL, 10); ROM_TimerLoadSet(BUZZER_TIMER, BUZZER_TIMER_CHANNEL, ROM_SysCtlClockGet()); ROM_TimerMatchSet(BUZZER_TIMER, BUZZER_TIMER_CHANNEL, ROM_SysCtlClockGet()); // PWM ROM_TimerEnable(BUZZER_TIMER, BUZZER_TIMER_CHANNEL); }
void Timer1A_Init(void){ // Enable the Timer 1 Periph ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // Configure Timer as Periodic ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC ); // Set Timer 1A to Frequency ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, (ROM_SysCtlClockGet()/TIMER1_FREQ)); // Enable Timer 1A ROM_TimerEnable(TIMER1_BASE, TIMER_A); }
void initTimer0(int interval, gyro *G){ // // 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(); volatile int tick = 0; tick = (ROM_SysCtlClockGet() / 1000) * interval; // // 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); // // Configure the two 32-bit periodic timers. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); /// imposta il time_out ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, tick); G->tick = (float) interval / 1000; // // 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); }
/** Configures timer. @see timers example in EK-LM4F120XL StellarisWare package @note On the LM4F120XL, there are 16/32 bit timers or "wide" timers featuring 32/64bit. We use a standard timer. @param seconds period of the timer. Maximum is 0xFFFFFFFF / SysCtlClockGet(); or about 171 sec if using 25MHz main clock @return 0 if success; -1 if illegal parameter */ int16_t initTimer(uint8_t seconds) { #define TIMER_MAX_SECONDS (0xFFFFFFFF / SysCtlClockGet()) if ((seconds > TIMER_MAX_SECONDS) || (seconds == 0)) return -1; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); ROM_TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); // Full width (32 bit for Timer 2) periodic timer ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, (ROM_SysCtlClockGet() * seconds)); // for once per second ROM_IntEnable(INT_TIMER2A); ROM_TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER2_BASE, TIMER_A); return 0; }
void init_Timer1B(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); ROM_TimerLoadSet(TIMER1_BASE, TIMER_B, ROM_SysCtlClockGet() / 2000); ROM_IntMasterEnable(); ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMB_TIMEOUT); ROM_IntEnable(INT_TIMER1B); timeCounter = 0; ROM_TimerEnable(TIMER1_BASE, TIMER_B); }
void OneMsTaskTimer::start(uint32_t timer_index) { uint32_t load = (F_CPU / 1000); //// !!!! count = 0; overflowing = 0; // Base address for first timer g_ulBase = getTimerBase(timerToOffset(timer_index)); timerAB = TIMER_A << timerToAB(timer_index); //Setup interrupts for duration, interrupting at 1kHz ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0+ timer_index); ROM_IntMasterEnable(); ROM_TimerConfigure(g_ulBase, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(g_ulBase, TIMER_A, F_CPU/1000); // Setup the interrupts for the timer timeouts. TimerIntRegister(g_ulBase, TIMER_A, OneMsTaskTimer_int); ROM_IntEnable(INT_TIMER0A+timer_index); ROM_TimerIntEnable(g_ulBase, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(g_ulBase, TIMER_A); }
//------------------------------------ Timer init --------------------------------- void ir_timer_init(void) { // The Timer0 peripheral must be enabled for use. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // The Timer0 peripheral must be enabled for use. // When configured for a pair of half-width timers, each timer is separately configured. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_ONE_SHOT); // Calculate the number of timer counts/microsecond ulCountsPerMicrosecond = ROM_SysCtlClockGet() / 10000; // 0.10ms = timeout delay ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ulCountsPerMicrosecond); ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0AIntHandler ); // // Configure the Timer0 interrupt for timer timeout. // ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Enable the Timer0 interrupt on the processor (NVIC). // ROM_IntEnable(INT_TIMER0A); gulTicks = 0; // // Enable Timer0A. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
void motor_init() { unsigned long timer; //configure timer0 for one shot intervals and assign interrupt routine ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_ONE_SHOT); ROM_TimerControlStall(TIMER0_BASE, TIMER_A, true); TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0A_ISR); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //setup RGB led outputs. ROM_SysCtlPeripheralEnable(LED_PERIPH); ROM_GPIOPinTypeGPIOOutput(LED_PORT, LED_R | LED_G | LED_B ); //enable peripherals used for motor ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //set motor pins to outputs ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, MOTOR_PORTA_PINS ); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, MOTOR_PORTB_PINS ); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, MOTOR_PORTD_PINS ); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, MOTOR_PORTE_PINS ); //make sure motors are disabled and step pins are low motor_disable(); motor_unstep(); //start the timer. the ISR will run at the minimum rate //interval until there is a block to execute. timer=calculate_timer(MIN_STEP_RATE); ROM_TimerLoadSet(TIMER0_BASE,TIMER_A, timer); ROM_TimerEnable(TIMER0_BASE,TIMER_A); }
int main() { ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_BLUE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_IntMasterEnable(); ROM_TimerDisable(TIMER0_BASE, TIMER_A); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()); ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0AIntHandler); ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_BLUE, led_value); ROM_TimerEnable(TIMER0_BASE, TIMER_A); while(1) {} }
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) { uint8_t port = digitalPinToPort(_pin); if (port == NOT_A_PORT) return; if (tone_state == 0 || _pin == current_pin) { //Setup PWM current_pin = _pin; tone_timer = digitalPinToTimer(_pin); uint32_t timerBase = getTimerBase(timerToOffset(tone_timer)); tone_state = 1; g_duration = duration; PWMWrite(_pin, 256, 128, frequency); //Setup interrupts for duration, interrupting at 1kHz ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); ROM_IntMasterEnable(); ROM_TimerConfigure(TIMER4_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER4_BASE, TIMER_A, ROM_SysCtlClockGet()/1000); ROM_IntEnable(INT_TIMER4A); ROM_TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER4_BASE, TIMER_A); } }
//***************************************************************************** // // Configure the timer and its pins for measuring the length of // ultrasonic sensor echo pulse. // //***************************************************************************** void ConfigureDistancePulseTimer() { // // Enable Timer 4 // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); // // Configure timer 4A as a 16-bit event capture up-counter // ROM_TimerConfigure(TIMER4_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP); // // Set prescaler to 255. This essentially makes // the 16-bit timer a 24-bit timer. // ROM_TimerPrescaleSet(TIMER4_BASE, TIMER_A, 0xFF); // // The timer should capture events on both rising and falling edges // ROM_TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_BOTH_EDGES); }
//***************************************************************************** // //! Initializes the touch screen driver. //! //! This function initializes the touch screen driver, beginning the process of //! reading from the touch screen. This driver uses the following hardware //! resources: //! //! - ADC sample sequence 3 //! - Timer 1 subtimer A //! //! \return None. // //***************************************************************************** void TouchScreenInit(void) { // // Set the initial state of the touch screen driver's state machine. // g_ulTSState = TS_STATE_INIT; // // Determine which calibration parameter set we will be using. // g_plParmSet = g_lTouchParameters[SET_NORMAL]; if(g_eDaughterType == DAUGHTER_SRAM_FLASH) { // // If the SRAM/Flash daughter board is present, select the appropriate // calibration parameters and reading threshold value. // g_plParmSet = g_lTouchParameters[SET_SRAM_FLASH]; g_sTouchMin = 40; } else if(g_eDaughterType == DAUGHTER_FPGA) { // // If the FPGA daughter board is present, select the appropriate // calibration parameters and reading threshold value. // g_plParmSet = g_lTouchParameters[SET_FPGA]; g_sTouchMin = 70; } // // There is no touch screen handler initially. // g_pfnTSHandler = 0; // // Enable the peripherals used by the touch screen interface. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ROM_SysCtlPeripheralEnable(TS_P_PERIPH); ROM_SysCtlPeripheralEnable(TS_N_PERIPH); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // // Configure the ADC sample sequence used to read the touch screen reading. // ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 4); ROM_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); ROM_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH_YP | ADC_CTL_END | ADC_CTL_IE); ROM_ADCSequenceEnable(ADC0_BASE, 3); // // Enable the ADC sample sequence interrupt. // ROM_ADCIntEnable(ADC0_BASE, 3); ROM_IntEnable(INT_ADC0SS3); // // Configure the GPIOs used to drive the touch screen layers. // ROM_GPIOPinTypeGPIOOutput(TS_P_BASE, TS_XP_PIN | TS_YP_PIN); // // If no daughter board or one which does not rewire the touchscreen // interface is installed, set up GPIOs to drive the XN and YN signals. // if((g_eDaughterType != DAUGHTER_SRAM_FLASH) && (g_eDaughterType != DAUGHTER_FPGA)) { ROM_GPIOPinTypeGPIOOutput(TS_N_BASE, TS_XN_PIN | TS_YN_PIN); } ROM_GPIOPinWrite(TS_P_BASE, TS_XP_PIN | TS_YP_PIN, 0x00); if(g_eDaughterType == DAUGHTER_SRAM_FLASH) { HWREGB(LCD_CONTROL_CLR_REG) = LCD_CONTROL_XN | LCD_CONTROL_YN; } else if(g_eDaughterType == DAUGHTER_FPGA) { HWREGH(LCD_FPGA_CONTROL_CLR_REG) = LCD_CONTROL_XN | LCD_CONTROL_YN; } else { ROM_GPIOPinWrite(TS_N_BASE, TS_XN_PIN | TS_YN_PIN, 0x00); } // // See if the ADC trigger timer has been configured, and configure it only // if it has not been configured yet. // if((HWREG(TIMER1_BASE + TIMER_O_CTL) & TIMER_CTL_TAEN) == 0) { // // Configure the timer to trigger the sampling of the touch screen // every millisecond. // ROM_TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, (ROM_SysCtlClockGet() / 1000) - 1); ROM_TimerControlTrigger(TIMER1_BASE, TIMER_A, true); // // Enable the timer. At this point, the touch screen state machine // will sample and run once per millisecond. // ROM_TimerEnable(TIMER1_BASE, TIMER_A); } }