Other Parts Discussed in Thread: DRV8301, DRV8302, INSTASPIN-BLDC, CONTROLSUITE
Tool/software: Code Composer Studio
Hello,
I'm using DRV 8301 HC_EVM devlopment kit with F28035 controller card. I'm using a maxon EC motor as given in the attachment. I successfully executed InstaSpin_BLDC Project. This project is a sensorless control and for my application, I need to control the motor using quadrature encoder. Below was the snippet used in the project (edited level-8) to control the motor using QEP.
#if (BUILDLEVEL==LEVEL8) //QEP Testing -Teja
_iq IDCfdbk;
// ------------------------------------------------------------------------------
// ADC conversion and offset adjustment
// Not used, reading is taken for debugging
// ------------------------------------------------------------------------------
#if defined(DRV8301) || defined(DRV8302)
IDCfdbk=-((_IQ15toIQ(AdcResult.ADCRESULT4<<3)-IDC_offset)<<1);
#endif
// ------------------------------------------------------------------------------
// Connect inputs of the IMPULSE module and call the Impulse macro.
// ------------------------------------------------------------------------------
impl1.Period = rmp3.Out;
IMPULSE_MACRO(impl1)
// ------------------------------------------------------------------------------
// Connect inputs of the MOD6 module and call the Modulo 6 counter macro.
// ------------------------------------------------------------------------------
if(DfuncStartup > _IQ(0.0))
{
mod_dir1.CntDirection = _IQ(1.0);
}
else
{
mod_dir1.CntDirection = _IQ(-1.0);
}
mod_dir1.TrigInput = impl1.Out;
PreviousState = mod_dir1.Counter;
MOD6CNTDIR_MACRO(mod_dir1)
QEP_MACRO(qep1);
// ------------------------------------------------------------------------------
// Connect inputs of the SPEED_FR module and call the speed calculation macro
// ------------------------------------------------------------------------------
speed2.ElecTheta = _IQ24toIQ((int32)qep1.ElecTheta);
speed2.DirectionQep = (int32)(qep1.DirectionQep);
SPEED_FR_MACRO(speed2)
// ------------------------------------------------------------------------------
// Connect inputs of the RMP3 module and call the Ramp control 3 macro.
// ------------------------------------------------------------------------------
rmp3.DesiredInput = CmtnPeriodTarget;
rmp3.Ramp3Delay = RampDelay;
RC3_MACRO(rmp3)
// ------------------------------------------------------------------------------
// Connect inputs of the PID_REG3 module and call the PID speed controller
// macro.
// ------------------------------------------------------------------------------
if ( lsw == TRUE && (SpeedLoopCount >= SpeedLoopPrescaler) )
{
pid1_spd.term.Ref = SpeedRef; //SpeedRef = 0.3
pid1_spd.term.Fbk = speed2.Speed;
PID_GR_MACRO(pid1_spd)
SpeedLoopCount = 1;
}
else
{
SpeedLoopCount++;
}
if ( lsw == FALSE)
{
pid1_spd.data.ui = 0;
pid1_spd.data.i1 = 0;
SpeedLoopCount = 1;
}
// ------------------------------------------------------------------------------
// Connect inputs of the PID_REG3 module and call the PID current controller
// macro.
// ------------------------------------------------------------------------------
pid1_idc.term.Ref = pid1_spd.term.Out;
pid1_idc.term.Fbk = IDCfdbk;
PID_GR_MACRO(pid1_idc)
// ------------------------------------------------------------------------------
// Connect inputs of the PWM_DRV module and call the PWM signal generation
// update macro.
// ------------------------------------------------------------------------------
pwmcntl1.State = (int16)mod_dir1.Counter;
if( lsw == TRUE)
{
pwmcntl1.Duty = pid1_idc.term.Out;
}
else
{
pwmcntl1.Duty = DfuncStartup;
}
PWM_CNTL_MACRO(pwmcntl1)
//------------------------------------------------------------------------------
// Connect inputs of the DATALOG module
// ------------------------------------------------------------------------------
DlogCh1 = (int16)mod_dir1.Counter;
DlogCh2 = (int16)_IQtoIQ15(qep1.ElecTheta);
DlogCh3 = (int16)_IQtoIQ15(qep1.MechTheta);
DlogCh4 = (int16)_IQtoIQ15(qep1.DirectionQep);
#endif // (BUILDLEVEL==LEVEL8)
With this code, with EnableFlag = 1 and lsw = 1, the motor is starting and rotating but after 2-3 mins, the motor is accelerating and is getting stopped.
Kindly help me out to run the motor using encoder feedback. Thank you.EN-241.pdf