📄 sfoc_ti.c
字号:
/*-----------------------------------------------------------------------------
Set up PID Controller parameters.
-----------------------------------------------------------------------------*/
v->pid_id.Kp_reg3 = 21178; /* Q15 */
v->pid_id.Ki_reg3 = 5592; /* Q31-16bit */
v->pid_id.Kd_reg3 = 0; /* Q14 */
v->pid_id.Kc_reg3 = 20281; /* Q15 */
v->pid_id.pid_out_max = 0x4000; /* Q15 */
v->pid_id.pid_out_min = 0xC000; /* Q15 */
/*-----------------------------------------------------------------------------
Set up PID Controller parameters.
-----------------------------------------------------------------------------*/
v->pid_iq.Kp_reg3 = 21178; /* Q15 */
v->pid_iq.Ki_reg3 = 5592; /* Q31-16bit */
v->pid_iq.Kd_reg3 = 0; /* Q14 */
v->pid_iq.Kc_reg3 = 20281; /* Q15 */
v->pid_iq.pid_out_max = 0x6500; /* Q15 */
v->pid_iq.pid_out_min = 0x9B00; /* Q15 */
/*-----------------------------------------------------------------------------
Set up PID Controller parameters.
-----------------------------------------------------------------------------*/
v->pid_spd.Kp_reg3 = 31457; /* Q15 */
v->pid_spd.Ki_reg3 = 5592; /* Q31-16bit */
v->pid_spd.Kd_reg3 = 0; /* Q14 */
v->pid_spd.Kc_reg3 = 31858; /* Q15 */
v->pid_spd.pid_out_max = 0x7FFF; /* Q15 */
v->pid_spd.pid_out_min = 0x8000; /* Q15 */
} /* End: SFOC_TI_Init() */
#endif /* (BUILDLEVEL==LEVEL6) */
#if (BUILDLEVEL==LEVEL7)
void SFOC_TI_Init(SFOC_TI_handle v)
{
/*------------------------------------------------------------------------------
Notes: 1. Attributes are conveniently changed here, but this does
consume cycles twice,
(a) in the 'C' boot-up, and then
(b) in the execution of this code. Setting up the needed
constants the declaration of SVGEN svgen = VALUES,
rather than the defaults is clearly more effecient.
This method is more intended for runtime changes.
2. There is also a code-size associated with these changes.
-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
Set up PID Controller parameters.
-----------------------------------------------------------------------------*/
v->pid_id.Kp_reg3 = 21178; /* Q15 */
v->pid_id.Ki_reg3 = 5592; /* Q31-16bit */
v->pid_id.Kd_reg3 = 0; /* Q14 */
v->pid_id.Kc_reg3 = 20281; /* Q15 */
v->pid_id.pid_out_max = 0x4000; /* Q15 */
v->pid_id.pid_out_min = 0xC000; /* Q15 */
/*-----------------------------------------------------------------------------
Set up PID Controller parameters.
-----------------------------------------------------------------------------*/
v->pid_iq.Kp_reg3 = 21178; /* Q15 */
v->pid_iq.Ki_reg3 = 5592; /* Q31-16bit */
v->pid_iq.Kd_reg3 = 0; /* Q14 */
v->pid_iq.Kc_reg3 = 20281; /* Q15 */
v->pid_iq.pid_out_max = 0x6500; /* Q15 */
v->pid_iq.pid_out_min = 0x9B00; /* Q15 */
/*-----------------------------------------------------------------------------
Set up PID Controller parameters.
-----------------------------------------------------------------------------*/
v->pid_spd.Kp_reg3 = 11457; /* Q15 */
v->pid_spd.Ki_reg3 = 4592; /* Q31-16bit */
v->pid_spd.Kd_reg3 = 0; /* Q14 */
v->pid_spd.Kc_reg3 = 31858; /* Q15 */
v->pid_spd.pid_out_max = 0x7FFF; /* Q15 */
v->pid_spd.pid_out_min = 0x8000; /* Q15 */
/*-----------------------------------------------------------------------------
Setup SMOPOS sliding mode rotor angle observer parameters.
(based on 15kHz sampling freq)
-----------------------------------------------------------------------------*/
/* PMSM motor (Pacific Scientific) */
/* fb = 200 Hz */
v->smo.fsmopos = 32319; /* Q15 */
v->smo.gsmopos = 15434; /* Q15 */
v->smo.kslide = 4236; /* Q15 */
v->smo.kslf = 3431; /* Q15 */
/*-----------------------------------------------------------------------------
Initialize parameters of the speed calculation based on estimated angle
(based on 15kHz sampling freq)
-----------------------------------------------------------------------------*/
/* fb = 200 Hz */
v->speed.K1_fr = 4800;
v->speed.K2_fr = 32361;
v->speed.K3_fr = 407;
v->speed.rpm_max = 6000;
} /* End: SFOC_TI_Init() */
#endif /* (BUILDLEVEL==LEVEL7) */
/* ************************************************************************** */
/* ************************************************************************** */
#if (BUILDLEVEL==LEVEL1)
void SFOC_TI_Run(SFOC_TI_handle v)
{
/*-----------------------------------------------------------------------------
Connect freq_testing inputs to the RMPCNTL
-----------------------------------------------------------------------------*/
v->rmpc.target_value = v->speed_ref;
/*-----------------------------------------------------------------------------
Call the compute function for the RMPCNTL
-----------------------------------------------------------------------------*/
v->rmpc.calc((void *)&v->rmpc); /* Call RMPCNTL compute function */
/*-----------------------------------------------------------------------------
Connect RMPCNTL output to the RAMPGEN input
-----------------------------------------------------------------------------*/
v->rg.rmp_freq = v->rmpc.setpt_value;
/*-----------------------------------------------------------------------------
Call the compute function for the RAMPGEN
-----------------------------------------------------------------------------*/
v->rg.calc((void *)&v->rg); /* Call RAMPGEN compute function */
/*-----------------------------------------------------------------------------
Connect voltages in DQT structure
-----------------------------------------------------------------------------*/
v->voltage_DQt.D = v->Vd_testing;
v->voltage_DQt.Q = v->Vq_testing;
v->voltage_DQt.theta = v->rg.rmp_out;
/*-----------------------------------------------------------------------------
Call the compute function for the IPARK
-----------------------------------------------------------------------------*/
ipark((void *)&v->voltage_DQt,(void *)&v->voltage_dq);
/*-----------------------------------------------------------------------------
Connect IPARK voltage outputs to the SVGENDQ inputs
-----------------------------------------------------------------------------*/
v->svgen.d = v->voltage_dq.d;
v->svgen.q = v->voltage_dq.q;
/*-----------------------------------------------------------------------------
Call the compute function for the SVGENDQ
-----------------------------------------------------------------------------*/
v->svgen.calc((void *)&v->svgen); /* Call SVGENDQ compute function */
} /* End: SFOC_TI_Run() */
#endif /* (BUILDLEVEL==LEVEL1) */
#if (BUILDLEVEL==LEVEL2)
void SFOC_TI_Run(SFOC_TI_handle v)
{
/*-----------------------------------------------------------------------------
Connect freq_testing inputs to the RMPCNTL
-----------------------------------------------------------------------------*/
v->rmpc.target_value = v->speed_ref;
/*-----------------------------------------------------------------------------
Call the compute function for the RMPCNTL
-----------------------------------------------------------------------------*/
v->rmpc.calc((void *)&v->rmpc); /* Call RMPCNTL compute function */
/*-----------------------------------------------------------------------------
Connect RMPCNTL output to the RAMPGEN input
-----------------------------------------------------------------------------*/
v->rg.rmp_freq = v->rmpc.setpt_value;
/*-----------------------------------------------------------------------------
Call the compute function for the RAMPGEN
-----------------------------------------------------------------------------*/
v->rg.calc((void *)&v->rg); /* Call RAMPGEN compute function */
/*-----------------------------------------------------------------------------
Connect voltages in DQT structure
-----------------------------------------------------------------------------*/
v->voltage_DQt.D = v->Vd_testing;
v->voltage_DQt.Q = v->Vq_testing;
v->voltage_DQt.theta = v->rg.rmp_out;
/*-----------------------------------------------------------------------------
Call the compute function for the IPARK
-----------------------------------------------------------------------------*/
ipark((void *)&v->voltage_DQt,(void *)&v->voltage_dq);
/*-----------------------------------------------------------------------------
Connect IPARK voltage outputs to the SVGENDQ inputs
-----------------------------------------------------------------------------*/
v->svgen.d = v->voltage_dq.d;
v->svgen.q = v->voltage_dq.q;
/*-----------------------------------------------------------------------------
Call the compute function for the SVGENDQ
-----------------------------------------------------------------------------*/
v->svgen.calc((void *)&v->svgen); /* Call SVGENDQ compute function */
/*-----------------------------------------------------------------------------
Call the compute function for the CLARKE
-----------------------------------------------------------------------------*/
clark((void *)&v->current_abc,(void *)&v->current_dq);
/*-----------------------------------------------------------------------------
Connect currents in DQT structure
-----------------------------------------------------------------------------*/
v->current_dqt.D = v->current_dq.d;
v->current_dqt.Q = v->current_dq.q;
v->current_dqt.theta = v->rg.rmp_out;
/*-----------------------------------------------------------------------------
Call the compute function for the PARK
-----------------------------------------------------------------------------*/
park((void *)&v->current_dqt,(void *)&v->current_DQ);
/*-----------------------------------------------------------------------------
Connect SVGENDQ outputs and Vbus to the PHASEVOLTAGE inputs
-----------------------------------------------------------------------------*/
v->volt.DC_bus = v->Vbus;
v->volt.Mfunc_V1 = v->svgen.va;
v->volt.Mfunc_V2 = v->svgen.vb;
v->volt.Mfunc_V3 = v->svgen.vc;
/*-----------------------------------------------------------------------------
Call the compute function for the PHASEVOLTAGE
-----------------------------------------------------------------------------*/
v->volt.calc((void *)&v->volt); /* Call PHASEVOLTAGE compute function */
} /* End: SFOC_TI_Run() */
#endif /* (BUILDLEVEL==LEVEL2) */
#if (BUILDLEVEL==LEVEL3)
void SFOC_TI_Run(SFOC_TI_handle v)
{
/*-----------------------------------------------------------------------------
Connect freq_testing inputs to the RMPCNTL
-----------------------------------------------------------------------------*/
v->rmpc.target_value = v->speed_ref;
/*-----------------------------------------------------------------------------
Call the compute function for the RMPCNTL
-----------------------------------------------------------------------------*/
v->rmpc.calc((void *)&v->rmpc); /* Call RMPCNTL compute function */
/*-----------------------------------------------------------------------------
Connect RMPCNTL output to the RAMPGEN input
-----------------------------------------------------------------------------*/
v->rg.rmp_freq = v->rmpc.setpt_value;
/*-----------------------------------------------------------------------------
Call the compute function for the RAMPGEN
-----------------------------------------------------------------------------*/
v->rg.calc((void *)&v->rg); /* Call RAMPGEN compute function */
/*-----------------------------------------------------------------------------
Connect PIDREG3 inputs for Id control
-----------------------------------------------------------------------------*/
v->pid_id.pid_ref_reg3 = v->Id_ref;
v->pid_id.pid_fdb_reg3 = v->current_DQ.d;
/*-----------------------------------------------------------------------------
Call the compute function for the PIDREG3 inputs for Id control
-----------------------------------------------------------------------------*/
v->pid_id.calc((void *)&v->pid_id); /* Call PIDREG3 compute function */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -