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.
Hi, I am trying to use a modified version of Lab12b in a dynamometer setup.
I think there are some qep objects that should be able to help me note which direction the motor is turning (QPOSCMP) and how many times it has turned (QPOSLAT). Can anyone confirm if these are the correct objects to look at?
If so, i need some help determining what i am doing wrong. I've pretty much disabled most of the enc_Run function and added in the following code:
void ENC_run(ENC_Handle encHandle, uint32_t posnCounts, uint16_t indextFlag, uint16_t dirFlag, int16_t log_flag) { ENC_Obj *enc; // create an object pointer for manipulation enc = (ENC_Obj *) encHandle; // read QEP direction from quadrature direction latch flag enc->dir = dirFlag; // check for index event after the encoder reading enc->index_flag = indextFlag; // handle a rollover event if (enc->index_flag){ if (enc->dir){ enc->rotations++; } else{ enc->rotations--; } } }// end of ENC_run() function
Per this forum topic (https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/501438/how-to-use-enc-qep-modules-to-measure-motor-speed-by-an-incremental-encoder), I added this to the proj_lab12b.c main ISR:
// run the ENC module ENC_run(encHandle, HAL_getQepPosnCounts(halHandle), HAL_getQepIndex(halHandle), HAL_getQepDirection(halHandle), true);
and this to hal.h:
#ifdef QEP //! \brief Return the index info from the QEP module //! \param[in] encHandle Handle to the ENC object //! \return The flag that indicate the index of encoder (true or false) inline uint16_t HAL_getQepIndex(HAL_Handle handle) { HAL_Obj *obj = (HAL_Obj *)handle; return (uint16_t)((QEP_QEPSTS_FIMF & QEP_read_status(obj->qepHandle[0]))>>1); } //! \brief Return the direction info from the QEP module //! \param[in] encHandle Handle to the ENC object //! \return The flag that indicate the direction of rotation (true or false) inline uint16_t HAL_getQepDirection(HAL_Handle handle) { HAL_Obj *obj = (HAL_Obj *)handle; //Added by Duongtb (24/4/2016) return (uint16_t)((QEP_QEPSTS_QDF & QEP_read_status(obj->qepHandle[0]))>>5); } #endif
When I run this project, enc.dir does not change until the current motion stops. Also, once enc.index_flag goes to 1, it stays there. What else do i need to do to make this work?
Is there a better way to do this without using SpinTAC?
Can anyone help?
Hello Deborah Curtis, The latest examples we support are based on C2000Ware driverlib and are available in Motor control SDK - https://www.ti.com/tool/C2000WARE-MOTORCONTROL-SDK
We got API for knowing the rotation direction - int16_t EQEP_getDirection
(uint32_t base) and the information can be found at https://software-dl.ti.com/C2000/docs/C2000_driverlib_api_guide/f28002x/html/modules/eqep.html
Let me know if a call would help to let you aware of latest solutions and how it could be leveraged for your projects.
Hi Navaneeth,
Thank you for your response. Yes, a call would be greatly appreciated!
I've had a look at the motor control SDK before posting in the forum and did not find anything useful. If you could point to a specific example, it would also be appreciated.
The link you provided for the EQEP_getDirection function looks like it is for a different controller (the F28002x while I am using the F28069). Is it still applicable to my controller? I was able to find the TMS320x2806x Piccolo Technical Reference Manual (Rev. H) (https://www.ti.com/lit/ug/spruh18h/spruh18h.pdf?ts=1652085372785&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FTMS320F28069M) where I do not see it mentioned in EQEP section.
Any advice on the code I provided?
Hi Deborah,
I am looking into your question. I will get back to you within 24 hours.
Best regards
Lori
When I run this project, enc.dir does not change until the current motion stops.
Deborah,
It looks like you are checking the right flag - that is the direction of rotation of motor based on the QEP inputs.
"Quadrature direction flag" QDF in the QEPSTS Register Field Descriptions.
If I understand, the value returned from the function is always 0?
Can you check the register value in code composer studio's register view and see if it matches?
Also, once enc.index_flag goes to 1, it stays there.
This seems to be expected. This flag marks the first index pulse. From the Technical Reference Manual (TRM):
First index marker flag
Note: Once this flag has been set, if the flag is cleared the flag will not be set again until the module is reset by a peripheral or system reset.
Is there a better way to do this without using SpinTAC?
In C2000Ware, there are a couple of QEP examples for F28069. These leverage bit-fields that are overlayed onto the registers. In this example the QDF bit being read is on line 175. You can explore the example through the link below, or download the C2000Ware core SDK here: https://www.ti.com/tool/C2000WARE
Link to example in the cloud:
https://dev.ti.com/tirex/explore/node?node=ANXjOxtkH2K9osaeRlAJVw__gYkahfz__LATEST