EDA365电子论坛网
标题:
TMS320C5502多波形发生器源程序
[打印本页]
作者:
MLXG
时间:
2021-9-29 13:19
标题:
TMS320C5502多波形发生器源程序
本帖最后由 MLXG 于 2021-9-29 14:04 编辑
3 b3 z5 v* U! i9 h& Q7 Q7 [
7 L9 T* ]7 h9 R" y1 P
可产生正弦波,锯齿波等
/***********************************************************************************/
/* 文件名: Taylorsine.c (将sineCODEC和sinecompute合并,实现计算并实时输出) */
/* 创建时间:10/05/2012 */
/* 功能描述:利用Taylor展开式法计算正弦波,并将信号从J6端口发送出去,平台为BJTU-DSP5502板*/ */
/* 修改者 hailingao , 06/25 */
/************************************************************************************/
#include <math.h>
#include <stdio.h>
#include <csl.h>
#include <csl_chip.h>
#include <csl_i2c.h>
#include <csl_pll.h>
#include <csl_mcbsp.h>
#include <csl_emif.h>
#include <csl_emifBhal.h>
#include <stdio.h>
//#include "E2PROM_Function.h"
#include "CODEC.h"
#define Nx 360 //每周期抽取点数
#pragma DATA_SECTION(output1,"data_out1"); //存放sin数据,浮点型
float output1[Nx];
#pragma DATA_SECTION(output,"data_out"); //存放sin数据,定点型
int output[Nx];
#undef CODEC_ADDR
#define CODEC_ADDR 0x1A
// 定义McBSP的句柄
MCBSP_Handle hMcbsp;
/*------------------------------------------------------------------------------------*/
//
// FUNCTION: MAIN
//
/*------------------------------------------------------------------------------------*/
void main(void)
{
Uint16 i,k=0;
float input0=0,x1;
float a,b,c,d,e,f,g,h,ii,step;//step为角度步长
step=360.0/Nx; // Nx为360度内取样点数
/*****************新增函数段*****************/
for(i=0;i<=Nx-1;i++)
{
float angle,xx;
angle=input0+step*i;
x1=3.1415926*angle/180;
xx=x1*x1;
a=1-xx/16/17;b=1-xx/14/15*a;c=1-xx/12/13*b;d=1-xx/10/11*c;e=1-xx/8/9*d;f=1-xx/6/7*e;g=1-xx/4/5*f;h=1-xx/2/3*g;ii=x1*h;
// g=x1*(1-xx/2/3*(1-xx/4/5*(1-xx/6/7*(1-xx/8/9*(1-xx/10/11*(1-xx/12/13*(1-xx/14/15*(1-xx/16/17))))))));//数学总公式
// fprintf(stdout,"COMPUTE%f",ii); fprintf(stdout,"\n "); //输出计算的正弦波的数值,x2=e
output1
= 32767*ii; //利用泰勒级数计算出正弦波的数值,存放到output1中
output
=output1
;
}
// Initialize CSL library - This is REQUIRED !!!
CSL_init();
// The main frequency of system is 240MHz
// 该频率是为了设置IIC模块的需要设置的,为了使用I2C_setup函数
PLL_setFreq(1, 0xC, 0, 1, 3, 3, 0);
//EMIF初始化
Emif_Config();
// Open McBSP port 1 and get a McBSP type handle
hMcbsp = MCBSP_open(MCBSP_PORT1,MCBSP_OPEN_RESET);
// Config McBSP port 1 by use previously defined structure
Mcbsp_Config(hMcbsp);
//I2C初始化
I2C_cofig();
//CODEC寄存器初始化
inti_AIC();
/*------------------------------------------------------------------------------------*/
// Receive the ADC output data of CODEC
// Then output the received data to DAC of CODEC
/*------------------------------------------------------------------------------------*/
while(1)
{
while(!MCBSP_xrdy(hMcbsp)) {};
MCBSP_write16(hMcbsp, output[k]); //左声道输出
while(!MCBSP_xrdy(hMcbsp)) {};
MCBSP_write16(hMcbsp, output[k]); //右声道输出
// k=k+1; //正弦波每周期的样点为360个,输出信号的频率为Fs/N=32000/360=88.89Hz
k=k+10; //正弦波每周期的样点为36个,输出信号的频率为Fs/N=32000/36=888.9Hz
if (k>=Nx) k=k%Nx;
……………………
- n4 R3 g9 p. r s1 `' P
作者:
grand
时间:
2021-9-29 14:05
IIC模块的频率怎么设置
作者:
jspij1
时间:
2021-9-29 16:18
学习了 感谢分享
欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/)
Powered by Discuz! X3.2