QQT912/CW32F030/原项目程序/SW/12 CW32 BLDC haLL pid OK/USER/compu.c

77 lines
1.3 KiB
C
Raw Normal View History

#include "compu.h"
void SampleSpeed(void)
{
unsigned int tem=0;
unsigned int st=0;
st=SampleData[2];
if(st<NMINVD-10) SetSpeed=0;
else if(st<=NMINVD);
else if(st<=NMAXVD)
{
tem=MINSPEED+KKN*(st-NMINVD);
SetSpeed=tem;
}
// printf("speed=%d\n",SetSpeed);
if(LevelSet==1) //250
{
SetSpeed /= 14;
SetSpeed *= 5;
}
else if(LevelSet==2) //350
{
SetSpeed /= 2;
}
else if(LevelSet==3) //450
{
SetSpeed /= 14;
SetSpeed *= 9;;
}
else {
SetSpeed /= 14;
SetSpeed *= 5;
}
// printf("Setspeed=%d\n",SetSpeed);
}
void SampleVI(void)
{
float t;
static unsigned char IErCount=0,VErCount=0;
//5 <20><><EFBFBD><EFBFBD> 4<><34>ѹ
if(SampleData[1]<=DIin)CanshuI=0;
else
{
t=(SampleData[1]-DIin);
t=t*11.097;// /t=t/4096*5000/22/0.005; //0.1ŷ
CanshuI=t;
}
if(CanshuI>=ISH*1000&&ErrorCode==0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
IErCount++;
if(IErCount>=NumErr)
{
ErrorCode=4;
}
}
else IErCount=0;
t =SampleData[3];
t=t/4096*5.0/RV1*(RV1+RV2);
CanshuV=t*10; //<2F>ɼ<EFBFBD>ĸ<EFBFBD>ߵ<EFBFBD>ѹ<EFBFBD>Ŵ<EFBFBD>10<31><30>
if(CanshuV>=VSH*10&&ErrorCode==0) //<2F><>ѹ<EFBFBD>ж<EFBFBD>
{
VErCount++;
if(VErCount>=NumErr)
{ErrorCode=6;}
}
else VErCount=0;
}