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)
    {
    }
}
Example #3
0
//*****************************************************************************
//
//! 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
    //
    ROM_TimerEnable(RED_TIMER_BASE, TIMER_BOTH);
    ROM_TimerEnable(GREEN_TIMER_BASE, TIMER_BOTH);
    ROM_TimerEnable(BLUE_TIMER_BASE, TIMER_BOTH);

    //
    // Reconfigure each LED's GPIO pad for timer control
    //
    ROM_GPIOPinConfigure(GREEN_GPIO_PIN_CFG);
    ROM_GPIOPinTypeTimer(GREEN_GPIO_BASE, GREEN_GPIO_PIN);
    MAP_GPIOPadConfigSet(GREEN_GPIO_BASE, GREEN_GPIO_PIN, GPIO_STRENGTH_8MA_SC,
                     GPIO_PIN_TYPE_STD);

    ROM_GPIOPinConfigure(BLUE_GPIO_PIN_CFG);
    ROM_GPIOPinTypeTimer(BLUE_GPIO_BASE, BLUE_GPIO_PIN);
    MAP_GPIOPadConfigSet(BLUE_GPIO_BASE, BLUE_GPIO_PIN, GPIO_STRENGTH_8MA_SC,
                     GPIO_PIN_TYPE_STD);

    ROM_GPIOPinConfigure(RED_GPIO_PIN_CFG);
    ROM_GPIOPinTypeTimer(RED_GPIO_BASE, RED_GPIO_PIN);
    MAP_GPIOPadConfigSet(RED_GPIO_BASE, RED_GPIO_PIN, GPIO_STRENGTH_8MA_SC,
                     GPIO_PIN_TYPE_STD);
}
Example #4
0
void Timer0IntHandler(void){
	// Used to countdown from entered time

	// Clear the timer interrupt.
	ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

	// Check if time has been reached
	if(g_countdownTime == 0){
		ROM_IntMasterDisable();
		UARTprintf("Time's Up!\n\n");
		ROM_IntMasterEnable();
		ROM_TimerEnable(TIMER1_BASE, TIMER_A);
		ROM_TimerIntDisable(TIMER0_BASE, TIMER_A);
		return;
	}

	// Turn on LED
	ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED, LED_RED);
	ROM_TimerEnable(TIMER2_BASE, TIMER_A);

	// Update the interrupt status on the display.
	ROM_IntMasterDisable();
	UARTprintf("    %i\n",g_countdownTime);
	ROM_IntMasterEnable();

	// Decrement counter
	g_countdownTime--;
	
	// Turn off LED
	//ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED, 0);
}
Example #5
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);
    }
}
Example #6
0
// 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){}

}
Example #7
0
//*****************************************************************************
//
// The interrupt handler for timer 4.  This will be called whenever the timer
// count reaches the match value (0 in this example).
//
// TODO: Make sure you hook your ISR to the correct vector in the application
// startup file.
//
//*****************************************************************************
void
Timer4IntHandler(void)
{
    //
    // Clear the timer interrupt.
    //
    // TODO: Rework this for the timer you are using in your application.
    //
    ROM_TimerIntClear(TIMER4_BASE, TIMER_CAPA_MATCH);

    //
    // TODO: Do whatever your application needs to do when the relevant
    // number of edges have been counted.
    //
    ProcessInterrupt();

    //
    // The timer is automatically stopped when it reaches the match value
    // so re-enable it here.
    //
    // TODO: Whether you reenable the timer here or elsewhere will be up to
    // your particular application.
    //
    ROM_TimerEnable(TIMER4_BASE, TIMER_A);
}
Example #8
0
//*****************************************************************************
//
// This function is called to start an acquisition running.  It determines
// which channels are to be logged, enables the ADC sequencers, and computes
// the first RTC match value.  This will start the acquisition running.
//
//*****************************************************************************
void AcquireStart()
{
    unsigned long ulIdx;

    ulIdx = ulSelectedMask;
    g_ulNumItems = 0;
    while(ulIdx)
    {
        if(ulIdx & 1)
        {
            g_ulNumItems++;
        }
        ulIdx >>= 1;
    }



    //USBStickOpenLogFile(0);

    ROM_ADCSequenceEnable(ADC0_BASE,SEQUENCER);
    //ROM_ADCSequenceDataGet(ADC0_BASE,SEQUENCER,&g_ulADCData[0]);
    ROM_ADCIntClear(ADC0_BASE,SEQUENCER);

    ROM_ADCIntEnable(ADC0_BASE,SEQUENCER);
    ROM_IntEnable(INT_ADC0SS2);

    ROM_TimerEnable(TIMER0_BASE, TIMER_A);

    //ROM_IntEnable(INT_TIMER1A);
    //ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    //ROM_TimerEnable(TIMER1_BASE, TIMER_A);
    ROM_IntMasterEnable();
}
Example #9
0
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);

    }
Example #10
0
File: io.c Project: RevaReva/tiva-c
//*****************************************************************************
//
// 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);
    }
}
Example #11
0
//*****************************************************************************
//
// 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.
    //

}
Example #12
0
//*****************************************************************************
//
//! 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);
    }

}
Example #13
0
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);
	
}
Example #14
0
File: wiring.c Project: Osuga/TivaC
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);
}
Example #16
0
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);
}
Example #17
0
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);
}
Example #18
0
//*****************************************************************************
//
//! 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;
}
Example #19
0
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);
  }
}
Example #20
0
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);
}
Example #21
0
//*****************************************************************************
//
//! Initializes the touch screen driver.
//!
//! \param ui32SysClock is the frequency of the system clock.
//!
//! This function initializes the touch screen driver, beginning the process of
//! reading from the touch screen.  This driver uses the following hardware
//! resources:
//!
//! - ADC 0 sample sequence 3
//! - Timer 5 subtimer B
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenInit(uint32_t ui32SysClock)
{
    //
    // Set the initial state of the touch screen driver's state machine.
    //
    g_ui32TSState = TS_STATE_INIT;

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

    //
    // Enable the peripherals used by the touch screen interface.
    //
    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);
}
Example #22
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);
}
Example #23
0
//函数创建区
//----------------------------------------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();

}
Example #24
0
void
MonitorStart() {
	// Let the ISR know that this is the first entry
	// Important, can cause false shock detection
	// bug if omitted.
	first_entry = true;

	ROM_TimerEnable(TIMER1_BASE, TIMER_A);
	//
	// Disable ADC sequencers
	//
	ROM_ADCSequenceEnable(ADC1_BASE, 3);
}
Example #25
0
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);
}
Example #26
0
/*---------------------------------------------------------------------------*/
void
clock_init(void)
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
	TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()/1000);
	TimerControlStall(TIMER0_BASE,TIMER_A,true);
	TimerEnable(TIMER0_BASE, TIMER_A);

	ROM_IntEnable(INT_TIMER0A);
	ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	ROM_TimerEnable(TIMER0_BASE, TIMER_A);

	count = 0;
}
Example #27
0
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);
  
}
Example #28
0
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);
}
Example #29
0
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);
}
Example #30
0
// 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){}

}