首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

调用ti的库函数2812的fft源程序!经典!推荐![转帖]

调用ti的库函数2812的fft源程序!经典!推荐![转帖]

经过多天的调试,终于调通了,为了方便大家少走弯路,带来痛苦,提高效率,下面将我的感受和源程序写出来,供大家学习!!希望大家共同交流!这个我已经运行了,通过了,大家做的时候先用matlab验证一下sin的频率!然后看计算结果对不!
2005.04.7号上午八点40程序纪录,这个程序运算完全正确,和前一个程序不同之处在sin值得大小,由于2812时定点运算,sin值得大小不能太小!否则计算结果为零!2812fft的错误在于fft.init1(),fft.init2()这两个函数没有这函数库里面定义,而是该用fft.init(&fft),而且由于是定点运算,输入的sin值不能太小,要不然计算结果为零!

#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "fft.h"
#include
#define BUF_SIZE 128
#pragma DATA_SECTION(ipcb, "FFTipcb");
#pragma DATA_SECTION(mag, "FFTmag");
// Prototype statements for functions found within this file.
// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 fftflag=0;//FFT转换启动标志:0不启动;1:启动
Uint16 i;
long Voltage1[BUF_SIZE];
long Voltage2[BUF_SIZE];
long ipcb[BUF_SIZE];
RFFT32 fft=RFFT32_128P_DEFAULTS;
//CFFT32 fft=CFFT32_128P_DEFAULTS;
long mag[BUF_SIZE/2+1];
const long win[BUF_SIZE/2]=HANNING128;
int x1;
long k=0;
double j=0.12345;

main()
{
Uint16 i;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// For this example, set HSPCLK to SYSCLKOUT / 6 (25Mhz assuming 150Mhz SYSCLKOUT)
EALLOW;
SysCtrlRegs.HISPCP.all = 0x3; // HSPCLK = SYSCLKOUT/6
EDIS;

// Step 2. Initialize GPIO:
// This example function is found in the DSP281x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP281x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
InitPieVectTable();

// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
// EALLOW; // This is needed to write to EALLOW protected register
// PieVectTable.ADCINT = &adc_isr;
// EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
InitAdc(); // For this example, init the ADC
// Step 5. User specific code, enable interrupts:

PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
LoopCount = 0;
ConversionCount = 0;

for(i=0;i {
// Voltage1=(long)1000*sin((2*3.14159*i)/25);
ipcb=(long)10000000*sin((2*3.14159*i)/12);
}

// RFFT32_brev(Voltage1,ipcb,BUF_SIZE);
//initialize FFT module
fft.ipcbptr=ipcb;
fft.magptr=ipcb;//存放幅度
// fft.magptr=ipcb;
// fft.winptr=(long *)win;//加窗
fft.init(&fft);
// fft.win(&fft);
RFFT32_brev(ipcb,ipcb,BUF_SIZE);
// RFFT32_brev(ipcb,ipcb,16);
fft.calc(&fft);
fft.split(&fft);
fft.mag(&fft);
for(i=0;i {
mag=sqrt(mag);
}
}

/*
//###########################################################################
//
// FILE: F2812_EzDSP_RAM_lnk.cmd
//
// TITLE: Linker Command File For F2812 eZdsp examples that run out of RAM
// This linker file assumes the user is booting up in Jump to H0 mode
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 1.00| 11 Sep 2003 | L.H. | Changes since previous version (v.58 Alpha)
// | | | Added BEGIN section to the start of H0
// | | | Removed .bss, .const and .sysmem
// | | | These are for a small memory model. All examples
// | | | use the large model.
// | | | Added .esysmem section
// | | | Changed ramfuncs section to load and run from RAM
// | | | (previously this was type DSECT)
// | | | Moved peripheral register files to DSP28_Headers_BIOS.cmd
// | | | and DSP28_Headers_nonBIOS.cmd
// | | | Added CSM_RSVD memory section in FLASHA - this region
// | | | should be programmed with all 0x0000 when using the CSM
// -----|-------------|------|-----------------------------------------------
//###########################################################################
*/
/* ======================================================
// For Code Composer Studio V2.2 and later
// ---------------------------------------
// In addition to this memory linker command file,
// add the header linker command file directly to the project.
// The header linker command file is required to link the
// peripheral structures to the proper locations within
// the memory map.
//
// The header linker files are found in \DSP281x_Headers\cmd
//
// For BIOS applications add: DSP281x_Headers_nonBIOS.cmd
// For nonBIOS applications add: DSP281x_Headers_nonBIOS.cmd
========================================================= */
/* ======================================================
// For Code Composer Studio prior to V2.2
// --------------------------------------
// 1) Use one of the following -l statements to include the
// header linker command file in the project. The header linker
// file is required to link the peripheral structures to the proper
// locations within the memory map */
/* Uncomment this line to include file only for non-BIOS applications */
/* -l DSP281x_Headers_nonBIOS.cmd */
/* Uncomment this line to include file only for BIOS applications */
/* -l DSP281x_Headers_BIOS.cmd */
/* 2) In your project add the path to \DSP281x_headers\cmd to the
library search path under project->build options, linker tab,
library search path (-i).
/*========================================================= */

MEMORY
{
PAGE 0 :
/* For this example, H0 is split between PAGE 0 and PAGE 1 */
/* BEGIN is used for the "boot to HO" bootloader mode */
/* RESET is loaded with the reset vector only if */
/* the boot is from XINTF Zone 7. Otherwise reset vector */
/* is fetched from boot ROM. See .reset section below */

RAMM0 : origin = 0x000000, length = 0x000400
BEGIN : origin = 0x3F8000, length = 0x000002
PRAMH0 : origin = 0x3F8002, length = 0x000FFE
RESET : origin = 0x3FFFC0, length = 0x000002

PAGE 1 :
/* For this example, H0 is split between PAGE 0 and PAGE 1 */
RAMM1 : origin = 0x000400, length = 0x000400
DRAMH0 : origin = 0x3f9000, length = 0x001000
}


SECTIONS
{
/* Setup for "boot to H0" mode:
The codestart section (found in DSP28_CodeStartBranch.asm)
re-directs execution to the start of user code.
Place this section at the start of H0 */
codestart : > BEGIN, PAGE = 0
ramfuncs : > PRAMH0 PAGE = 0
.text : > PRAMH0, PAGE = 0
.cinit : > PRAMH0, PAGE = 0
.pinit : > PRAMH0, PAGE = 0
.switch : > RAMM0, PAGE = 0
.reset : > RESET, PAGE = 0, TYPE = DSECT /* not used, */
FFTtf > PRAMH0, PAGE = 0
FFTipcb ALIGN(256): {}> DRAMH0, PAGE = 1
FFTmag > DRAMH0, PAGE = 1
.stack : > RAMM1, PAGE = 1
.ebss : > DRAMH0, PAGE = 1
.econst : > DRAMH0, PAGE = 1
.esysmem : > DRAMH0, PAGE = 1

}

[此贴子已经被作者于2005-11-15 14:33:25编辑过]

高手!厉害!佩服!
学习一下!
3x!
O(∩_∩)O谢谢
返回列表