/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2023 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "adc.h" #include "dac.h" #include "dma.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "arm_math.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ #define DATA_LEN 2048 uint32_t result_data[DATA_LEN]; //float32_t rms_buf[DATA_LEN]; /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ arm_rfft_fast_instance_f32 S; float32_t fft_rawdata[DATA_LEN]; float32_t fft_outdata[DATA_LEN]; float32_t fft_mag[DATA_LEN>>1]; float32_t window_data[DATA_LEN]; float32_t Vdc= 0; float32_t V50hz_mA=0; //float32_t offset= 0; float32_t max_val,main_freq; float32_t rms_mV,rms_mA,Vpp; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ void arm_hanning_f32(float32_t * pDst,uint32_t blockSize) { float32_t k = 2.0f / ((float32_t) blockSize); float32_t w; for(uint32_t i=0;i>1); arm_scale_f32(fft_mag,4.0f/DATA_LEN,fft_mag,DATA_LEN>>1); Vdc = fft_mag[0]/2.0f; arm_max_f32(&fft_mag[5],(DATA_LEN>>2)-1,&max_val,&max_val_freq); main_freq = ((float32_t)max_val_freq+5.0)/DATA_LEN*2000.0; // 单独50Hz频率信号的有效值 无需归零校准 V50hz_mA = fft_mag[51]/4096.0*3300.0f*0.0380/1.414; // 信号频率为50Hz左右 // if(main_freq<75.0f && main_freq>35.0f) // { for(i = 0;i