標題:
STM32數(shù)控源設計原理圖加代碼
[打印本頁]
作者:
1512992980
時間:
2019-5-25 11:23
標題:
STM32數(shù)控源設計原理圖加代碼
電路圖:
0.png
(114.37 KB, 下載次數(shù): 39)
下載附件
2019-5-26 01:59 上傳
** 調用相應的子模塊文件
**********************************************************/
#include"LCD12864.H"
#include"eeprom.h"
#include"usart.h"
#include"ad.h"
#include"pwm_10BIT.h"
extern void calc_voltage_current();
void OUT_VOLTAGE_1()
{
if(VOL_OUT_FLAG==1)
{
OUT_Voltage_PWM=ADJ_VOL;
OUT_Current_PWM=ADJ_CUR;
}
else
{
OUT_Voltage_PWM=1;
OUT_Current_PWM=1;
}
}
/*********************************************************
** 將電壓發(fā)送到串口
**********************************************************/
//void Voltage_Send(U8 Voltage_num,U16 Voltage_dat)
//{
// SendData('A');
// SendData('D');
// SendData(Voltage_num+'0');
// SendData('=');
// SendData(Voltage_dat/1000+'0');
// SendData(Voltage_dat%1000/100+'0');
// SendData('.');
// SendData(Voltage_dat%100/10+'0');
// SendData(Voltage_dat%10+'0');
// SendData('V');
// SendData(' ');
// SendData(' ');
// SendData(' ');
// SendData(' ');
//}
//void data_Send(U16 Voltage_dat)
//{
// SendData('d');
// SendData('a');
// SendData('t');
// SendData('a');
// SendData(':');
// SendData(Voltage_dat/10000+'0');
// SendData(Voltage_dat%10000/1000+'0');
// SendData(Voltage_dat%1000/100+'0');
// SendData(Voltage_dat%100/10+'0');
// SendData(Voltage_dat%10+'0');
// SendData(' ');
// SendData(' ');
// SendData(' ');
// SendData(' ');
//}
/*********************************************************
**中值濾波
**算法:先進行排序,然后將數(shù)組的中間值作為當前值返回。
**********************************************************/
U16 Error_Correct(U16 *str,U8 num)
{
unsigned char i=0;
unsigned char j=0;
U16 Temp=0;
U16 shu;
//排序
for(i=0;i<num-1;i++)
{
for(j=i+1;j<num;j++)
{
if(str[i]<str[j])
{
Temp=str[i];
str[i]=str[j];
str[j]=Temp;
}
}
}
shu=str[3]+str[4]+str[5]+str[6];
//去除誤差,取中間值
return shu/4;
}
/*********************************************************
** 檢測10次電壓
**********************************************************/
U16 ADC_Caculate(U8 channel)
{
U16 ADC_Voltage=0;
U8 i;
for(i=0;i<10;i++) //檢測5次取平均值返回
{
ADC_TEMP[i]=Get_ADC10bitResult(channel);
}
ADC_Voltage=Error_Correct(ADC_TEMP,10);
return ADC_Voltage;
}
/*********************************************************
******電壓采集及計算
**********************************************************/
void Voltage_Gath_calc()
{
U8 i,k;
for(k=0;k<7;k++)
{
VOL_TEMP2[k]=ADC_Caculate(k);
}
for(i=0;i<7;i++)
{
VOL_TEMP[i]=((((VOL_TEMP2[i]*2.5*10)/VOL_TEMP2[0])*100)+5)/10;
}
VOL_TEMP[1]*=111; //輸出電流顯示微調
VOL_TEMP[2]*=82; //輸出電壓顯示微調
VOL_TEMP[1]/=100;
VOL_TEMP[2]/=100;
}
復制代碼
全部資料51hei下載地址:
程序和電路圖.rar
(364.81 KB, 下載次數(shù): 30)
2019-5-26 01:59 上傳
點擊文件名下載附件
原理圖+代碼
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1