ccs mspm0g3507 高频采样+fft

📅 2026/7/13 21:56:44
ccs mspm0g3507 高频采样+fft
1.导入工程2.adc接口3.采样时间手动设置取样周期在32Mhz的adc时钟和12bit的模式下转化周期6*1/32M187.5ns采样时间取样周期转换周期812.5187.51000ns------1Mhz的采样率最大可设置为62.5ns可达到4Mhz的采样周期4.DSP的导入ccs空白工程添加dsp库-CSDN博客5.fft的代码#include ti_msp_dl_config.h #include arm_const_structs.h #include arm_math.h #define ADC_SAMPLE_SIZE (2048) /* When FIFO is enabled 2 samples are compacted in a single word */ #define ADC_FIFO_SAMPLES (ADC_SAMPLE_SIZE 1) /* Global variables and defines for FFT */ #define IFFTFLAG 0 #define BITREVERSE 1 /* Expected Maximum amplitude and frequency index of FFT */ #define GOLDEN_FFT_MAX_FREQ_INDEX (5) volatile int16_t gFFTintput[ADC_SAMPLE_SIZE * 2]; /* Array with FFT results */ volatile int16_t gFFTOutput[ADC_SAMPLE_SIZE * 2]; /* Maximum amplitude of FFT */ volatile uint32_t gFFTmaxValue; /* Index of maximum frequency */ volatile uint32_t gFFTmaxFreqIndex; uint16_t gADCSamples[ADC_SAMPLE_SIZE]; volatile bool gCheckADC;// 1. 将ADC原始数据转换为Q15格式并填充复数输入数组 for (int i 0; i ADC_SAMPLE_SIZE; i) { // 将ADC采样值缩放到Q15范围假设ADC为12位分辨率0-4095 // 缩放至[-1, 1)对应Q15的[-32768, 32767] float scale_factor 32767.0f / 2048.0f; // 2048为ADC量程的一半 int32_t scaled_value (int32_t)((gADCSamples[i] - 2048) * scale_factor); // 饱和处理防止溢出 if (scaled_value 32767) scaled_value 32767; if (scaled_value -32768) scaled_value -32768; // 填充复数数组实部ADC值虚部0 gFFTintput[2*i] (q15_t)scaled_value; // 实部 gFFTintput[2*i1] 0; // 虚部 } // 2. 初始化FFT实例使用预定义配置表 const arm_cfft_instance_q15 *fft_instance arm_cfft_sR_q15_len2048; // 3. 执行FFT变换 arm_cfft_q15(fft_instance, (q15_t*)gFFTintput, IFFTFLAG, BITREVERSE); // 4. 计算复数幅度Q15格式输出 arm_cmplx_mag_q15((q15_t*)gFFTintput, (q15_t*)gFFTOutput, ADC_SAMPLE_SIZE); // 5. 寻找幅度最大值及其频率索引 uint32_t maxIndex 0; arm_max_q15((q15_t*)gFFTOutput, ADC_SAMPLE_SIZE, (q15_t*)gFFTmaxValue, maxIndex); gFFTmaxFreqIndex maxIndex; // 存储峰值频率索引 for(int i0;i5;i) { // gFFTOutput[(i1)*gFFTmaxFreqIndex]gFFTOutput[(i1)*gFFTmaxFreqIndex-2]; // gFFTOutput[(i1)*gFFTmaxFreqIndex]gFFTOutput[(i1)*gFFTmaxFreqIndex2]; gFFTOutput[(i1)*gFFTmaxFreqIndex]gFFTOutput[(i1)*gFFTmaxFreqIndex-1]; gFFTOutput[(i1)*gFFTmaxFreqIndex]gFFTOutput[(i1)*gFFTmaxFreqIndex1]; }