Part Number: TMS570LS1227
Other Parts Discussed in Thread: HALCOGEN
Hi, I have the eQEP module running with a quadrature encoder in quadrature count mode. I have setup a position compare interrupt that fires with every unit position event and I can read the position counter successfully each time.
The problem is I need to measure the time between unit events and I’ve been trying to use the capture period register (QCPRD) without any success. The values I’m seeing drastically change value between successive reads while the waveform of the encoder is very stable. I am not seeing any Capture overflow error flag (COEF) but I do see a Capture direction error flag (CDEF) occasionally but there is very little information as to what this means. I have also tried the HALCoGen example (non ISR version) and I get the same result!
I’ve tried everything I can see, can you please help?
Code is below.
int main(void)
{
/* USER CODE BEGIN (3) */
/* enable irq interrupt in Cortex R4 */
_enable_interrupt_();
gioInit();
etpwmInit();
adcInit();
hetInit();
QEPInit();
hal_DisplayInit();
hal_unipolarWaveInit();
/* Enable Position Counter */
eqepEnableCounter(eqepREG1);
/* Enable position compare */
eqepEnablePosnCompare(eqepREG1);
/* Enable Unit Timer. */
eqepEnableUnitTimer(eqepREG1);
/* Enable capture timer and capture period latch. */
eqepEnableCapture(eqepREG1);
while(1)
{
//app code
}
}
/*Position compare interrupt. Fires every time the eQEP position counter changes */
void eqepNotification(eqepBASE_t *eqep,uint16 flags)
{
copy++;
/** Load the position compare value */
eqepREG1->QPOSCMP = copy+1U;
pulsePeriod = eqepREG1->QCPRD;
/** Read the position counter */
encoderVal = eqepReadPosnCount(eqepREG1);
eqepREG1->QCLR = (uint16) 0xFFFFU;
}
Below is from eqep.c
#include "eqep.h"
#include "sys_vim.h"
/*the functions
*/
/* USER CODE BEGIN (0) */
/* USER CODE END */
/** @fn void QEPInit(void)
* @brief Initializes the eQEP Driver
*
* This function initializes the eQEP module.
*/
/* SourceId : EQEP_SourceId_001 */
/* DesignId : EQEP_DesignId_001 */
/* Requirements : HL_QEP_SR1 */
void QEPInit(void)
{
/* USER CODE BEGIN (1) */
/* USER CODE END */
/** - Clear Position Counter register */
eqepREG1->QPOSCNT = 0x00000000U;
/** - Initialize Position Counter value register */
eqepREG1->QPOSINIT = 0x00000000U;
/** - Set Maximum position counter value */
eqepREG1->QPOSMAX = 0x000003E7U;
/** - Set the initial Position compare value */
eqepREG1->QPOSCMP = 0x00000001U;
/** - Clear the time base */
eqepREG1->QUTMR = 0x00000000U;
/** - Configure unit period register */
eqepREG1->QUPRD = (uint32) 0x00000000U;
/** - Clear Watchdog Timer register */
eqepREG1->QWDTMR = (uint16) 0x00000000U;
/** - Configure Watchdog Period */
eqepREG1->QWDPRD = (uint16) 0x0000U;
/* USER CODE BEGIN (2) */
/* USER CODE END */
/** - Setup Decoder Control Register
* - Select Position counter Mode
* - Enable / Disable Sync Output
* - Select Sync Output Pin
* - Select external Clock rate ( resolution)
* - Enable / Disable Swap Quadrature clock input
* - Enable / Disable Gating of index pulse with Strobe.
* - Enable / Disable Negate QEPA input
* - Enable / Disable Negate QEPB input
* - Enable / Disable Negate QEPI input
* - Enable / Disable Negate QEPS input
*/
eqepREG1->QDECCTL = (uint16)((uint16)((uint16)eQEP_QUADRATURE_COUNT << 14U)
| (uint16)((uint16)0U << 13U)
| (uint16)((uint16)eQEP_INDEX_PIN << 12U)
| (uint16)((uint16)eQEP_RESOLUTION_2x << 11U)
| (uint16)((uint16)0U << 10U)
| (uint16)((uint16)0U << 9U)
| (uint16)((uint16)0U << 8U)
| (uint16)((uint16)0U << 7U)
| (uint16)((uint16)0U << 6U)
| (uint16)((uint16)0U << 5U)
| (uint16)0x0000U);
/** - Setup eQEP Control Register
* - Select Position counter Reset Mode
* - Enable & Select Stobe event initialization of position counter
* - Enable & Select Index event initialization of position counter
* - Enable / Disable Software Initialization of Position counter.
* - Select Strobe event latch of position counter.
* - Select Index event latch of position counter.
* - Select EQEP capture Latch mode
*/
eqepREG1->QEPCTL = (uint16)((uint16)((uint16)eQEP_MAX_POSITION << 12U)
| (uint16)((uint16)0U << 11U )
| (uint16)((uint16)eQEP_DIRECTON_DEPENDENT << 10U)
| (uint16)((uint16)0U << 9U)
| (uint16)((uint16)eQEP_RISING_EDGE << 8U)
| (uint16)((uint16)1U << 7U)
| (uint16)((uint16)eQEP_RISING_EDGE << 6U)
| (uint16)((uint16)eQEP_LATCH_RISING_EDGE << 4U)
| (uint16)((uint16)eQEP_ON_POSITION_COUNTER_READ << 2U)
| (uint16)0x0000U);
/** - Setup eQEP Position Control Register
* - Enable / Disable Position compare shadow.
* - Select Position compare shadow load mode.
* - Select Polarity of Sync output.
* - Select Position compare sync output pulse width.
*/
eqepREG1->QPOSCTL = (uint16)((uint16)((uint16)0U << 15U)
| (uint16)((uint16)eQEP_QPOSCNT_EQ_QPSCMP << 14U)
| (uint16)((uint16)eQEP_ACTIVE_HIGH << 13U)
| (uint16)((uint16)0x000U)
| (uint16)0x0000U);
/** - Setup eQEP Capture Control Register
* - Select capture timer clock prescaler.
* - Select Unit position event prescaler.
*/
eqepREG1->QCAPCTL = (uint16)((uint16)((uint16)eQEP_PS_32 << 4U)//
| (uint16)((uint16)eQEP_PS_2) //unit events
| (uint16)0x0000U);
/* USER CODE BEGIN (3) */
/* USER CODE END */
/** - Clear Interrupt Flag register */
eqepREG1->QCLR = (uint16) 0xFFFFU;
/** - Setup eQEP Interrupt Enable Register
* Enable / Diable UTO Interrupt
* Enable / Diable IEL Interrupt
* Enable / Diable SEL Interrupt
* Enable / Diable PCM Interrupt
* Enable / Diable PCR Interrupt
* Enable / Diable PCO Interrupt
* Enable / Diable PCU Interrupt
* Enable / Diable WTO Interrupt
* Enable / Diable QDC Interrupt
* Enable / Diable QPE Interrupt
* Enable / Diable PCE Interrupt
*/
eqepREG1->QEINT = (uint16)((uint16)((uint16)0U << 11U)
| (uint16)((uint16)0U << 10U)
| (uint16)((uint16)0U << 9U)
| (uint16)((uint16)0U << 8U)
| (uint16)((uint16)0U << 7U)
| (uint16)((uint16)0U << 6U)
| (uint16)((uint16)0U << 5U)
| (uint16)((uint16)0U << 4U)
| (uint16)((uint16)0U << 3U)
| (uint16)((uint16)0U << 2U)
| (uint16)((uint16)0U << 1U));
/** - Clear Capture Timer register */
eqepREG1->QCTMR = (uint16)0x0000U;
/** - Clear the Capture Period regiter */
eqepREG1->QCPRD = (uint16)0x0000U;
/** - Clear Period Latch register */
eqepREG1->QCPRDLAT = (uint16)0x0000U;
/* USER CODE BEGIN (4) */
/* USER CODE END */
/** - Clear Position Counter register */
eqepREG2->QPOSCNT = 0x00000000U;
/** - Initialize Position Counter value register */
eqepREG2->QPOSINIT = 0x00000000U;
/** - Set Maximum position counter value */
eqepREG2->QPOSMAX = 0x00000000U;
/** - Set the initial Position compare value */
eqepREG2->QPOSCMP = 0x00000000U;
/** - Clear the time base */
eqepREG2->QUTMR = 0x00000000U;
/** - Configure unit period register */
eqepREG2->QUPRD = (uint32) 0x00000000U;
/** - Clear Watchdog Timer register */
eqepREG2->QWDTMR = (uint16) 0x00000000U;
/** - Configure Watchdog Period */
eqepREG2->QWDPRD = (uint16) 0x0000U;
/* USER CODE BEGIN (5) */
/* USER CODE END */
/** - Setup Decoder Control Register
* - Select Position counter Mode
* - Enable / Disable Sync Output
* - Select Sync Output Pin
* - Select external Clock rate ( resolution)
* - Enable / Disable Swap Quadrature clock input
* - Enable / Disable Gating of index pulse with Strobe.
* - Enable / Disable Negate QEPA input
* - Enable / Disable Negate QEPB input
* - Enable / Disable Negate QEPI input
* - Enable / Disable Negate QEPS input
*/
eqepREG2->QDECCTL = (uint16)((uint16)((uint16)eQEP_DIRECTION_COUNT << 14U)
| (uint16)((uint16)0U << 13U)
| (uint16)((uint16)eQEP_INDEX_PIN << 12U)
| (uint16)((uint16)eQEP_RESOLUTION_1x << 11U)
| (uint16)((uint16)0U << 10U)
| (uint16)((uint16)0U << 9U)
| (uint16)((uint16)0U << 8U)
| (uint16)((uint16)0U << 7U)
| (uint16)((uint16)0U << 6U)
| (uint16)((uint16)0U << 5U)
| (uint16)0x0000U);
/** - Setup eQEP Control Register
* - Select Position counter Reset Mode
* - Enable & Select Strobe event initialization of position counter
* - Enable & Select Index event initialization of position counter
* - Enable / Disable Software Initialization of Position counter.
* - Select Strobe event latch of position counter.
* - Select Index event latch of position counter.
* - Select EQEP capture Latch mode
*/
eqepREG2->QEPCTL = (uint16)((uint16)((uint16)eQEP_MAX_POSITION << 12U)
| (uint16)((uint16)0U << 11U)
| (uint16)((uint16)eQEP_DIRECTON_DEPENDENT << 10U)
| (uint16)((uint16)0U << 9U)
| (uint16)((uint16)eQEP_RISING_EDGE << 8U)
| (uint16)((uint16)0U << 7U)
| (uint16)((uint16)eQEP_RISING_EDGE << 6U)
| (uint16)((uint16)eQEP_LATCH_RISING_EDGE << 4U)
| (uint16)((uint16)eQEP_ON_POSITION_COUNTER_READ << 2U)
| (uint16)0x0000U);
/** - Setup eQEP Position Control Register
* - Enable / Disable Position compare shadow.
* - Select Position compare shadow load mode.
* - Select Polarity of Sync output.
* - Select Position compare sync output pulse width.
*/
eqepREG2->QPOSCTL = (uint16)((uint16)((uint16)0U << 15U)
| (uint16)((uint16)eQEP_QPOSCNT_EQ_QPSCMP << 14U)
| (uint16)((uint16)eQEP_ACTIVE_HIGH << 13U)
| (uint16)((uint16)0x000U)
| (uint16)0x0000U);
/** - Setup eQEP Capture Control Register
* - Select capture timer clock prescaler.
* - Select Unit position event prescaler.
*/
eqepREG2->QCAPCTL = (uint16)((uint16)((uint16)eQEP_PS_8 << 4U)
| (uint16)((uint16)eQEP_PS_512)
| (uint16)0x0000U);
/* USER CODE BEGIN (6) */
/* USER CODE END */
/** - Clear Interrupt Flag register */
eqepREG2->QCLR = (uint16) 0xFFFFU;
/** - Setup eQEP Interrupt Enable Register
* Enable / Diable UTO Interrupt
* Enable / Diable IEL Interrupt
* Enable / Diable SEL Interrupt
* Enable / Diable PCM Interrupt
* Enable / Diable PCR Interrupt
* Enable / Diable PCO Interrupt
* Enable / Diable PCU Interrupt
* Enable / Diable WTO Interrupt
* Enable / Diable QDC Interrupt
* Enable / Diable QPE Interrupt
* Enable / Diable PCE Interrupt
*/
eqepREG2->QEINT = (uint16)((uint16)((uint16)0U << 11U)
| (uint16)((uint16)0U << 10U)
| (uint16)((uint16)0U << 9U)
| (uint16)((uint16)0U << 8U)
| (uint16)((uint16)0U << 7U)
| (uint16)((uint16)0U << 6U)
| (uint16)((uint16)0U << 5U)
| (uint16)((uint16)0U << 4U)
| (uint16)((uint16)0U << 3U)
| (uint16)((uint16)0U << 2U)
| (uint16)((uint16)0U << 1U));
/** - Clear Capture Timer register */
eqepREG2->QCTMR = (uint16)0x0000U;
/** - Clear the Capture Period regiter */
eqepREG2->QCPRD = (uint16)0x0000U;
/** - Clear Period Latch register */
eqepREG2->QCPRDLAT = (uint16)0x0000U;
/* USER CODE BEGIN (7) */
/* USER CODE END */
}