Other Parts Discussed in Thread: EK-TM4C123GXL
Hello,
i try to implement a simple application, which can count the QEI edges. This edges are displayed at the console.
I use the TI-RTOS and the code compile without errors. The Problem is the output, which is always the same and varies by a maximum of 1.
I would be very grateful for help.
Output Console:Position: 500
Position: 499
Position: 499
Position: 499
Position: 500
Position: 500
/* XDCtools Header files */ #include <xdc/std.h> #include <xdc/runtime/System.h> #include <xdc/cfg/global.h> /* BIOS Header files */ #include <ti/sysbios/BIOS.h> /* Standard IO stream etc. */ #include <stdbool.h> // Defines for standard boolean representation. #include <stdio.h> // IO-stream for console display etc. /* Drivers etc. */ #include "inc/hw_ints.h" // Macros defining the interrupts. #include "inc/hw_memmap.h" // Macros defining the memory map of the device. #include "inc/hw_sysctl.h" // Macros for usage with SysCtl. #include "inc/hw_types.h" // Macros for common types. #include "driverlib/debug.h" // Macros to debug the driverlib. #include "driverlib/gpio.h" // Macros defining the GPIO assignments. #include "driverlib/pin_map.h" // Macros defining the pin map of the device. #include "driverlib/sysctl.h" // Prototypes for the SysCtl driver. #include "driverlib/qei.h" // for quadratur encoder /* Global variables */ // Put your global variables here. uint32_t Position; /* Function prototypes */ void Init_Clock(void); void ConfigureQEI0(void); /* * ======== main ======== */ void main(void) { printf("BIOS starting...\n"); // Initialize the main clock/oscillator. Init_Clock(); //QEI Module aktivieren ConfigureQEI0(); printf("Finished.\n"); // Start TI-RTOS. Everything is now controlled by the BIOS, as defined in your project .CFG file. BIOS_start(); } /* * ======== tasks ======== */ // This is the background task. void Task_Idle(void) { // Code here ... System_flush(); } // This is a repetitive task that is executed every 100 ms. // Timing can be modified in the .CFG file. void Task_100ms(void) { // Read the encoder position. Position = QEIPositionGet(QEI0_BASE); // display values in debug window System_printf("Position: %d\n", Position); } /* * ======== user functions ======== */ // This function initializes the clock/oscillator used in the project. void Init_Clock(void) { // Settings for 80 MHz. SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); return; } void ConfigureQEI0(){
printf("Initializing QEI ..."); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable the QEI0 peripheral // while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF)); SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0); // Enable the QEI0 peripheral // while(!SysCtlPeripheralReady(SYSCTL_PERIPH_QEI0)); // Wait for the QEI0 module to be ready. //Set Pins to be PHA0 and PHB0 GPIOPinConfigure(GPIO_PF0_PHA0); GPIOPinConfigure(GPIO_PF1_PHB0); GPIOPinTypeQEI(GPIO_PORTF_BASE, GPIO_PIN_0); GPIOPinTypeQEI(GPIO_PORTF_BASE, GPIO_PIN_1); //DISable peripheral and int before configuration QEIDisable(QEI0_BASE); QEIIntDisable(QEI0_BASE,QEI_INTERROR | QEI_INTDIR | QEI_INTTIMER | QEI_INTINDEX); QEIConfigure(QEI0_BASE, QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP, 1000); // enable QEI module QEIEnable(QEI0_BASE); //Set Register start Values QEIPositionSet(QEI0_BASE,500); printf(" done.\n"); return; } // End of file.