#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
/* for test fft */
#include "fft.h"
#include"math.h"
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
int FindMax(long a[],int length);
void scia_loopback_init(void);
void scia_fifo_init(void);
void scia_xmit(int a);
void error(int);
void wait(int nWait);
void SendString(char *String);
//void InitForFFT();
void itoa (int n,char s[]);
// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Voltage1[1024];
Uint16 MaxAdd=0;
#define N 1024 //FFT Length
#pragma DATA_SECTION(ipcb, "FFTipcb");
#pragma DATA_SECTION(mag,"FFTmag");
RFFT32 fft=RFFT32_1024P_DEFAULTS;
long ipcb[N+2]; //In place computation buffer
long mag[N/2+1]; //Magnitude buffer
char cReceive,cBuffer[17];
//const long win[N/2]=HAMMING128; //Window coefficient array
RFFT32_ACQ acq=FFTRACQ_DEFAULTS; //Instance the module
main()
{
int i,Max;
float Frequence,Speed;
char ReceivedChar;
int k=0;
InitSysCtrl();//初始化cpu
DINT;//关中断
InitPieCtrl();//初始化pie寄存器
/* Initialize acquisition module */
acq.buffptr=ipcb;
acq.tempptr=ipcb;
acq.size=N;
acq.count=N;
acq.acqflag=1;
/* Initialize FFT module */
fft.ipcbptr=ipcb;
fft.magptr=mag;
fft.init(&fft);
IER = 0x0000;//禁止所有的中断
IFR = 0x0000;
InitPieVectTable();//初始化pie中断向量表
// 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
AdcRegs.ADCTRL1.bit.RESET = 1; // Reset the ADC module
asm(" RPT #10 || NOP"); // Must wait 12-cycles (worst-case) for ADC reset to take effect
AdcRegs.ADCTRL3.all = 0x00C8; // first power-up ref and bandgap circuits
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3; // Power up bandgap/reference circuitry
AdcRegs.ADCTRL3.bit.ADCPWDN = 1; // Power up rest of ADC
// Enable ADCINT in PIE
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 = 1;
// Configure ADC
AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 2 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.
// AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup ADCINA2 as 2nd SEQ1 conv.
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
// Configure EVA
// Assumes EVA Clock is already enabled in InitSysCtrl();
EvaRegs.T1CMPR = 0x0080; // Setup T1 compare value
// EvaRegs.T1PR = 0x61a8; // Setup period register
EvaRegs.T1PR=2500; //0.4us*EvaRegs.T1PR
EvaRegs.GPTCONA.bit.T1TOADC = 1; // Enable EVASOC in EVA
EvaRegs.T1CON.all = 0x1042; // Enable timer 1 compare (upcount mode)
EALLOW;
GpioMuxRegs.GPFMUX.all=0x0030; // Select GPIOs to be Sci pins // Port F MUX - x000 0000 0011 0000
EDIS;
scia_fifo_init(); // Initialize the SCI FIFO
scia_loopback_init(); // Initalize SCI for digital loop back
// Note: Autobaud lock is not required for this example
// Send a character starting with 0
// Step 6. Send Characters forever starting with 0x00 and going through
// 0xFF. After sending each, check the recieve buffer for the correct value
SendString("Hello DSP!");
// Wait for ADC interrupt
while(1)
{
//LoopCount++;
if (acq.acqflag==0) // If the samples are acquired
{
DINT;
//RFFT32_brev(ipcb,ipcb,N);
//RFFT32_brev(ipcb,ipcb,N); // Input samples in Real Part
fft.calc(&fft);
fft.split(&fft);
fft.mag(&fft);
for(i=0;i<N;i++)
{
mag[i]=sqrt(mag[i]);
}
acq.acqflag=1; // Enable the next acquisition
Max=FindMax(mag,1024);
Frequence=29.296875*MaxAdd;//可测量范围20-1500Hz
// Max=Frequence;
while(SciaRegs.SCIFFRX.bit.RXFIFST !=0) // 如果接受寄存器不为0则跳出
{ ReceivedChar = SciaRegs.SCIRXBUF.all;
cBuffer[k]=ReceivedChar;
if ( ReceivedChar=='F')
{
cBuffer[k+1]='\0';
//nLen=k+1;
SendString("FFT Frequency is:");
//bReceive=1;
//break;
itoa(Frequence,cBuffer);
SendString(cBuffer);
SendString("Hz");
//scia_xmit('\n');
}
if ( ReceivedChar=='V')
{
cBuffer[k+1]='\0';
//nLen=k+1;
SendString("The Speed is:");
//bReceive=1;
//break;
Speed=(Frequence*10.8)/483;//Fd*c/2f0
itoa(Speed,cBuffer);
SendString(cBuffer);
SendString("Km/h");
//scia_xmit('\n');
}
k++; k%=16;
}
EINT;
}
}
}
interrupt void adc_isr(void)
{
Voltage1[ConversionCount] = AdcRegs.ADCRESULT0>>4;
acq.input=((unsigned long)Voltage1[ConversionCount])<<16;
acq.update(&acq);
// ipcb[ConversionCount]=((unsigned long)Voltage1[ConversionCount])<<16;
//Voltage2[ConversionCount] = AdcRegs.ADCRESULT1 >>4;
// If 40 conversions have been logged, start over
if(ConversionCount == 1023)
{
ConversionCount = 0;
// acq.acqflag=0;
}
else ConversionCount++;
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
int FindMax(long a[],int length)
{
int i,maxvalue=0;
for (i=1;i<length;i++)
{
if (i==1)
{
maxvalue = a[i];
}
else
{
if (maxvalue < a[i])
{
maxvalue = a[i];
MaxAdd=i;
}
}
}
return maxvalue;
}
// Test 1,SCIA DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void scia_loopback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all =0x0003;
SciaRegs.SCICTL2.bit.TXINTENA =1;
SciaRegs.SCICTL2.bit.RXBKINTENA =1;
SciaRegs.SCIHBAUD =0x0001;
SciaRegs.SCILBAUD =0x00e7;
SciaRegs.SCICCR.bit.LOOPBKENA =0; // disable loop back
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
// Transmit a character from the SCI'
void scia_xmit(int a)
{
SciaRegs.SCITXBUF=a;
}
// Initalize the SCI FIFO
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
}
void wait(int nWait)
{
int i,j,k=0;
for ( i=0;i<nWait;i++ )
for ( j=0;j<64;j++ )
k++;
}
没有合适的资源?快使用搜索试试~ 我知道了~
DSP TMS320F2812 内部FLASH脱机运行测速程序
共44个文件
obj:20个
cmd:3个
paf:2个
2星 需积分: 9 32 下载量 28 浏览量
2010-11-15
16:39:49
上传
评论
收藏 315KB RAR 举报
温馨提示
基于ICETEK-F2812-A开发板,测速程序编译后下载内部FLASH,上电后从FLASH启动,实现脱机运行。
资源推荐
资源详情
资源评论
收起资源包目录
Flash_Test.rar (44个子文件)
Flash_Test
DSP281x_Headers_nonBIOS.cmd 5KB
F2812.cmd 7KB
Example_281xSci_FFDLB.gel 502B
adfft.c 8KB
sci.CS_
SYMBOL.CDX 425KB
SYMBOL.FPT 587KB
FILE.FPT 2KB
FILE.DBF 1KB
SYMBOL.DBF 340KB
FILE.CDX 3KB
sci.sbl 12KB
DSP281x_PieVect.obj 16KB
DSP281x_DefaultIsr.obj 36KB
DSP281x_CodeStartBranch.obj 1KB
sci.paf2 8KB
sci.pjt 2KB
DSP281x_GlobalVariableDefs.obj 114KB
FLASH_SCI.c 2KB
Debug.lkv 1016B
DSP281x_PieCtrl.obj 5KB
sic.paf 7KB
FLASH+SCI.obj 5KB
Debug
DSP281x_PieVect.obj 16KB
FLASH_SCI.obj 5KB
DSP281x_DefaultIsr.obj 36KB
DSP281x_CodeStartBranch.obj 1KB
sci.map 18KB
DSP281x_GlobalVariableDefs.obj 114KB
DSP281x_PieCtrl.obj 5KB
FLASH+SCI.obj 5KB
Example_281xSci_FFDLB.obj 18KB
sci.obj 45KB
adfft.obj 47KB
DSP281x_Sci.obj 2KB
DSP281x_SysCtrl.obj 9KB
sci.out 139KB
AD1.dat 4KB
cc_build_Debug.log 3KB
adfft.cmd 6KB
DSP281x_CodeStartBranch.asm 2KB
DSP281x_Sci.obj 2KB
sci.paf 7KB
DSP281x_SysCtrl.obj 9KB
Debug.lkf 762B
共 44 条
- 1
资源评论
- zerochenxiaoj2013-07-08被坑了,程序没法用,文件都是缺失的
- sanghaysay2015-09-23写得比较深奥
xwlingh
- 粉丝: 3
- 资源: 42
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功