基于STM32的FFT傅里叶变换.docx
《基于STM32的FFT傅里叶变换.docx》由会员分享,可在线阅读,更多相关《基于STM32的FFT傅里叶变换.docx(24页珍藏版)》请在冰豆网上搜索。
基于STM32的FFT傅里叶变换
/********************(C)COPYRIGHT2010STMicroelectronics********************
*FileName:
ADCompute.c
*Author:
*Version:
V1.0
*Date:
10/08/2007
*Description:
AD_Computeprogrambody
********************************************************************************
*THEPRESENTSOFTWAREWHICHISFORGUIDANCEONLYAIMSATPROVIDINGCUSTOMERS
*WITHCODINGINFORMATIONREGARDINGTHEIRPRODUCTSINORDERFORTHEMTOSAVETIME.
*ASARESULT,STMICROELECTRONICSSHALLNOTBEHELDLIABLEFORANYDIRECT,
*INDIRECTORCONSEQUENTIALDAMAGESWITHRESPECTTOANYCLAIMSARISINGFROMTHE
*CONTENTOFSUCHSOFTWAREAND/ORTHEUSEMADEBYCUSTOMERSOFTHECODING
*INFORMATIONCONTAINEDHEREININCONNECTIONWITHTHEIRPRODUCTS.
*******************************************************************************/
/*Includes------------------------------------------------------------------*/
//#include"stm32f10x.h"
#include"main.h"
#include"stm32f10x_usart.h"
#include"stm32f10x_lib.h"
#include"stm32f10x_map.h"
#include"platform_config.h"
#include"stm32f10x_nvic.h"
#include"stm32f10x_adc.h"
#include"stm32f10x_dma.h"
#include"extern.h"
#include
#include
#defineplus10
#defineplus21
#defineplus32
//#defineBufferSize200
#defineADC1((ADC_TypeDef*)ADC1_BASE)
#defineDMA1_Channel6((DMA_Channel_TypeDef*)DMA1_Channel6_BASE)
//u8ch_flag[3]={0,0,0};
//u8plus_state[3]={0,0,0};
volatileunsignedshortintCurrent_L;//剩余电流
volatileunsignedshortintADC_ValueData[224];
//volatileunsignedshortintADC_ValueDataTAB[7]={0,0,0,0,0,0,0};
volatileunsignedshortintAngle_Value_Data[7]={0,0,0,0,0,0,0};
volatilesignedlongintzhengxuDateTab[36][7];
volatilesignedlongintfuxuDateTab[36][7];
//unsignedshortintADC_Value[7]={0,0,0,0,0,0,0};
///////////////标识///////////////////////////////
u8prun,ddj_run,qda,qdc[5],Trip,Trip2,Alarm,RLP_oweI,RLP_oweP,RLP_oweUA,RLP_oweUT;
///////////////变量///////////////////////////////
vs32recval3[16],e[40];
vs32ss0,ss1,ss2,ss3,ss4,ss5,ss6,ss7,ss8,ss9,ss10,ss11,ss12,ss13,ss14,ss15,ss16,ss17,ss18,ss19,ss20,ss21,sss_r,sss_x,
ss_dxa,ss_dxb,ss_dxc,ss_bphave,ss_bpha,ss_bphb,ss_bphc,ss_bphmax;
vu8pro1,pro2,pro3,pro4,pro5,pro6,pro7,pro8,pro9,pro10,pro11,pro12,pro13,pro14,pro15,sett[FLASH_PAGE_SIZE];
vu32e_im,e_105im,e_3im,e_6im,e_25im,e_1375im,pn,un;
u32est_t,st_t,tfdl2,rtfdl2;
vu8chn,set_num,M_num;
floatTtirp,t_rgz;
constsignedshortintx_Num[]={
0,347,684,1000,1285,1532,1732,1879,1969,2000,1969,1879,1732,1532,1285,1000,684,347,-0,-347,-684,-1000,-1285,-1532,-1732,-1879,-1969,-2000,-1969,-1879,-1732,-1532,-1285,-1000,-684,-347
};
//vs16resist_temper[4];
unsignedshortintSampleData(volatileunsignedshortintADCDataTab[],unsignedshortintnChannel);//
constsignedshortinty_Num[]={
2000,1969,1879,1732,1532,1285,1000,684,347,0,-347,-684,-1000,-1285,-1532,-1732,-1879,-1969,-2000,-1969,-1879,-1732,-1532,-1285,-1000,-684,-347,-0,347,684,1000,1285,1532,1732,1879,1969
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
floatCH_ComputeTab[10][7];
floatUI_Parent[7];
//unsignedshortintSignal_Data[7]={0,0,0,0,0,0,0};
//unsignedintIA1_Value=0;
//voidVoltage_Calculate(void);
voidSignal_Conversion(void);
voidSIG_Distribute(void);
floatDifferencevalue(floatnumber);//绝对值
double_squarert(doublenumber);//开方
structCtrl_FlagCtrlState;
structMeterage_ParameterphaseA,phaseB,phaseC;//定义测量参数
/*******************************************************************************
*FunctionName:
ADC_Configuration
*Description:
ThisfunctionhandlesADC_Configuration
*Input:
None
*Output:
None
*Return:
None
*******************************************************************************/
voidADC_Configuration(void)
{
ADC_InitTypeDefADC_InitStructure;
/*ADC1Configuration------------------------------------------------------*/
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;//独立工作模式
ADC_InitStructure.ADC_ScanConvMode=ENABLE;//扫描方式
ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;//连续转换
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;//外部触发禁止
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;//数据右对齐
ADC_InitStructure.ADC_NbrOfChannel=7;//用于转换的通道数
ADC_Init(ADC1,&ADC_InitStructure);
/*ADC1regularchannel8configuration*///[规则模式通道配置]
ADC_RegularChannelConfig(ADC1,ADC_Channel_0,4,ADC_SampleTime_239Cycles5);//Ia
ADC_RegularChannelConfig(ADC1,ADC_Channel_1,5,ADC_SampleTime_239Cycles5);//Ib
ADC_RegularChannelConfig(ADC1,ADC_Channel_2,6,ADC_SampleTime_239Cycles5);//Ic
ADC_RegularChannelConfig(ADC1,ADC_Channel_3,1,ADC_SampleTime_239Cycles5);//Ua
ADC_RegularChannelConfig(ADC1,ADC_Channel_4,2,ADC_SampleTime_239Cycles5);//Ub
ADC_RegularChannelConfig(ADC1,ADC_Channel_5,3,ADC_SampleTime_239Cycles5);//Uc
ADC_RegularChannelConfig(ADC1,ADC_Channel_6,7,ADC_SampleTime_239Cycles5);//Il
/*Configurehighandlowanalogwatchdogthresholds*/
//ADC_AnalogWatchdogThresholdsConfig(ADC1,0x0B00,0x0300);
/*Configurechannel8asthesingleanalogwatchdogguardedchannel*/
//ADC_AnalogWatchdogSingleChannelConfig(ADC1,ADC_Channel_8);
/*Enableanalogwatchdogononeregularchannel*/
//ADC_AnalogWatchdogCmd(ADC1,ADC_AnalogWatchdog_SingleRegEnable);
/*EnableAWDinterupt*/
//ADC_ITConfig(ADC1,ADC_IT_AWD,ENABLE);//AD中断
/*EnableADC1*/
ADC_Cmd(ADC1,ENABLE);
/*EnableADC1resetcalibarationregister*/
ADC_ResetCalibration(ADC1);//下面是ADC自动校准,开机后需执行一次,保证精度
/*ChecktheendofADC1resetcalibrationregister*/
while(ADC_GetResetCalibrationStatus(ADC1));
/*StartADC1calibaration*/
ADC_StartCalibration(ADC1);
/*ChecktheendofADC1calibration*/
while(ADC_GetCalibrationStatus(ADC1));
//DMA_Cmd(DMA1_Channel1,ENABLE);
/*StartADC1SoftwareConversion*/
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
/*EnableADC1DMA[使能ADC1DMA]*/
ADC_DMACmd(ADC1,ENABLE);
}
/*****************************************************************************
FunctionName:
SampleData*
Description:
SampletheADCconvertedvalueofonechannel*
Input:
AddressoftheADCDataTab,NumberoftheChannel*
Output:
SampleData*
Return:
SampleData*
******************************************************************************/
unsignedshortintSampleData(volatileunsignedshortintADCDataTab[],unsignedshortintnChannel)
{
autofloatValue=0;
for(ss10=0;ss10<(DATALEN-5);ss10++)
{
Value+=(unsignedshortint)(*(ADCDataTab+nChannel+ss10*TDCONLEN));
}
return(unsignedshortint)(Value/(DATALEN-5));
}
/*****************************************************************************
FunctionName:
Voltage_Conversion*
Description:
averagetheADCconvertedvalueofonechannel*
Input:
AddressoftheADCDataTab,NumberoftheChannel*
Output:
Averagevalue*
Return:
Averagevalue*
******************************************************************************/
voidVoltage_Conversion(void)
{
volatilesignedshortintAdcValueTmp=0;
ss12=0;
for(ss12=0;ss12<(TDCONLEN);ss12++)
{
AdcValueTmp=(SampleData(ADC_ValueData,ss12)-0x800);
zhengxuDateTab[ss13][ss12]=(AdcValueTmp*x_Num[ss13]);
fuxuDateTab[ss13][ss12]=(AdcValueTmp*y_Num[ss13]);
}ss13++;
if(ss13>=(DATALEN-1))
{
ss13=0;
CtrlState.ADCompute_Flag=1;
}
}
/*******************************************************************************
*FunctionName:
xinhaoConversion
*Description:
None
*Input:
None
*Output:
None
*Return:
None
*******************************************************************************/
voidxinhaoConversion(void)//信号转换
{
autounsignedcharxubu=0,shibu=0;//虚部和实部变量
autounsignedlongintTotalTemp=0;//总变量
autosignedlongintTotalSTemp=0,TotalLTemp=0;//总分量
if(CtrlState.ADCompute_Flag)
{
CtrlState.ADCompute_Flag=0;
for(shibu=0;shibu<(TDCONLEN-1);shibu++)
{
TotalSTemp=0;
TotalLTemp=0;
TotalTemp=0;
for(xubu=0;xubu<(DATALEN-1);xubu++)
{
TotalSTemp+=zhengxuDateTab[xubu][shibu];
TotalLTemp+=fuxuDateTab[xubu][shibu];
}
TotalSTemp=((TotalSTemp/(((float)((fangdabeishu*(fangdabeishu))*kxishu)))));
TotalLTemp=(TotalLTemp/(((float)((fangdabeishu*(fangdabeishu))*kxishu))));
TotalSTemp*=TotalSTemp;
TotalLTemp*=TotalLTemp;
TotalTemp=(TotalSTemp+TotalLTemp);//求矢量和
CH_ComputeTab[RLP_oweUT][shibu]=Differencevalue((float)TotalTemp);
}
CH_ComputeTab[RLP_oweUT][shibu]*=(CH_ComputeTab[RLP_oweUT][shibu]);
CH_ComputeTab[RLP_oweUT][shibu]=(((float)(_squarert((double)CH_ComputeTab[RLP_oweUT][shibu]))));
RLP_oweUT++;
if(RLP_oweUT>=1)
{
RLP_oweUT=0;
CtrlState.ADCAverage_Flag=1;
}
}
}
/*******************************************************************************
*FunctionName:
Signal_Conversion
*Description:
None
*Input:
None
*Output:
None
*Return:
None
*******************************************************************************/
voidSignal_Conversion(void)
{
xinhaoConversion();
SIG_Distribute();
}
/*******************************************************************************
*FunctionName:
SIG_Distribute*
*Description:
None
*Input:
floatdata
*Output:
unsignedintdata
*Return:
None
*******************************************************************************/
voidSIG_Distribute(void)
{
autounsignedchariii=0,jjj=0;
autodoubleaverage=0;
if(CtrlState.ADCAverage_Flag)
{