中级会员
- 积分
- 334
- 金钱
- 334
- 注册时间
- 2013-5-22
- 在线时间
- 13 小时
|
楼主 |
发表于 2013-5-22 15:41:10
|
显示全部楼层
请原子大哥指点
u16 ADCColl(u8 channel,u8 i){
// FeedDog();
if(i<16)chselect(i);
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
ADC_RegularChannelConfig(ADC1, channel, 1, ADC_SampleTime_239Cycles5);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(!(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)));
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
return ADC_GetConversionValue(ADC1);
}这是那个被两个任务调用的函数
void RefreshData(char channelx){
u16 i,ADch,tmp1;
s16 temp;
u32 ADsum[ADNUM2];
OSTimeDlyHMSM(0, 0, 0, 300);
for(ADch = CH1ADB1; ADch < ADNUM2; ADch++){ ADsum[ADch] = 0;}
for(i = 0; i < ADSAMP_NUM; i++)
{
if(channelx==0)
{
for(ADch = CH1ADB1; ADch < CH2ADB1; ADch++)
{
ADsum[ADch] += ADCColl(channel[ADch],ADch);//(enum ADCHANNELX)
}
}
if(channelx==1)
{
for(ADch = CH2ADB1; ADch < DCVIN; ADch++)
{
ADsum[ADch] += ADCColl(channel[ADch],ADch);//(enum ADCHANNELX)
}
}
for(ADch = DCVIN; ADch < ADNUM2; ADch++)
{
ADsum[ADch] += ADCColl(channel[ADch],ADch);//(enum ADCHANNELX)
}
}
for(ADch = CH1ADB1; ADch < ADNUM2; ADch++){
ADsum[ADch] /= ADSAMP_NUM;
}
switch(channelx)
{
case 0:
for(i = CH1ADB1; i < CH1DCC; i++){
run[channelx].VB[i+1] = COVER_B16(ADsum);//*CALIVOL/calivalue;
if(run[channelx].VB[i+1] < 500) run[channelx].VB[i+1] = 0;
}
temp = COVER_CC(ADsum[ADCUR1]);
// if((temp > 10)&&(temp < 1000)) temp -= (run.SCC*(10-temp/100)/10);
run[channelx].CC = temp/* * CALICC/calivalue[ADCUR1] */- run[channelx].SCC;////屏蔽校准
if(run[channelx].CC < 10) run[channelx].CC = 0;
run[channelx].DC = COVER_DC(ADsum[CH1DCC]) - run[channelx].SDC;//)*CALIDC/calivalue[ADDC];
if(run[channelx].DC < 10) run[channelx].DC = 0;
run[channelx].VIN = COVER_BPNI(ADsum[DCVIN]);
if(run[channelx].VIN < 50) run[channelx].VIN = 0;
run[channelx].VOUT= (COVER_BPNI(ADsum[CH1BV])/**CALIVOL*4/calivalue[CH1BV]*/) - (run[channelx].CC/ 100);////屏蔽校准
if(run[channelx].VOUT < 50) run[channelx].VOUT = 0;
tmp1 = COVER_NTCV(ADsum[ADNTC1]); //求电压
tmp1 = COVER_NTCR(tmp1); //求电阻
run[channelx].NTC = COVER_NTC((float)tmp1/1000); //求温度
if((run[channelx].NTC < -10)||(run[channelx].NTC > 100))
///run[channelx].NTC = -100;
run[channelx].NTC = 30;
tmp1 = COVER_NTCV(ADsum[ADBT1]); //求电压
tmp1 = COVER_NTCR(tmp1); //求电阻
run[channelx].BNTC = COVER_NTC((float)tmp1/1000); //求温度
if((run[channelx].BNTC < -10)||(run[channelx].BNTC > 100))
///run[channelx].BNTC = -100;
run[channelx].BNTC = 30;
break;
case 1: for(i = CH2ADB1; i < CH2DCC; i++){
run[channelx].VB[i-7] = COVER_B16(ADsum);//*CALIVOL/calivalue;
if(run[channelx].VB[i-7] < 500) run[channelx].VB[i-7] = 0;
}
temp = COVER_CC(ADsum[ADCUR2]);
// if((temp > 10)&&(temp < 1000)) temp -= (run.SCC*(10-temp/100)/10);
run[channelx].CC = temp /** CALICC/calivalue[ADCUR2]*/ - run[channelx].SCC;
if(run[channelx].CC < 10) run[channelx].CC = 0;
run[channelx].DC = COVER_DC(ADsum[CH2DCC]) - run[channelx].SDC;//)*CALIDC/calivalue[ADDC];
if(run[channelx].DC < 10) run[channelx].DC = 0;
run[channelx].VIN = COVER_BPNI(ADsum[DCVIN]);
if(run[channelx].VIN < 50) run[channelx].VIN = 0;
run[channelx].VOUT= (COVER_BPNI(ADsum[CH2BV])/**CALIVOL*4/calivalue[CH2BV]*/) - (run[channelx].CC/ 100);
if(run[channelx].VOUT < 50) run[channelx].VOUT = 0;
tmp1 = COVER_NTCV(ADsum[ADNTC2]); //求电压
tmp1 = COVER_NTCR(tmp1); //求电阻
run[channelx].NTC = COVER_NTC((float)tmp1/1000); //求温度
if((run[channelx].NTC < -10)||(run[channelx].NTC > 100))
///run[channelx].NTC = -100;
run[channelx].NTC = 30;
tmp1 = COVER_NTCV(ADsum[ADBT2]); //求电压
tmp1 = COVER_NTCR(tmp1); //求电阻
run[channelx].BNTC = COVER_NTC((float)tmp1/1000); //求温度
if((run[channelx].BNTC < -10)||(run[channelx].BNTC > 100))
////run[channelx].BNTC = -100;
run[channelx].BNTC = 30;
break;
default: break;
}
FANProc();
}
这是调用AD转换的函数 |
|