老古开发网首页
导航:老古开发网首页文章索引文章分类DSP数字信号处理→[C2000例程连载6]
| -文章搜索 - 最新文章 - |

C2000例程连载6

发布时间:2006年7月24日 点击次数:1140
来源:   作者:
 

F2812 fft 源程序 TI例程

作者不详

/**************************************************************/
/* */
/*     fft.c */
/* */
/**************************************************************/

/*
Fast Fourier Transform (FFT).
Using 8 points, takes about 1.2 ms to execute one FFT.
Sets up General Purpose Timer 1 to generate events at 10 kHz.
Will produce 10 kHz output on T1PWM and T1PWM pins.
*/

#include "system.h"
#include "eva.h"
#include "io2407.h"
#include "adc.h"
#include "interrup.h"

#include "fftcmplx.h" /* Complex structure definition*/

extern void FFT(COMPLEX *Y, int N); /* FFT Function */

/* The following define gives the number of samples. */
/* It should divide exactly into 512 */
/* Should N be increased, to say to 32, then the execution */
/* time of the FFT would increase */

#define N 8

unsigned int perform_fft = 0; /* Flag driven by interrupt */

/*************************************************************/
/*
Initialise General Purpose Timers GPT1 and GPT2
*/
/*************************************************************/

/* Initialise General Purpose Timer 1. */

void init_GPT1(void)
{
MCRA = T1PWM; /* Turn on T1PWM */
T1CON = 0x8142; /* Turn off GPT1 */
GPTCONA = 0x0041; /* Active low. */
T1PR = 1475; /* Sample at 10 kHz */
T1CMPR = 0; /* Duty = 0% */
T1CNT = 0xFFFE; /* Set to -2 */
T1CON = 0x9142; /* Start timer 1 */

EVAIFRA = 0xFFFF; /* Clear any pending interrupts */
EVAIMRA = T1PINT_FLAG; /* Enable T1 period interrupt */
}

/* Initialise General Purpose Timer 2 */

void init_GPT2(void)
{
MCRA = T2PWM; /* Turn on T2PWM */
T2CON = 0x8142; /* Turn off GPT2 */
GPTCONA = 0x0008; /* Controlled from GPT1 */
T2PR = 1475; /* Sample at 10 kHz */
T2CMPR = 0; /* Duty cycle 0% decimal */
T2CNT = 0xFFFE; /* Set to -2 */
T2CON = 0x9142; /* Start timer 2 */
}

/**************************************************************/

void init_ADC()
{
/* Non Cascade for 8 measurements. */
/* Will affect RESULT0 to RESULT7 only */

ADCCTRL1 = (ADC_SOFT ADC_CPS /* ADC_ACQ_PS3 ADC_ACQ_PS2*/ );

CHSELSEQ1 = 0x3210; /* 8 measurements 0 */
CHSELSEQ2 = 0x0000;
CHSELSEQ3 = 0xFFFF;
CHSELSEQ4 = 0xFFFF;
MAX_CONV = 0x0007; /* 8 measurements, not 0 */

/* Reset sequence at zero and software start of conversion */

ADCCTRL2 = ( RST_SEQ1 SOC_SEQ1);

} /* No semicolon here */

/***********************************************************/

int input_buffer[N] = {8191, 8191, 8191, 8191, 0, 0, 0, 0};

COMPLEX y[N]; /* Variable passed to FFT and modified */

/***********************************************************/
/*
Shuffle input buffer along one place.
Put latest input from ADC into first buffer location.
Input from ADCIN2 lies in range 0 to FFC0h (65472 decimal).
Divide by 8 to limit range from 0 to 8184.
*/
/***********************************************************/

void shuffle_and_read(void)
{
signed int i;

for ( i = N-1 ; i > 0 ; i--)
{
input_buffer[i] = input_buffer[i-1];
}

input_buffer[0] = (RESULT2 >> 3);
}

/***********************************************************/
/*
Copy from input buffer to complex structure.
When FFT is performed, the complex structure is overwritten
by the return values.
*/
/***********************************************************/

void copy_input_to_complex(void)
{
unsigned int i;

for ( i = 0 ; i < N; i++)
{
(y[i]).real = input_buffer[i];
(y[i]).imag = 0;
}
}

/***********************************************************/
/*
Main program
Uses timers to read analog input on ADCIN2 into a buffer
and then perform an 8-point FFT on it.
*/
/**********************************************************/

void main(void)
{
signed int output1, output2;
signed int x; /* General purpose variable. */
signed int i; /* Counter */
signed long temp;

init_system(); /* Initialize variables and hardware */

init_ADC(); /* Initialise ADC */
init_GPT1(); /* Turn on timer 1 */
init_GPT2(); /* Turn on timer 2 */

MCRB &= 0xFFFE; /* I/O on IOPC0 for monitoring purposes */

IMR = INT2; /* Turn on INT 2 */

asm(" CLRC INTM"); /* Turn on maskable interrupts */

for ( ;; )
{
if ( perform_fft != 0 )
{
perform_fft = 0; /* Clear flag used to start fft */

PCDATDIR = 0x0101; /* IOPC0 high */

ADCCTRL2 = SOC_SEQ1; /* Start next conversion*/

copy_input_to_complex(); /* Copy inputs from receive buffer */


FFT(y,8); /* Calls generic FFT function*/

/* Determine magnitude of (y[0]).real */
/* output1 lies in range 0 to 32736 */

if ( (y[0]).real > 0)
output1 = (y[0]).real;
else
output1 = -(y[0]).real;

/* Determine magnitude of (y[0]).real */
/* output2 lies in range -32736 to 32736 */

if ( (y[2]).real > 0)
output2 = (y[2]).real;
else
output2 = -(y[2]).real;

/* Scale output in range 0 to 1475 */

temp = (signed long)(output1 * 2952);
output1 = (signed int)(temp >> 16);

T1CMPR = output1;

temp = (signed long)( output2 * 2952);
output2 = (signed int)(temp >> 16);

T2CMPR = output1;

shuffle_and_read(); /* Read in latest value from ADC */
/* and put into buffer */

PCDATDIR = 0x0100; /* IOPC0 low */

} /* End if */

} /* End for */

} /* End main() */

/************************************************************/

/* Interrupt routine */
/* The interrupt occurs once every 0.1 ms.
/* Will make perform_fft = 1 once every 20 * 0.1 ms = 2 ms */

void c_int2(void)
{
static unsigned int x;

if ( 0x0027 == PIVR)
{
EVAIFRA = T1PINT_FLAG; /* Clear GPT1 period interrupt */

if ( x < 19 ) /* Increase if FFT with more points */
{
x++;
}
else
{
x = 0;
perform_fft = 1; /* Global flag to start FFT */
}

}
}

/* End of fft.c */

/************************************************************/


欢迎进入老古论坛进行讨论
[DSP数字信号处理] 相关文章:
C2000例程连载3
简介:
S320F2812的延时程序 作者不详 .def _DSP28x_usDelay ;==================================================== ;Delay Function ;The C assembly call will look as follows: ; ; extern void Delay(long time); &nb......

C2000例程连载2
C2000例程连载1
C/C++中多维数组指针作为函数参数传递!
如何用C语言开发DSP嵌入式系统(肖宛昂 曾为民)
德州仪器以3.25 美元的最低售价推出业界最低成本 32 位数字信号控制器
基于DSP和CPLD的宽带信号源的设计
2000系列dsp的MP/MC管脚[YC]
基于DSP与双目CMOS摄像头的数字图像处理系统
基于DSP的小型直流风扇自动化测试系统
 
下一个:[DSP数字信号处理]C2000例程连载4
简介:
一个关于TMS320LF2407异步串行例子 作者不详 这里有一个关于TMS320LF2407异步串行例子:(也适用于F240) ;=========================================================== * File Name: SCI.asm * Description: PROGRAM TO PERFORM A LOOPBACK IN THE SCI MODULE * This program is capable of doing either an internal loopback or an e......
 

上一个:[DSP数字信号处理]C2000例程连载7

老古开发网版权所有 2006年9月 asp.Net V2.0 设计:老古
页面缓存:10分钟 执行时间:16毫秒