/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file main.c
**
** \brief This sample demonstrates how to set GPIO as output function.
**
** - 2021-04-16 CDT first version for Device Driver Library of GPIO.
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "hc32_ddl.h"
#include "ev_hc32f460_lqfp100_v1.h"
#include "TIM_Measure.h"
#include "arm_math.h"
#include "arm_const_structs.h"
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define LENGTH 1024
#define DOUBLE_LENGTH 2*LENGTH
#define FS 5000.0f
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
float t = 0.0f;
float CFFT_Inputbuf[DOUBLE_LENGTH]; //FFT输入数组
float CFFT_Outputbuf[LENGTH]; //FFT输出数组
float CFFT_x2_Inputbuf[DOUBLE_LENGTH]; //FFT输入数组
float CFFT_x2_Outputbuf[LENGTH]; //FFT输出数组
float CFFT_x4_Inputbuf[DOUBLE_LENGTH]; //FFT输入数组
float CFFT_x4_Outputbuf[LENGTH]; //FFT输出数组
float RFFT_Inputbuf[LENGTH]; //FFT输入数组
float RFFT_Outputbuf[LENGTH]; //FFT输出数组
float RFFT_Output_buf[LENGTH]; //FFT输出数组
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief Main function of GPIO output
**
** \param None
**
** \retval int32_t Return value, if needed
**
******************************************************************************/
int32_t main(void)
{
int i = 0;
stc_clk_freq_t stc_clk;
arm_rfft_fast_instance_f32 S1;
arm_cfft_radix2_instance_f32 S2;
arm_cfft_radix4_instance_f32 S4;
BSP_CLK_Init();
DDL_PrintfInit(BSP_PRINTF_DEVICE, BSP_PRINTF_BAUDRATE, BSP_PRINTF_PortInit);
TIM_Measure_Init();
CLK_GetClockFreq(&stc_clk);
DDL_Printf("System Clock: %dMHz\n",stc_clk.sysclkFreq/1000/1000);
DDL_Printf("\n");
for(i = 0;i < LENGTH;i++)
{
CFFT_Inputbuf[i << 1] = 10 + 4.5*arm_sin_f32(2*PI*i*200/ FS)+ 3.2*arm_sin_f32(2*PI*i*350/ FS);
CFFT_Inputbuf[(i << 1) + 1] = 0;
CFFT_x2_Inputbuf[i << 1] = 10 + 4.5*arm_sin_f32(2*PI*i*200/ FS)+ 3.2*arm_sin_f32(2*PI*i*350/ FS);
CFFT_x2_Inputbuf[(i << 1) + 1] = 0;
CFFT_x4_Inputbuf[i << 1] = 10 + 4.5*arm_sin_f32(2*PI*i*200/ FS)+ 3.2*arm_sin_f32(2*PI*i*350/ FS);
CFFT_x4_Inputbuf[(i << 1) + 1] = 0;
RFFT_Inputbuf[i << 1] = 10 + 4.5*arm_sin_f32(2*PI*i*200/ FS)+ 3.2*arm_sin_f32(2*PI*i*350/ FS);
}
while(1)
{
TIM_Measure_Start();
arm_cfft_f32(&arm_cfft_sR_f32_len1024,CFFT_Inputbuf,0,1);
TIM_Measure_Stop();
t = Get_Time();
DDL_Printf("arm_cfft_f32 use time: %fus\n",t*1000.0f);
arm_cmplx_mag_f32(CFFT_Inputbuf,CFFT_Outputbuf,LENGTH);
DDL_Printf("calc amp at base: %f,actual is 10\n",CFFT_Outputbuf[0]/LENGTH);
DDL_Printf("calc amp at 200Hz: %f,actual is 4.5\n",CFFT_Outputbuf[(unsigned int)(200*LENGTH/FS) + 1]/(LENGTH/2.0f));
DDL_Printf("calc amp at 350Hz: %f,actual is 3.2\n",CFFT_Outputbuf[(unsigned int)(350*LENGTH/FS) + 1]/(LENGTH/2.0f));
DDL_Printf("\n");
arm_cfft_radix2_init_f32(&S2,LENGTH,0,1);
TIM_Measure_Start();
arm_cfft_radix2_f32(&S2,CFFT_x2_Inputbuf);
TIM_Measure_Stop();
t = Get_Time();
DDL_Printf("arm_cfft_radix2_f32 use time: %fus\n",t*1000.0f);
arm_cmplx_mag_f32(CFFT_x2_Inputbuf,CFFT_x2_Outputbuf,LENGTH);
DDL_Printf("calc amp at base: %f,actual is 10\n",CFFT_x2_Outputbuf[0]/LENGTH);
DDL_Printf("calc amp at 200Hz: %f,actual is 4.5\n",CFFT_x2_Outputbuf[(unsigned int)(200*LENGTH/FS) + 1]/(LENGTH/2.0f));
DDL_Printf("calc amp at 350Hz: %f,actual is 3.2\n",CFFT_x2_Outputbuf[(unsigned int)(350*LENGTH/FS) + 1]/(LENGTH/2.0f));
DDL_Printf("\n");
arm_cfft_radix4_init_f32(&S4,LENGTH,0,1);
TIM_Measure_Start();
arm_cfft_radix4_f32(&S4,CFFT_x4_Inputbuf);
TIM_Measure_Stop();
t = Get_Time();
DDL_Printf("arm_cfft_radix4_f32 use time: %fus\n",t*1000.0f);
arm_cmplx_mag_f32(CFFT_x4_Inputbuf,CFFT_x4_Outputbuf,LENGTH);
DDL_Printf("calc amp at base: %f,actual is 10\n",CFFT_x4_Outputbuf[0]/LENGTH);
DDL_Printf("calc amp at 200Hz: %f,actual is 4.5\n",CFFT_x4_Outputbuf[(unsigned int)(200*LENGTH/FS) + 1]/(LENGTH/2.0f));
DDL_Printf("calc amp at 350Hz: %f,actual is 3.2\n",CFFT_x4_Outputbuf[(unsigned int)(350*LENGTH/FS) + 1]/(LENGTH/2.0f));
DDL_Printf("\n");
arm_rfft_fast_init_f32(&S1,LENGTH);
TIM_Measure_Start();
arm_rfft_fast_f32(&S1,RFFT_Inputbuf,RFFT_Outputbuf,0);
TIM_Measure_Stop();
t = Get_Time();
DDL_Printf("arm_rfft_fast_f32 use time: %fus\n",t*1000.0f);
arm_cmplx_mag_f32(RFFT_Outputbuf,RFFT_Output_buf,LENGTH);
DDL_Printf("calc amp at base: %f,actual is 10\n",RFFT_Output_buf[0]/LENGTH);
DDL_Printf("calc amp at 200Hz: %f,actual is 4.5\n",RFFT_Output_buf[(unsigned int)(200*LENGTH/FS) + 1]/(LENGTH/2.0f));
DDL_Printf("calc amp at 350Hz: %f,actual is 3.2\n",RFFT_Output_buf[(unsigned int)(350*LENGTH/FS) + 1]/(LENGTH/2.0f));
DDL_Printf("\n");
while(1);
};
}
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
不开启FPU: