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.

TMS320F28069M: Lab 12b: Direction & rotation count from encoder without using SpinTAC

Part Number: TMS320F28069M
Other Parts Discussed in Thread: C2000WARE

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:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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--;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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: 

Fullscreen
1
2
3
4
5
6
// run the ENC module
ENC_run(encHandle,
HAL_getQepPosnCounts(halHandle),
HAL_getQepIndex(halHandle),
HAL_getQepDirection(halHandle),
true);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and this to hal.h:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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?