📄 example_280xadcsoc.c
字号:
epwm2_info.EPwmMaxCMPA = EPWM2_MAX_CMPA; // Setup min/max CMPA/CMPB values
epwm2_info.EPwmMinCMPA = EPWM2_MIN_CMPA;
epwm2_info.EPwmMaxCMPB = EPWM2_MAX_CMPB;
epwm2_info.EPwmMinCMPB = EPWM2_MIN_CMPB;
}
//-------------------------------------
void motor_ctrl_2(void)
{
if(Uint16Emf1>MOTOR_ADJ)
{
//------
// Example, write to the HRPWM extension of CMPA
// Example, 32-bit write to CMPA:CMPAHR
//EPwm1Regs.CMPA.all = ((Uint32)EPwm1Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);
//------
if(Uint16Emf1>(MOTOR_ADJ+2))
{
Uint16Motor_ERR=Uint16Emf1-MOTOR_ADJ;
if(EPWM1_CMPA>100)
{
EPWM1_CMPA-=1;
if(Uint16Motor_ERR>2)
EPWM1_CMPA-=1;
if(Uint16Motor_ERR>4)
EPWM1_CMPA-=2;
if(Uint16Motor_ERR>6)
EPWM1_CMPA-=8;
if(Uint16Motor_ERR>8)
EPWM1_CMPA-=8;
if(Uint16Motor_ERR>16)
EPWM1_CMPA-=32;
emf_count=0;
emf_flag=1;
}
}
} //EPWM1_CMPA
else
{
if(Uint16Emf1<(MOTOR_ADJ-2))
{
Uint16Motor_ERR=MOTOR_ADJ-Uint16Emf1;
if(EPWM1_CMPA<1500)
{
EPWM1_CMPA+=1;
if(Uint16Motor_ERR>2)
EPWM1_CMPA+=1;
if(Uint16Motor_ERR>4)
EPWM1_CMPA+=2;
if(Uint16Motor_ERR>6)
EPWM1_CMPA+=2;
if(Uint16Motor_ERR>8)
EPWM1_CMPA+=4;
emf_flag=1;
}
} //EPWM1_CMPA
}
// Reset the watchdog counter
ServiceDog();
}
//---------------------
//-------------------------------------
void motor_ctrl_1(void)
{
if(Uint16Emf1>MOTOR_ADJ)
{
//------
// Example, write to the HRPWM extension of CMPA
// Example, 32-bit write to CMPA:CMPAHR
//EPwm1Regs.CMPA.all = ((Uint32)EPwm1Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);
//------
if(Uint16Emf1>(MOTOR_ADJ+1))
{
Uint16Motor_ERR=Uint16Emf1-MOTOR_ADJ;
if(EPWM1_CMPA>100)
{
EPWM1_CMPA-=1;
if(Uint16Motor_ERR>2)
EPWM1_CMPA-=1;
if(Uint16Motor_ERR>4)
EPWM1_CMPA-=2;
if(Uint16Motor_ERR>6)
EPWM1_CMPA-=4;
if(Uint16Motor_ERR>8)
EPWM1_CMPA-=8;
if(Uint16Motor_ERR>16)
EPWM1_CMPA-=32;
emf_count=0;
emf_flag=1;
}
}
} //EPWM1_CMPA
else
{
if(Uint16Emf1<(MOTOR_ADJ-1))
{
Uint16Motor_ERR=MOTOR_ADJ-Uint16Emf1;
if(EPWM1_CMPA<1000)
{
EPWM1_CMPA+=1;
if(Uint16Motor_ERR>2)
EPWM1_CMPA+=1;
if(Uint16Motor_ERR>4)
EPWM1_CMPA+=2;
if(Uint16Motor_ERR>6)
EPWM1_CMPA+=2;
if(Uint16Motor_ERR>8)
EPWM1_CMPA+=4;
emf_flag=1;
}
} //EPWM1_CMPA
}
// Reset the watchdog counter
ServiceDog();
}
//-------------------------------------
void motor_ctrl_8(void)
{
Uint16 temp;
EMF_js++;
EMF_pj+=EMF;
if(EMF_js>4)
{
EMF_pj_temp=EMF_pj>>2;
EMF_pj=0;
EMF_js=0;
if(EMF_pj_temp>MOTOR_ADJ)
{
Uint16Motor_ERR=EMF_pj_temp-MOTOR_ADJ;
if(EPWM1_CMPA>60)
{
/*if(Uint16Motor_ERR>300)
EMF_pwma=30;
else if(Uint16Motor_ERR>100)
EMF_pwma=10;
else if(Uint16Motor_ERR>100)
EMF_pwma=10;
else if(Uint16Motor_ERR>60)
EMF_pwma=6;
else if(Uint16Motor_ERR>30)
EMF_pwma=3;
else if(Uint16Motor_ERR>20)
EMF_pwma=2;
else if(Uint16Motor_ERR>10)
EMF_pwma=1;
else
EMF_pwma=1;*/
if(Uint16Motor_ERR>30)
EMF_pwma=Uint16Motor_ERR/30;
else
EMF_pwma=1;
temp=MOTOR_ADJ/60;
if(EMF_pwma>temp)
EMF_pwma=temp;
EPWM1_CMPA-=EMF_pwma;
emf_count=0;
emf_flag=1;
}
} //EPWM1_CMPA
else
{
Uint16Motor_ERR=MOTOR_ADJ-EMF_pj_temp;
if(EPWM1_CMPA<MAX_PWM)
{
if(Uint16Motor_ERR>100)
EMF_pwma=10;
else if(Uint16Motor_ERR>60)
EMF_pwma=4;
else if(Uint16Motor_ERR>40)
EMF_pwma=3;
else if(Uint16Motor_ERR>20)
EMF_pwma=2;
else if(Uint16Motor_ERR>10)
EMF_pwma=1;
else
EMF_pwma=1;
/*if(Uint16Motor_ERR>20)
EMF_pwma=Uint16Motor_ERR/20;
else
EMF_pwma=1;
temp=MOTOR_ADJ/20;
if(EMF_pwma>temp)
EMF_pwma=temp; */
EPWM1_CMPA+=EMF_pwma;
emf_flag=1;
}
} //EPWM1_CMPA
}
// Reset the watchdog counter
ServiceDog();
}
//-------------------------------------
void motor_ctrl_9(void)
{
Uint32 temp,i;
U_ARR[M_U_COUNT]=M_U;
I_ARR[M_U_COUNT]=I_SUM;
temp=0;
for(i=0;i<128;i++)
{
temp+=U_ARR[i];
}
M_U_PJ=temp>>7;
temp=0;
for(i=0;i<128;i++)
{
temp+=I_ARR[i];
}
I_SUM_PJ=temp>>7;
if(M_U_COUNT==128)//MAX_PWM_adj
M_U_COUNT=0;
else
M_U_COUNT++;
//----
PWM_U_TEMP=((Uint32)I_SUM_PJ*DC_R*PWM_U)/(900- pwm_temp);
temp=MAX_PWM_adj+PWM_U_TEMP;
if(temp>MAX_PWM)
EPWM1_CMPA=MAX_PWM;
else
EPWM1_CMPA=temp;
//---
// Reset the watchdog counter
ServiceDog();
}
//-------------------------------------
//-------------------------------------
void motor_ctrl_10(void)
{
Uint16 temp;
M_U_COUNT++;
M_U_SUM+=M_U;
I_SUM_SUM+=I_SUM;
if(M_U_COUNT>32)//MAX_PWM_adj
{
M_U_PJ=M_U_SUM>>5;
I_SUM_PJ=I_SUM_SUM>>5;
I_SUM_SUM=0;
M_U_SUM=0;
M_U_COUNT=0;
PWM_U_TEMP=((Uint32)I_SUM_PJ*DC_R*PWM_U)/(350- pwm_temp);
temp=MAX_PWM_adj+PWM_U_TEMP;
//--
//--
if(temp>MAX_PWM)
EPWM1_CMPA=MAX_PWM;
else
EPWM1_CMPA=temp;
}
// Reset the watchdog counter
ServiceDog();
}
///----------------------------------
void cal_dc_in_vol()
{
Uint16 i;
Uint32 temp32;
if(PROTECT_FLAG_reg.bit.SAMP_flag)
{
PROTECT_FLAG_reg.bit.SAMP_flag=0;
// //--计算输入直流电压--
temp32=0;
for(i=0;i<128;i++)
{
temp32+=Voltage1[i];
}
M_U=(temp32<<8)/20331;
//-----------
M_DC_R=(I_SUM*DC_R)>>2;
if(M_U>M_DC_R)
EMF=M_U-M_DC_R;
//-----------
}
// Reset the watchdog counter
ServiceDog();
}
/*void S60_S90_QF()
{
if(PROTECT_FLAG_reg.bit.S60_S90_flag==1)
{
MOTOR_ADJ=MOTOR_ADJ_s60s90;
}
else
{
if(MOTOR_ADJ_s60s90<12)
MOTOR_ADJ=0;
else
MOTOR_ADJ=(MOTOR_ADJ_s60s90>>3)+(710*GPIO31);
}
// Reset the watchdog counter
ServiceDog();
}*/
//------------------------------------
void S60_S90_QF()
{
Uint16 temp;
Uint32 temp32;
if(PROTECT_FLAG_reg.bit.S60_S90_flag==1)
{
temp32=(MOTOR_ADJ_s60s90*10)/12;
temp=temp32;
}
else
{
if(MOTOR_ADJ_s60s90<12)
temp=0;
else
//temp=(MOTOR_ADJ_s60s90>>3)+(710*GPIO31);
temp=MOTOR_ADJ_s60s90/(8-GPIO31);//2008-1-10
}
if(temp==0)
{
MOTOR_ADJ=0;
if(rqd_flag==0)
rqd_flag=1;
}
else
{
if(rqd_flag==1)
{
MOTOR_ADJ+=10;
if(MOTOR_ADJ>temp)
rqd_flag=0;
}
else
MOTOR_ADJ=temp;
}
// MOTOR_ADJ=temp;
// Reset the watchdog counter
ServiceDog();
}
//--------运行开始标志----
void run_start(void)
{
if(PROTECT_FLAG_reg.bit.run_start_flag==1)
{
if(PROTECT_FLAG_reg.bit.run_jc_flag==1)
{
if(MOTOR_ADJ<12)
{
PROTECT_FLAG_reg.bit.run_jc_flag=0;
PROTECT_FLAG_reg.bit.run_start_flag=0;
GpioDataRegs.GPASET.bit.GPIO13=1;
}
}
/* else
{
if(MOTOR_ADJ>12)
PROTECT_FLAG_reg.bit.run_start_flag=0;
}*/
}
else
{
if(I_SUM_PJ>500)
//if((I_SUM>500)||(U_SUM>300))
{
PROTECT_FLAG_reg.bit.run_start_flag=1;
PROTECT_FLAG_reg.bit.run_jc_flag=1;
GpioDataRegs.GPACLEAR.bit.GPIO13=1;
}
}
// Reset the watchdog counter
ServiceDog();
}
//-------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -