This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

QEI not working

Other Parts Discussed in Thread: LM393

Hi Guys,


I'm using the FreeRTOS demo that came with the Stellaris files and want to add a quadrature encoder interface.

Although CCS doesn't give me an error, the µc freezes when I want to configure the interface?
Also I needed to add the register settings manually to the pin_map.h

in pin_map.h I've added:

// LM4F120H5QR Port/Pin Mapping Definitions
#define GPIO_PC5_PHA1            0x00021406
#define GPIO_PC6_PHB1            0x00021806

Here's my code, like I said when adding the QEI configuration (code in bold) the µc freezes but I don't get an error.
When I comment the code out, everything works fine..

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/adc.h"
#include "inc/lm4f120h5qr.h"
#include "utils/uartstdio.h"
#include "led_task.h"
#include "switch_task.h"
#include "routine_task.h"
#include "dht_task.h"
#include "qei_task.h"
#include "lm393_adc.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "driverlib/qei.h"
#include "driverlib/pwm.h"
#include "pwm_task.h"
#include "inc/hw_i2c.h"
#include "driverlib/i2c.h"
#include "display/oled.h"

xSemaphoreHandle g_pUARTSemaphore;
xSemaphoreHandle xCountingSemaphore;
xSemaphoreHandle rCountingSemaphore;

#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}

#endif

void
vApplicationStackOverflowHook(xTaskHandle *pxTask, signed char *pcTaskName)
{
    while(1)
    {
    }
}

//    Set I2C    : 0    :    MASTER
void I2C_init(void){
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
    I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), true);

}

int
main(void)
{

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);  //for DHT
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);  //for UART
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);  //for I2C
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);  //for QEI1
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);  //for ADC
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //for Timer 0

    GPIOPinConfigure(GPIO_PC5_PHA1);  //Quadrature Encoder
    GPIOPinConfigure(GPIO_PC6_PHB1);
    GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 |  GPIO_PIN_6);
    //QEIDisable(QEI1_BASE);
    //QEIIntDisable(QEI1_BASE,QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX);
    // Configure quadrature encoder
    //QEIConfigure(QEI1_BASE, (QEI_CONFIG_CAPTURE_A_B  | QEI_CONFIG_NO_RESET     | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 23);

    // Enable the quadrature encoder.
    //QEIEnable(QEI1_BASE);

    //Set position to a middle value so we can see if things are working
    //QEIPositionSet(QEI1_BASE, 0);

    GPIOPinConfigure(GPIO_PA0_U0RX);  //UART
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);

    //ADC
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);

    SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);
    ADCHardwareOversampleConfigure(ADC0_BASE, 64);
    ADCSequenceDisable(ADC0_BASE, 1);
    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 0,0, ADC_CTL_CH0);
    ADCSequenceEnable(ADC0_BASE,0);

    I2C_init();
    Display_Boot();
    PWM_init(50);

    UARTprintf("\n\nWelcome to the Stellaris EK-LM4F120 FreeRTOS Demo!\n");

    g_pUARTSemaphore = xSemaphoreCreateMutex();
    xCountingSemaphore = xSemaphoreCreateCounting(50,0); //for interrupt semaphore in dht_task
    rCountingSemaphore = xSemaphoreCreateCounting(10,0); //for interrupt semaphore in routine_task

    // Create Tasks.
    if(LEDTaskInit() != 0){while(1){}}  //LED
    if(SwitchTaskInit() != 0){while(1){}} //SWITCH
    if(xCountingSemaphore != NULL){
        if(DHTTaskInit() != 0){while(1){}} //DHT
     }else{
        UARTprintf("failed to create counting semaphore");
    }
    //if(LM393TaskInit() != 0){while(1){}}
    if(RoutineTaskInit() != 0){while(1){}}
    //if(QeiTaskInit() != 0){while(1){}}

    vTaskStartScheduler();

    while(1)
    {
    }
}