Exemplo n.º 1
0
//*****************************************************************************
//
// This function prepares the quadrature encoder module for capturing the
// position and speed of the motor.
//
//*****************************************************************************
void
EncoderInit(void)
{
    //
    // Configure the QEI pins.
    //
    ROM_GPIOPinTypeQEI(QEI_PHA_PORT, QEI_PHA_PIN);
    ROM_GPIOPinTypeQEI(QEI_PHB_PORT, QEI_PHB_PIN);
    ROM_GPIOPinTypeQEI(QEI_INDEX_PORT, QEI_INDEX_PIN);

    //
    // Configure the QEI module.
    //
    ROM_QEIConfigure(QEI0_BASE,
                     (QEI_CONFIG_RESET_IDX | QEI_CONFIG_CAPTURE_A |
                      QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 0xffffffff);

    //
    // Initialize the QEI position to zero.
    //
    ROM_QEIPositionSet(QEI0_BASE, 0);

    //
    // Enable the QEI module.
    //
    ROM_QEIEnable(QEI0_BASE);

    //
    // Configure the encoder input to generate an interrupt on every rising
    // edge.
    //
    ROM_GPIOIntTypeSet(QEI_PHA_PORT, QEI_PHA_PIN, GPIO_RISING_EDGE);
    ROM_GPIOPinIntEnable(QEI_PHA_PORT, QEI_PHA_PIN);
    ROM_IntEnable(QEI_PHA_INT);
}
Exemplo n.º 2
0
char run()
{
    unsigned long period = (SysCtlClockGet() / multi2hz(interval)) / 2;

    stop();

    led(1,0,0);

    clear_buf();

    if (mode == MODE_INTERVAL)
    {
        ROM_IntEnable(INT_TIMER0A);
        ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, period - 1);
        ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
        ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
 
        if (trigger == TRIGGER_IMMEDIATE)
        {
            ROM_TimerEnable(TIMER0_BASE, TIMER_A);
        }
        else if (trigger == TRIGGER_PIN_RISING)
        {
            ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_RISING_EDGE);
            ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff);
            ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins);
            ROM_IntEnable(INT_GPIOB);
        }
        else if (trigger == TRIGGER_PIN_FALLING)
        {
            ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_FALLING_EDGE);
            ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff);
            ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins);
            ROM_IntEnable(INT_GPIOB);
        }
        else if (trigger == TRIGGER_PIN_BOTH)
        {
            ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, 1, GPIO_BOTH_EDGES);
            ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff);
            ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins);
            ROM_IntEnable(INT_GPIOB);
        }
    }
    else if (mode == MODE_EVENT)
    {
        if (trigger == TRIGGER_PIN_FALLING)
        {
            ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_FALLING_EDGE);
            ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff);
            ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins);
            ROM_IntEnable(INT_GPIOB);
        }
        else if (trigger == TRIGGER_PIN_RISING)
        {
            ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_RISING_EDGE);
            ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff);
            ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins);
            ROM_IntEnable(INT_GPIOB);
        }
        else if (trigger == TRIGGER_PIN_BOTH)
        {
            ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, trigger_pins, GPIO_BOTH_EDGES);
            ROM_GPIOPinIntClear(GPIO_PORTB_BASE, 0xff);
            ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, trigger_pins);
            ROM_IntEnable(INT_GPIOB);
        }

        HWREG(NVIC_ST_CURRENT) = 0;
    }
    ROM_IntMasterEnable();

    sampling = SAMPLING_ON;

    return STATE_GET_COMMAND;
}
Exemplo n.º 3
0
//*****************************************************************************
//
// Toggle the JTAG pins between JTAG and GPIO mode with a push button selecting
// between the two.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulMode;

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Enable the peripherals used by this application.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Configure the push button as an input and enable the pin to interrupt on
    // the falling edge (i.e. when the push button is pressed).
    //
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_4);
    ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,
                         GPIO_PIN_TYPE_STD_WPU);
    ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE);
    ROM_GPIOPinIntEnable(GPIO_PORTB_BASE, GPIO_PIN_4);
    ROM_IntEnable(INT_GPIOB);

    //
    // Configure the LED as an output and turn it on.
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
    ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0);

    //
    // Set the global and local indicator of pin mode to zero, meaning JTAG.
    //
    g_ulMode = 0;
    ulMode = 0;

    //
    // Initialize the UART.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);
    UARTprintf("\033[2JGPIO <-> JTAG\n");

    //
    // Indicate that the pins start out as JTAG.
    //
    UARTprintf("Pins are JTAG\n");

    //
    // Loop forever.  This loop simply exists to display on the UART the
    // current state of PC0-3; the handling of changing the JTAG pins to and
    // from GPIO mode is done in GPIO Interrupt Handler.
    //
    while(1)
    {
        //
        // Wait until the pin mode changes.
        //
        while(g_ulMode == ulMode)
        {
        }

        //
        // Save the new mode locally so that a subsequent pin mode change can
        // be detected.
        //
        ulMode = g_ulMode;

        //
        // See what the new pin mode was changed to.
        //
        if(ulMode == 0)
        {
            //
            // Indicate that PC0-3 are currently JTAG pins.
            //
            UARTprintf("Pins are JTAG\n");
        }
        else
        {
            //
            // Indicate that PC0-3 are currently GPIO pins.
            //
            UARTprintf("Pins are GPIO\n");
        }
    }
}