I'm new to Tiva and has just finish the basic examples in Tiva Lauchpad Workshop. My very first project is to close-looped control the DC motor's velocity so I'm trying to work with the QEI module for velocity feedback. The code shown below is my build base on the posts about QEI on this forum and the Tiva Peripheral Library document.
This code was built and debugged without error. The problem is when I try to place a breakpoint on the line which calculate the qei_velocity variable, then configure the breakpoint to update the value of velocity on the expression window without halting the result is always 0. I don't know if there's anything not right in the code itself, the way I place the breakpoint or the hardware (which I believe is right).
Here's the code:
#include <stdbool.h>
#include <stdint.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/qei.h"
int qei_position;
int qei_velocity;
extern void QEI1IntHandler(void)
{
unsigned long status;
status = QEIIntStatus(QEI1_BASE, false);
if ((status & QEI_INTTIMER) == QEI_INTTIMER)
{
QEIIntClear(QEI1_BASE, QEI_INTTIMER);
qei_position = QEIPositionGet(QEI1_BASE);
qei_velocity = QEIVelocityGet(QEI1_BASE) * QEIDirectionGet(QEI1_BASE);
}
}
void main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
QEIConfigure(QEI1_BASE, QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET
| QEI_CONFIG_QUADRATURE | QEI_CONFIG_SWAP, 0xFFFFFFFF);
GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6);
GPIOPinConfigure(GPIO_PC5_PHA1);
GPIOPinConfigure(GPIO_PC6_PHB1);
QEIVelocityConfigure(QEI1_BASE, QEI_VELDIV_2, SysCtlClockGet()/50); //20 ms period
QEIVelocityEnable(QEI1_BASE);
QEIEnable(QEI1_BASE);
QEIIntEnable(QEI1_BASE, QEI_INTTIMER);
QEIIntRegister(QEI1_BASE, &QEI1IntHandler);
IntEnable(INT_QEI1);
IntMasterEnable();
GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD_WPU);
while(1)
{
}