⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainprog.c

📁 单体电容测试仪源码程序 可测电压、有A/D转换等。
💻 C
📖 第 1 页 / 共 3 页
字号:
		else {	//ADC_result2最大
			if (ADC_result1>ADC_result3) ADC_result_intr=ADC_result1; //ADC_result1为中间
			else  ADC_result_intr=ADC_result3;						 //ADC_result3为中间
		}
	}
}

/*
//通道电压检测
//全局变量Votage表示电压转换后的电压或电流
void Channel_Votage(float ADC_result,unsigned char channel)
{
	//printic(ADC_result);
	if(channel==1) {
		Votage=(ADC1_coefficient*ADC_result)/100;	//实际电压,单位:10mV
	}
	else if(channel==2) {
		Votage=(ADC2_coefficient*ADC_result)/100;	//实际电压,单位:mV
	}
	else if(channel==3) {
		Votage=(ADC3_coefficient*ADC_result)/10000;	//实际电压,单位:10mV
	}
}
//显示电压
void disp_votage(void)
{
	//打印测量时间计数
	disp_float_decimal(Mesure_counter_10ms);
	//测量电极电压。全局变量Votage表示电压,如果电压低于3V,chip_connect表示是否正在接触芯片
	ADC_filter(1);		//测量电压
	Channel_Votage(ADC_result,1);	//单位毫伏
	//以十进制方式显示电压,单位V.
	disp_float_votage(Votage,2);
	//测量电极电压。全局变量Votage表示电压,如果电压低于3V,chip_connect表示是否正在接触芯片
	ADC_filter(2);		//测量电压
	Channel_Votage(ADC_result,2);	//单位毫伏
	//以十进制方式显示电压,单位V.
	disp_float_votage(Votage,2);
	//测量电极电压。全局变量Votage表示电压,如果电压低于3V,chip_connect表示是否正在接触芯片
	ADC_filter(3);		//测量电压
	Channel_Votage(ADC_result,3);	//单位毫伏
	//以十进制方式显示电压,单位V.
	disp_float_votage(Votage,2);
	printh(0x0d);printh(0x0a);
}
*/
void Capacitance_Mesure(void)
{
/*
	float float_temp;
	//float float_temp;
	switch (Mesure_state)	//侧量状态
	{
	case Capacitance_Mesure_start:	//测量初始化
		Mesure_counter_10ms=0;	//侧量计数
	    break;
	//28V电容充电电容测量开始
	case charge_28V_cap_test_start:
		//测量起始电压
 		ADC_filter(1);		//测量电压
		Channel_Votage(ADC_result,1);	//单位毫伏
		start_votage=Votage;		 	//充电起始电压
		Votage_record=Votage;		 		//电压记录
		//清累计电荷量
		charge=0;			//充电总电荷
		charge_record=0;	//充电电荷记录
		ADC_counter=0;		//累加次数
		printh(0x0d);printh(0x0a);
		print("28VC: ");
		print("V:");
		disp_float_votage(Votage,2);		//显示当前电压
		print("I:");
		disp_float_votage(current,2);	//显示当前电流
		print("Counter:");
		disp_float_decimal(ADC_counter);		//显示累加次数
		print("Q:");
		disp_float_decimal(charge);		//显示累加电荷量
		Channel_Votage(float_temp,2);	//折合成电压,单位:毫伏
		printh(0x0d);printh(0x0a);
		//进入测量状态
		Mesure_state=charge_28V_cap_test;		//开始测量
		disp_flag=1;
	    break;

	//28V电容充电电容测量
	case charge_28V_cap_test:
		if (flag_10ms_1==1) {
			flag_10ms_1=0;	
			ADC_filter(2);		//测量电流
			charge+=ADC_result_intr;	//电荷量累加
			ADC_counter++;		//累加次数
			Channel_Votage(ADC_result_intr,2);	//单位毫伏
			current=Votage/25;				//当前电流
			if ((disp_flag==1) && (flag_1s_1==1) )
			{
				flag_1s_1=0;
				print(" I:");
				disp_float_votage(current,2);		//显示当前电流
				ADC_filter(1);					//测量电压
				print(" V:");
				Channel_Votage(ADC_result_intr,1);	//单位毫伏
				disp_float_votage(Votage,2);		//显示当前电压
			}
		}
		ADC_filter(1);		//测量电压
		Channel_Votage(ADC_result_intr,1);	//单位毫伏
		Curent_Votage=Votage;			//当前电压
		//每达到1伏打印一次
		if(((Votage/1000)>(Votage_record/1000))||(stop_flag==1)){	//打印电压
			Votage_record=Votage;
			float_temp=(charge-charge_record)/2500;
			charge_record=charge;			//记录本次电荷累计数量
			printh(0x0d);printh(0x0a);
			print("28VC: ");
			print("V:");
			disp_float_votage(Votage,2);		//显示当前电压
			print("I:");
			disp_float_votage(current,2);		//显示当前电流
			print("Counter:");
			disp_float_decimal(ADC_counter);	//显示累加次数
			print("Q:");
			disp_float_decimal(charge);		//显示累加电荷量
			print("ΔQ:");
			disp_float_decimal(charge-charge_record);	//显示电荷量差
			print("ΔC:");
			Channel_Votage(charge-charge_record,2);	//折合成电压,单位:毫伏
			Votage=Votage/25000;					//折合成电流(以25毫欧为采样电阻)
			Votage=Votage*1000/(Curent_Votage-Votage_record);	//折合成电容
			disp_float_votage(Votage,2);				//显示电容量
			print("C:");
			Channel_Votage(charge/1000,2);	//折合成电压,单位:毫伏
			//disp_float_decimal(Votage);
			Votage=Votage/25;				//折合成电流(以25毫欧为采样电阻)
			//disp_float_decimal(Votage);
			Votage=Votage*1000/(Curent_Votage-start_votage);	//总电容
			//disp_float_decimal(Curent_Votage);
			//disp_float_decimal(start_votage);
			disp_float_votage(Votage,2);		//显示电容量
			printh(0x0d);printh(0x0a);

			charge_record=charge;			//记录本次电荷累计数量
			Votage_record=Curent_Votage;			//记录当前电压
		}
		if (stop_flag==1)	{
			stop_flag=0;
			disp_flag=0;
		}
		break;
	//28V电容放电电容测量开始
	case discharge_28V_cap_test_start:
		//测量起始电压
 		ADC_filter(1);		//测量电压
		Channel_Votage(ADC_result_intr,1);	//单位毫伏
		start_votage=Votage;		 	//充电起始电压
		Votage_record=Votage;		 		//电压记录
		//清累计电荷量
		charge=0;			//充电总电荷
		charge_record=0;	//充电电荷记录
		ADC_counter=0;		//累加次数
		printh(0x0d);printh(0x0a);
		print("28VF: ");
		print("V:");
		disp_float_votage(Votage,2);		//显示当前电压
		print("I:");
		disp_float_votage(current,2);	//显示当前电流
		print("Counter:");
		disp_float_decimal(ADC_counter);		//显示累加次数
		print("Q:");
		disp_float_decimal(charge);		//显示累加电荷量
		printh(0x0d);printh(0x0a);
		Mesure_state=discharge_28V_cap_test;		//开始测量
		disp_flag=1;
	    break;
	//28V电容放电电容测量
	case discharge_28V_cap_test:
		if (flag_10ms_1==1) {
			flag_10ms_1=0;	
			ADC_filter(2);		//测量电流
			charge+=ADC_result_intr;	//电荷量累加
			ADC_counter++;		//累加次数
			Channel_Votage(ADC_result_intr,2);	//单位毫伏
			current=Votage/25;				//当前电流
			if ((disp_flag==1) && (flag_1s_1==1) ) {
				flag_1s_1=0;
				print(" I:");
				disp_float_votage(current,2);		//显示当前电流
				ADC_filter(1);					//测量电压
				print(" V:");
				Channel_Votage(ADC_result_intr,1);	//单位毫伏
				disp_float_votage(Votage,2);		//显示当前电压
			}
		}
		ADC_filter(1);		//测量电压
		Channel_Votage(ADC_result_intr,1);	//单位毫伏
		Curent_Votage=Votage;			//当前电压
		//每达到1伏打印一次
		if(((Votage/1000)<(Votage_record/1000))||(stop_flag==1)){	//打印电压
			printh(0x0d);printh(0x0a);
			print("28VF: ");
			print("V:");
			disp_float_votage(Curent_Votage,2);	//显示当前电压
			print("I:");
			disp_float_votage(current,2);			//显示当前电流
			print("Counter:");
			disp_float_decimal(ADC_counter);	//显示累加次数
			print("Q:");
			disp_float_decimal(charge);			//显示累加电荷量
			print("ΔQ:");
			disp_float_decimal(charge-charge_record);	//显示电荷量差
			print("ΔC:");
			Channel_Votage(charge-charge_record,2);	//折合成电压,单位:毫伏
			//disp_float_decimal(Votage);
			Votage=Votage/25000;					//折合成电流(以25毫欧为采样电阻)
			//disp_float_decimal(Votage);
			Votage=Votage*1000/(Votage_record-Curent_Votage);	//折合成电容
			disp_float_votage(Votage,2);				//显示电容量
			print("C:");
			Channel_Votage(charge/1000,2);	//折合成电压,单位:毫伏
			//disp_float_decimal(Votage);
			Votage=Votage/25;				//折合成电流(以25毫欧为采样电阻)
			//disp_float_decimal(Votage);
			Votage=Votage*1000/(start_votage-Curent_Votage);	//总电容
			disp_float_votage(Votage,2);		//显示电容量
			printh(0x0d);printh(0x0a);

			charge_record=charge;			//记录本次电荷累计数量
			Votage_record=Curent_Votage;			//记录当前电压
		}
		if (stop_flag==1)	{
			stop_flag=0;
			disp_flag=0;
		}
		break;
	//28V电容充电电容测量开始
	case charge_sigle_cap_test_start:
		//测量起始电压
 		ADC_filter(3);		//测量电压
		Channel_Votage(ADC_result_intr,3);	//单位毫伏
		start_votage=Votage;		 	//充电起始电压
		Votage_record=Votage;		 		//电压记录
		//清累计电荷量
		charge=0;			//充电总电荷
		charge_record=0;	//充电电荷记录
		ADC_counter=0;		//累加次数
		printh(0x0d);printh(0x0a);
		print("1.2VC: ");
		print("V:");
		disp_float_votage(Votage,2);		//显示当前电压
		print("I:");
		disp_float_votage(current,2);	//显示当前电流
		print("Counter:");
		disp_float_decimal(ADC_counter);		//显示累加次数
		print("Q:");
		disp_float_decimal(charge);		//显示累加电荷量
		printh(0x0d);printh(0x0a);
		//进入测量状态
		Mesure_state=charge_sigle_cap_test;		//开始测量
		disp_flag=1;
	    break;

	//sigle电容充电电容测量
	case charge_sigle_cap_test:
		if (flag_10ms_1==1) {
			flag_10ms_1=0;	
			ADC_filter(2);		//测量电流
			charge+=ADC_result_intr;	//电荷量累加
			ADC_counter++;		//累加次数
			Channel_Votage(ADC_result_intr,2);	//单位毫伏
			current=Votage/25;				//当前电流
			if ((disp_flag==1) && (flag_1s_1==1) ) {
				flag_1s_1=0;
				print(" I:");
				disp_float_votage(current,2);		//显示当前电流
				ADC_filter(3);					//测量电压
				print(" V:");
				Channel_Votage(ADC_result_intr,3);	//单位毫伏
				disp_float_votage(Votage,2);		//显示当前电压
			}
		}
		ADC_filter(3);		//测量电压
		Channel_Votage(ADC_result_intr,3);	//单位毫伏
		Curent_Votage=Votage;			//当前电压
		//每达到0.1伏打印一次
		if(((Votage/100)>(1+Votage_record/100))||(stop_flag==1)){	//打印电压
			printh(0x0d);printh(0x0a);
			print("1.2VC: ");
			print("V:");
			disp_float_votage(Votage,2);		//显示当前电压
			print("I:");
			disp_float_votage(current,2);		//显示当前电流
			print("Counter:");
			disp_float_decimal(ADC_counter);	//显示累加次数
			print("Q:");
			disp_float_decimal(charge);		//显示累加电荷量
			print("ΔQ:");
			disp_float_decimal(charge-charge_record);	//显示电荷量差
			print("ΔC:");
			Channel_Votage(charge-charge_record,2);	//折合成电压,单位:毫伏
			Votage=Votage/25000;					//折合成电流(以25毫欧为采样电阻)
			Votage=Votage*10000/(Curent_Votage-Votage_record);	//折合成电容
			//disp_float_decimal(Votage_record);
			//disp_float_decimal(Curent_Votage);
			disp_float_votage(Votage,2);				//显示电容量
			print("C:");
			Channel_Votage(charge/1000,2);	//折合成电压,单位:毫伏
			//disp_float_decimal(Votage);
			Votage=Votage/25;				//折合成电流(以25毫欧为采样电阻)
			//disp_float_decimal(Votage);
			Votage=Votage*10000/(Curent_Votage-start_votage);	//总电容
			//disp_float_decimal(Curent_Votage);
			//disp_float_decimal(start_votage);
			disp_float_votage(Votage,2);		//显示电容量
			printh(0x0d);printh(0x0a);

			charge_record=charge;			//记录本次电荷累计数量
			Votage_record=Curent_Votage;			//记录当前电压
		}
		if (stop_flag==1)	{
			stop_flag=0;
			disp_flag=0;
		}
		break;
	//sigle电容放电电容测量开始
	case discharge_sigle_cap_test_start:
		//测量起始电压
 		ADC_filter(3);		//测量电压
		Channel_Votage(ADC_result_intr,3);	//单位毫伏
		start_votage=Votage;		 	//充电起始电压
		Votage_record=Votage;		 		//电压记录
		//清累计电荷量
		charge=0;			//充电总电荷
		charge_record=0;	//充电电荷记录
		ADC_counter=0;		//累加次数

		printh(0x0d);printh(0x0a);
		print("1.2VF: ");
		print("V:");
		disp_float_votage(Votage,2);		//显示当前电压
		print("I:");
		disp_float_votage(current,2);	//显示当前电流
		print("Counter:");
		disp_float_decimal(ADC_counter);		//显示累加次数
		print("Q:");
		disp_float_decimal(charge);		//显示累加电荷量
		printh(0x0d);printh(0x0a);
		Mesure_state=discharge_sigle_cap_test;		//开始测量
		disp_flag=1;
	    break;
	//sigle电容放电电容测量
	case discharge_sigle_cap_test:
		if (flag_10ms_1==1) {
			flag_10ms_1=0;	
			ADC_filter(2);		//测量电流
			charge+=ADC_result_intr;	//电荷量累加
			ADC_counter++;		//累加次数
			Channel_Votage(ADC_result_intr,2);	//单位毫伏
			current=Votage/25;				//当前电流
			if ((disp_flag==1) && (flag_1s_1==1) ) {
				flag_1s_1=0;
				Channel_Votage(ADC_result_intr,2);	//单位毫伏
				print(" I:");
				disp_float_votage(current,2);		//显示当前电流
				ADC_filter(3);					//测量电压
				print(" V:");
				Channel_Votage(ADC_result_intr,3);	//单位毫伏
				disp_float_votage(Votage,2);		//显示当前电压
			}
		}
		ADC_filter(3);		//测量电压
		Channel_Votage(ADC_result_intr,3);	//单位毫伏
		Curent_Votage=Votage;			//当前电压
		//每达到0.1伏打印一次
		if(((Curent_Votage/100)<((Votage_record/100)-1))||(stop_flag==1)){	//打印电压
			printh(0x0d);printh(0x0a);
			print("1.2VF: ");
			print("V:");
			disp_float_votage(Curent_Votage,2);	//显示当前电压
			print("I:");
			disp_float_votage(current,2);			//显示当前电流
			print("Counter:");
			disp_float_decimal(ADC_counter);	//显示累加次数
			print("Q:");
			disp_float_decimal(charge);			//显示累加电荷量
			print("ΔQ:");
			disp_float_decimal(charge-charge_record);	//显示电荷量差
			print("ΔC:");
			Channel_Votage(charge-charge_record,2);	//折合成电压,单位:毫伏
			//disp_float_decimal(Votage);
			Votage=Votage/25000;					//折合成电流(以25毫欧为采样电阻)
			//disp_float_decimal(Votage);
			Votage=Votage*10000/(Votage_record-Curent_Votage);	//折合成电容
			disp_float_votage(Votage,2);				//显示电容量
			print("C:");
			Channel_Votage(charge/1000,2);	//折合成电压,单位:毫伏
			//disp_float_decimal(Votage);
			Votage=Votage/25;				//折合成电流(以25毫欧为采样电阻)
			//disp_float_decimal(Votage);
			Votage=Votage*10000/(start_votage-Curent_Votage);	//总电容
			disp_float_votage(Votage,2);		//显示电容量
			printh(0x0d);printh(0x0a);

			charge_record=charge;			//记录本次电荷累计数量
			Votage_record=Curent_Votage;			//记录当前电压
		}
		if (stop_flag==1)	{
			stop_flag=0;
			disp_flag=0;
		}
		break;
	//28V电容内阻测量开始(短路放电法)
	case resistance_measure_28V_start:
		if (resistance_measure_1ms==1) {
			resistance_measure_1ms=0;	
			//测量起始电压
 			ADC_filter(1);		//测量电压
			Channel_Votage(ADC_result_intr,1);	//单位毫伏
			start_votage=Votage;		 	//充电起始电压
			//清累计电荷量
			charge=0;			//充电总电荷
			charge_record=0;	//充电电荷记录
			ADC_counter=0;		//累加次数
			current=0;			//电流
			printh(0x0d);printh(0x0a);
			Mesure_state=resistance_measure_28V_1;		//开始测量
			Swich_Ctr=0;	//开始放电
		}
	    break;
	//28V电容内阻测量_放电10毫秒后测量电流电流
	case resistance_measure_28V_1:
		if (resistance_measure_1ms==1) {
			resistance_measure_1ms=0;	
			ADC_filter(2);				//测量电流
			current=ADC_result_intr;			//停止放电前取样电阻电压AD
 			ADC_filter(1);				//测量电压
			Votage_record=ADC_result_intr;		//停止放电前电压AD
			Swich_Ctr=1;				//停止放电
			Mesure_state=resistance_measure_28V_2;
		}
		break;
	//28V电容内阻测量_停止放电10毫秒后测量电压
	case resistance_measure_28V_2:
		if (resistance_measure_1ms==1) {
			resistance_measure_1ms=0;	

			ADC_filter(1);					//测量电压
			//计算停止放电后电压
			Channel_Votage(ADC_result_intr,1);	//单位毫伏
			Curent_Votage=Votage;			//当前电压
			//计算停止放电前电流
			Channel_Votage(current,2);		//停止放电时,取样电阻毫伏值,单位:毫伏
			current=1000*Votage/75;				//停止放电时,取样电阻电流(毫安)
			//计算停止放电前电压
			Channel_Votage(Votage_record,1);//停止放电时,电容电压,单位毫伏
			Votage_record=Votage;		 	//放电停止前电压
			//计算电阻
			float_temp=1000*(Curent_Votage-Votage_record)/current;	//单位:毫欧
			//显示
			print("28VR: ");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -