Dear Motorware team,
I'm trying to read motor speed which is used by an Encoder (1024 pulses per revolution and the output signals are A, B and Z). I referenced the lab12a, b and included two modules (qep.h/qep.c and enc.h/enc.c) in my project and used the following functions in order to get the speed info from the encoder.
So that, I declared in user.h
#elif (USER_MOTOR == My_Motor_ACIM)
#define USER_MOTOR_TYPE MOTOR_Type_Induction
#define USER_MOTOR_NUM_POLE_PAIRS (2) //!> PAIRS, not total poles. Used to calculate user RPM from rotor Hz only
#define USER_MOTOR_Rr (0.9621) //!> Identified phase to neutral in a Y equivalent circuit (Ohms, float)
#define USER_MOTOR_Rs (1.05) //!> Identified phase to neutral in a Y equivalent circuit (Ohms, float)
#define USER_MOTOR_Ls (0.0842)
#define USER_MOTOR_Ls_d (0.0842) //!> For Induction, Identified average stator inductance (Henry, float)
#define USER_MOTOR_Ls_q (0.0842) //!> For Induction, Identified average stator inductance (Henry, float)
#define USER_MOTOR_RATED_VOLTAGE (350) //!> The rated volate of the motor
#define USER_MOTOR_RATED_FREQ_Hz (52.7) //!> The rated frequency of the motor
#define USER_MOTOR_RATED_FLUX (0.8165*350.0/52.7) //!> The rated flux = sqrt(2/3)* Rated V (line-line) / Rated Freq (Hz)
#define USER_MOTOR_MAGNETIZING_CURRENT (7.2509) //!> Identified magnetizing current for induction motors, else NULL
#define USER_MOTOR_RES_EST_CURRENT (1.0) //!> During Motor ID, maximum current (Amperes, float) used for Rs estimation, 10-20% rated current
#define USER_MOTOR_IND_EST_CURRENT (NULL) //!> Must be ZERO/NULL for ACIM motors
#define USER_MOTOR_MAX_CURRENT (13.0) //!> Max. nameplate current of the motor.
//!> CRITICAL: Used during ID and run-time, sets a limit on the maximum current command output of the provided Speed PI Controller to the Iq controller
#define USER_MOTOR_FLUX_EST_FREQ_Hz (5.0) //!> For IPM, set to 20.0Hz; for ACIM, set to 5.0Hz
#define USER_MOTOR_ENCODER_LINES (1024.0) //!> Added by Duongtb (24-Mar-2016)
#define USER_MOTOR_MAX_SPEED_KRPM (3.0) //!> Added by Duongtb (24-Mar-2016)
#define USER_SYSTEM_INERTIA (0.02) //!> Added by Duongtb (24-Mar-2016)
#define USER_SYSTEM_FRICTION (0.01) //!> Added by Duongtb (24-Mar-2016)
In the HAL_setupGpios() function, I set up:
// GPIO-20: PIN FUNCTION = EQEPA GPIO_setMode(obj->gpioHandle,GPIO_Number_20,GPIO_20_Mode_EQEP1A); GPIO_setQualification(obj->gpioHandle,GPIO_Number_20,GPIO_Qual_Sample_3); // GPIO-21: PIN FUNCTION = EQEPB GPIO_setMode(obj->gpioHandle,GPIO_Number_21,GPIO_21_Mode_EQEP1B); GPIO_setQualification(obj->gpioHandle,GPIO_Number_21,GPIO_Qual_Sample_3); // GPIO-23: PIN FUNCTION = EQEP1I GPIO_setMode(obj->gpioHandle,GPIO_Number_23,GPIO_23_Mode_EQEP1I); GPIO_setQualification(obj->gpioHandle,GPIO_Number_23,GPIO_Qual_Sample_3);
In the main() function, I setup:
halHandle = HAL_init(&hal,sizeof(hal));
// set the hardware abstraction layer parameters
HAL_setParams(halHandle,&gUserParams);
//!> initialize and setup the Encoder modude - Added by Duongtb (24-Mar-2016)
{
// initialize the ENC module
encHandle = ENC_init(&enc, sizeof(enc));
// setup the ENC module
ENC_setup(encHandle,
1,
USER_MOTOR_NUM_POLE_PAIRS,
USER_MOTOR_ENCODER_LINES,
0,
USER_IQ_FULL_SCALE_FREQ_Hz,
USER_ISR_FREQ_Hz,
8000.0);
}
Notice that, the QEP_init() function is called in HAL_init() as following:
//! \Brief Initializes all Hardware Drives that is used in the project.
HAL_Handle HAL_init(void *pMemory,const size_t numBytes)
{
uint_least8_t cnt;
HAL_Handle handle;
HAL_Obj *obj;
...
#ifdef QEP
// initialize QEP driver
obj->qepHandle[0] = QEP_init((void*)QEP1_BASE_ADDR,sizeof(QEP_Obj));
#endif
...
return;
}
and the QEP_setup() is called in the HAL_setupparams() as following:
//! \Brief Setting up the parameters which is used in every module of HAL
void HAL_setParams(HAL_Handle handle,const USER_Params *pUserParams)
{
uint_least8_t cnt;
HAL_Obj *obj = (HAL_Obj *)handle;
_iq beta_lp_pu = _IQ(pUserParams->offsetPole_rps/(float_t)pUserParams->ctrlFreq_Hz);
...
#ifdef QEP
// setup the QEP
HAL_setupQEP(handle,HAL_Qep_QEP1);
#endif
...
return;
}
In the mainISR() function, I called:
// compute the electrical angle which is get from Encoder ENC_calcElecAngle(encHandle, HAL_getQepPosnCounts(halHandle)); // get the feedback speed in kilo rpm gMotorVars.Speed_krpm = ENC_getSpeedRPM(encHandle);
However, when I run motor in debug mode, I always see the value of gMotorVars.Speed_krpm = ZERO???
I think it maybe I have not know how to use two modules to get the right result, although I checked the A, B and Z signals on my hardware and the result is good.
Could you please guide me to resolve this problem.
Many thanks,
Mr. Tran