Other Parts Discussed in Thread: MOTORWARE
Tool/software: Code Composer Studio
Hi, I'm having trouble to integrate an absolute encoder with my InstaSpin development board.
I have done all motorware labs and sucessfuly had a ABI encoder to run my motor. I'm running lab 12b (sensored speed control).
My problem is very simmilar to this thread: https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/663317
I mannaged to receive the encoder signal via SPI (20 bits) and already done the "interpolation" to 24bits (_iq24). Now I have a position variable that tells me exactly what is my mechanical angle.
I'm trying to replace the QEP module with my own.
This is the code to get the electrical angle:
void incoderGetElecAngle(){
uint32_t temp = incAbsPos; //mech angle
temp += incMechOffset;
temp *= USER_MOTOR_NUM_POLE_PAIRS;
elecAngle = (_iq24)(temp & 0x00ffffff);
}
incAbsPos is a global variable that is updated by the SPI readings, incMechOffset is a variable that is, for now, zero. My encoder has a option to set the zero. I power the motor to align it and reset the zero in the encoder.
elecAngle is the output, saved in a global.
I can turn the motor and feel the 21 pole pairs swithcing and the electrical angle correctly apearing in the debug (I did a graphing for absolute and electrical angle and they are perfectly in sync, I can see 21 cycles for electrical for 1 cycle of mechanical).
In mainISR, this is my code:
interrupt void mainISR(void)
{
static uint16_t stCnt = 0;
CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;
//Do SPI reading of encoder and refresh the global variable(incoder is a brand)
SPI_ReadIncoder();
// convert the ADC data
HAL_readAdcData(halHandle,&gAdcData);
// Run the SpinTAC Components
if(stCnt++ >= ISR_TICKS_PER_SPINTAC_TICK) {
ST_runPosConv(stHandle, encHandle, ctrlHandle);
ST_runVelCtl(stHandle, ctrlHandle);
stCnt = 1;
}
CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData, elecAngle);
// write the PWM compare values
HAL_writePwmData(halHandle,&gPwmData);
// setup the controller
CTRL_setup(ctrlHandle);
// if we are forcing alignment, using the Rs Recalculation, align the eQEP angle with the rotor angle
if((EST_getState(obj->estHandle) == EST_State_Rs) && (USER_MOTOR_TYPE == MOTOR_Type_Pm))
{
incMechOffset = incMaxPos - incAbsPos; // same as the QEP, bur here "incAbsPos" is already a mechanical angle,so no need to gain
}
HAL_acqAdcInt(halHandle,ADC_IntNumber_1);
return;
} // end of mainISR() function
and here is my ST_runPosConv code:7
void ST_runPosConv(ST_Handle handle, ENC_Handle encHandle, CTRL_Handle ctrlHandle)
{
ST_Obj *stObj = (ST_Obj *)handle;
#ifdef INCODERELECANGLE //if defined, gets encoder elec angle
STPOSCONV_setElecAngle_erev(stObj->posConvHandle, elecAngle);
#else
// get the electrical angle from the ENC module
STPOSCONV_setElecAngle_erev(stObj->posConvHandle, ENC_getElecAngle(encHandle));
#endif
/*
if(USER_MOTOR_TYPE == MOTOR_Type_Induction) {
// The CurrentVector feedback is only needed for ACIM
// get the vector of the direct/quadrature current input vector values from CTRL
STPOSCONV_setCurrentVector(stObj->posConvHandle, CTRL_getIdq_in_addr(ctrlHandle));
}
*/
// run the SpinTAC Position Converter
STPOSCONV_run(stObj->posConvHandle);
/*
if(USER_MOTOR_TYPE == MOTOR_Type_Induction) {
// The Slip Velocity is only needed for ACIM
// update the slip velocity in electrical angle per second, Q24
SLIP_setSlipVelocity(slipHandle, STPOSCONV_getSlipVelocity(stObj->posConvHandle));
}
*/
}
I tested both with or without the "force alignment" routine, no matter what I do, change polarities, realign the encoder, I cannot put the motor to spin.
I'm I missing something?
Sory for my poor english.
Much thanks in advance.