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.

TMS570LC4357: Explaination regarding the example_eqepEdgeCapture

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

I am using a 600PPR/2400CPR rotary quadrature encoder which outputs Channel A and Channel B quadrature outputs. It doesn't output any Index output.

I connected the Encoder Channel A to EQEP1_A and Encoder Channel B to EQEP1_B, also I grounded the EQEP1_I just to be sure.

When I run the code, in debug menu, the velocity remains 0.0 even when I rotate the encoder.

I modified the code to show me encoder position and the position is getting updated just fine, but the velocity remains zero.

I have the following doubts:

1) I set the UNIT_POSITION_X as

#define UNIT_POSITION_X 2400U

is that correct for my case?

2) What is the unit of the deltaT? And how is it generated?

3) What is the unit of velocity I am getting from the code? Why is it constantly 0 even when I constantly rotate the encoder?

I have attached my project here for reference    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/312/2210.EQEP_5F00_EDGE_5F00_CAPTURE.7z 

  • For quick reference here's the code:
    
    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "HL_sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "HL_eqep.h"
    #include "HL_sys_core.h"
    /* USER CODE END */
    
    
    /* USER CODE BEGIN (2) */
    #define UNIT_POSITION_X 2400U
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
    
    	uint16 deltaT = 0U;
    	int position = 0;
    	float velocity = 0U;
    	/* EQEP initialization based on GUI Configuration. */
    	QEPInit();
    
    	/* Enable Position Counter */
    	eqepEnableCounter(eqepREG1);
    
    	/* Enable Unit Timer. */
    	eqepEnableUnitTimer(eqepREG1);
    
    	/* Enable capture timer and capture period latch. */
    	eqepEnableCapture(eqepREG1);
    
    	while(1)
    	{
    		/* Status flag is set to indicate that a new value is latched in the QCPRD register. */
    		if((eqepREG1->QEPSTS & 0x80U) !=0U)
    		{
    			/* Elapsed time between unit position events */
    			deltaT = eqepREG1->QCPRD;
    
    			position = eqepREG1->QPOSCNT;
    
    			/* Calculate Velocity from deltaT and the value of the unit position. */
    			/* The value of Unit Position is a sample value and should be changed by the User as per the actual value in the UNIT_POSITION_X macro above. */
    			velocity = (float)(UNIT_POSITION_X/deltaT);
    
    			/* Clear the Status flag. */
    			eqepREG1->QEPSTS |= 0x80U;
    		}
    	}
    /* USER CODE END */
    
        return 0;
    }
    
    
    /* USER CODE BEGIN (4) */
    /* USER CODE END */

    and the EQEP1 configuration from HALCoGen:


  • Hi Yash,
    Did you have a chance to run the HalCoGen example? Did it work for you?

    Today and Tomorrow are U.S. public holiday. Please expect delay in response.
  • Hello Charles,
    Yes, I did run the HALCoGen example: example_eqepEdgeCapture but was unable to get the velocity measurements as mentioned above.

    Also, I was unable to understand how the deltaT variable works (its unit and functioning) and what I should be keeping the value of UNIT_POSITION_X for my case.

    My modifications to the code did not change any functionality of it, rather I am just observing a few more variables.
  • Hi Yash,
    What did you read on the deltaT?

    Please note that the method of using the equation: v = X/deltaT where X = Unit position defined by integer multiple of quadrature edges is typically used for low speed measurement. Please refer to the eQEP usergude for details.
  • Hello Charles,
    I am reading values ranging anywhere between 5,000 to 60,000 in deltaT.

    I have gone through the eQEP section of the Technical Reference Manual and Datasheet, and understand the formula used.
    But the problem is, I am getting 0 for velocity most of the time, and don't understand the units of deltaT (is it in seconds, mS, uS etc.).

    Also, I have put 2400 as the value for UNIT_POSITION_X. Is that correct?

  • I've done a test with Hercules and rotary encoders. The blog below has my set-up.

    I'm working on a BoosterPack with a quadrature encoder and a GaN Half Bridge;

  • Hello Jan,
    I went through your blog and found it really educating. However, It doesn't answer the doubts I asked in this post.

    I am unable to get the velocity of my encoder (you have not implemented that in your project).
    The example code that TI provides doesn't explain clearly what value does deltaT represent (and its unit) and what to put in the UNIT_POSITION_X for a given encoder specification. Using the example code the velocity always comes to be zero.
  • I'll recheck the behaviour, Yash. I was under the (possibly wrong) impression that the eQEP module behaved propotional to the speed that I turn the encoder. This may be me wanting my wish to be reality more than me reading the TRM :)