//***************************************************************************** // // 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) { } }
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); }
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); } }
// 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){} }
//***************************************************************************** // // Set the timer used to pace the animation. We scale the timer timeout such // that a speed of 100% causes the timer to tick once every 20 mS (50Hz). // //***************************************************************************** static void io_set_timer(unsigned long ulSpeedPercent) { unsigned long ulTimeout; // // Turn the timer off while we are mucking with it. // ROM_TimerDisable(TIMER2_BASE, TIMER_A); // // If the speed is non-zero, we reset the timeout. If it is zero, we // just leave the timer disabled. // if(ulSpeedPercent) { // // Set Timeout // ulTimeout = g_ui32SysClock / 50; ulTimeout = (ulTimeout * 100 ) / ulSpeedPercent; ROM_TimerLoadSet(TIMER2_BASE, TIMER_A, ulTimeout); ROM_TimerEnable(TIMER2_BASE, TIMER_A); } }
//***************************************************************************** // // The interrupt handler for the fourth timer interrupt. (light) // //***************************************************************************** void Timer3IntHandler(void) { // // Clear the timer interrupt. // ROM_TimerIntClear(TIMER3_BASE, TIMER_TIMA_TIMEOUT); // Get the timer value and reset it ROM_TimerDisable(TIMER5_BASE, TIMER_A); // Get the timer value Timer = ROM_TimerValueGet(TIMER5_BASE, TIMER_A); // Reset the timer value to 65000 ROM_TimerLoadSet(TIMER5_BASE, TIMER_A, 65000); // Timer5 ROM_TimerEnable(TIMER5_BASE, TIMER_A); // // Toggle the flag for the light timer. // HWREGBITW(&g_ui32InterruptFlags, 2) = 1; // // Update the interrupt status. // }
double current_time(int reset) { if(!initFlag)InitTimer() ; initFlag = true ; if(reset)ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, -1); return (double)(-(int)ROM_TimerValueGet(TIMER0_BASE, TIMER_A ))/120000000.0 ; }
void ServoClass::ServoIntHandler(void) { // Clear the timer interrupt. ROM_TimerIntClear(SERVO_TIMER, SERVO_TIMER_TRIGGER); // Get the pulse width value for the current servo from the array // if we have already serviced all servos (g_iServoNo = MAX_SERVO_NO) // then this value should be the 20ms period value unsigned long l_ulPulseWidth = g_ulTicksPerMicrosecond * g_ulServoPulse[g_iServoNo]; // Re-Load the timer with the new pulse width count value ROM_TimerLoadSet(SERVO_TIMER, SERVO_TIMER_A, l_ulPulseWidth); // End the servo pulse set previously (if any) if(g_iServoNo > 0) // If not the 1st Servo.... { if (g_ulServoPins[g_iServoNo - 1] != INVALID_SERVO_PIN) digitalWrite(g_ulServoPins[g_iServoNo - 1], LOW); } // Set the current servo pin HIGH if(g_iServoNo < SERVOS_PER_TIMER) { if (g_ulServoPins[g_iServoNo] != INVALID_SERVO_PIN) digitalWrite(g_ulServoPins[g_iServoNo], HIGH); g_iServoNo++; // Advance to next servo for processing next time } else { g_iServoNo = 0; // Start all over again } }
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); }
//***************************************************************************** // //! Sets the blink rate of the RGB Led //! //! \param fRate is the blink rate in hertz. //! //! This function controls the blink rate of the RGB LED in auto blink mode. //! to enable blinking pass a non-zero floating pointer number. To disable //! pass 0.0f as the argument. Calling this function will override the current //! RGBDisable or RGBEnable status. //! //! \return None. // //***************************************************************************** void RGBBlinkRateSet(float fRate) { uint64_t ui64Load; if(fRate == 0.0f) { // // Disable the timer and enable the RGB. If blink rate is zero we // assume we want the RGB to be enabled. To disable call RGBDisable // ROM_TimerDisable(WTIMER5_BASE, TIMER_B); RGBEnable(); } else { // // Keep the math in floating pointing until the end so that we keep as // much precision as we can. // ui64Load = (uint64_t) (((float)SysCtlClockGet()) / (fRate * 2.0f)); ROM_TimerLoadSet(WTIMER5_BASE, TIMER_B, ui64Load); ROM_TimerEnable(WTIMER5_BASE, TIMER_B); } }
void buzzer_setsound(uint32_t ulFrequency) { uint32_t ulPeriod; if (ulFrequency == 0) { ROM_TimerLoadSet(BUZZER_TIMER, BUZZER_TIMER_CHANNEL, ROM_SysCtlClockGet()); ROM_TimerMatchSet(BUZZER_TIMER, BUZZER_TIMER_CHANNEL, ROM_SysCtlClockGet()); } else { ulPeriod = ROM_SysCtlClockGet() / ulFrequency; ROM_TimerLoadSet(BUZZER_TIMER, BUZZER_TIMER_CHANNEL, ulPeriod); ROM_TimerMatchSet(BUZZER_TIMER, BUZZER_TIMER_CHANNEL, ulPeriod / 2); } }
void PWMWrite(uint8_t pin, uint32_t analog_res, uint32_t duty, unsigned int freq) { if (duty == 0) { pinMode(pin, OUTPUT); digitalWrite(pin, LOW); } else if (duty >= analog_res) { pinMode(pin, OUTPUT); digitalWrite(pin, HIGH); } else { uint8_t bit = digitalPinToBitMask(pin); // get pin bit uint8_t port = digitalPinToPort(pin); // get pin port uint8_t timer = digitalPinToTimer(pin); uint32_t portBase = (uint32_t) portBASERegister(port); uint32_t offset = timerToOffset(timer); uint32_t timerBase = getTimerBase(offset); uint32_t timerAB = TIMER_A << timerToAB(timer); if (port == NOT_A_PORT) return; // pin on timer? uint32_t periodPWM = ROM_SysCtlClockGet()/freq; enableTimerPeriph(offset); ROM_GPIOPinConfigure(timerToPinConfig(timer)); ROM_GPIOPinTypeTimer((long unsigned int) portBase, bit); // // Configure for half-width mode, allowing timers A and B to // operate independently // HWREG(timerBase + TIMER_O_CFG) = 0x04; if(timerAB == TIMER_A) { HWREG(timerBase + TIMER_O_CTL) &= ~TIMER_CTL_TAEN; HWREG(timerBase + TIMER_O_TAMR) = PWM_MODE; } else { HWREG(timerBase + TIMER_O_CTL) &= ~TIMER_CTL_TBEN; HWREG(timerBase + TIMER_O_TBMR) = PWM_MODE; } ROM_TimerLoadSet(timerBase, timerAB, periodPWM); ROM_TimerMatchSet(timerBase, timerAB, (analog_res-duty)*periodPWM/analog_res); // // If using a 16-bit timer, with a periodPWM > 0xFFFF, // need to use a prescaler // if((offset < WTIMER0) && (periodPWM > 0xFFFF)) { ROM_TimerPrescaleSet(timerBase, timerAB, (periodPWM & 0xFFFF0000) >> 16); ROM_TimerPrescaleMatchSet(timerBase, timerAB, (((analog_res-duty)*periodPWM/analog_res) & 0xFFFF0000) >> 16); } ROM_TimerEnable(timerBase, timerAB); }
// 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){} }
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(unsigned long nTime) { ROM_TimerLoadSet(WTIMER5_BASE, TIMER_A, nTime * 10); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER5_BASE, TIMER_A); ROM_SysCtlSleep(); ROM_TimerIntDisable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(WTIMER5_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; }
void SetPWM(uint32_t ulBaseAddr, uint32_t ulTimer, uint32_t ulFrequency, int32_t ucDutyCycle) { uint32_t ulPeriod; ulPeriod = ROM_SysCtlClockGet() / ulFrequency; ROM_TimerLoadSet(ulBaseAddr, ulTimer, ulPeriod); if (ucDutyCycle > 70) ucDutyCycle = 70; else if (ucDutyCycle < -70) ucDutyCycle = -70; ROM_TimerMatchSet(ulBaseAddr, ulTimer, (100 + ucDutyCycle) * ulPeriod / 200 - 1); }
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); }
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); }
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 delay_isr() { ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); if (delay_count > 50000) { delay_count -= 50000; ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, 50000*80000); ROM_TimerEnable(TIMER1_BASE, TIMER_A); } else if (delay_count > 0) { ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, delay_count*80000); ROM_TimerEnable(TIMER1_BASE, TIMER_A); delay_count = 0; } else { delay_stat = DELAY_IDLE; ROM_TimerIntDisable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(TIMER1_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); }
//函数创建区 //----------------------------------------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 delay(uint32_t nTime) { ROM_TimerLoadSet(WTIMER5_BASE, TIMER_A, nTime * 10); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER5_BASE, TIMER_A); ROM_SysCtlSleep(); // Make sure the timer finished, go back to sleep if it didn't // (Another interrupt may have woken up the system) while (ROM_TimerValueGet(WTIMER5_BASE, TIMER_A) != nTime * 10) ROM_SysCtlSleep(); ROM_TimerIntDisable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(WTIMER5_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; }
//***************************************************************************** // // The interrupt handler for the SoftUART GPIO edge interrupt. // //***************************************************************************** void GPIOAIntHandler(void) { // // Configure the SoftUART receive timer so that it will sample at the // mid-bit time of this character. // ROM_TimerDisable(TIMER0_BASE, TIMER_B); ROM_TimerLoadSet(TIMER0_BASE, TIMER_B, g_ulBitTime); ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_B); // // Call the SoftUART receive timer tick function. // SoftUARTRxTick(&g_sUART, true); }