完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
[i][i][i][i][list]
[*]用DSP5509A与AIC23B音频芯片采集500Hz的正弦信号,为什么graph显示的频率为400多Hz?而不是500Hz,采样频率为8k。 以下是脚本: /******************************************************************************/ /*----------------------------------------------------------------------------*/ /* DESCRIPtiON: */ /* */ /* This is an example for EMIF of C5509 */ /*----------------------------------------------------------------------------*/ /* MODULE NAME... I2C and Mcbsp */ /* FILENAME...... codec.c */ /* DATE CREATED.. Mon 02/4/2004 */ /* COMPONENT..... */ /* PREREQUISITS.. */ /*----------------------------------------------------------------------------*/ /* DESCRIPTION: */ /* */ /* this example is that the codec is controled by the I2C and Mcbsp */ /*----------------------------------------------------------------------------*/ #include #include #include #include #include #include #define CODEC_ADDR 0x1A #define nx 1024 void gengxin(DATA xn[nx], DATA x) { int i = 0; for (i = nx-2; i >=0; i--){ xn[i+1] = xn[i]; } xn[0] = x; } //DATA xx[nx] = {-32768,-31744,-30720,-29696,-28672,-27648,-26624,-25600,-24576,-23552,-22528,-21504,-20480,-19456, // -18432,-17408,-16384,-15360,-14336,-13312,-12288, -11264,-10240,-9216,-8192,-7168,-6144,-5120,-4096,-3072, // -2048,-1024,0,1024,2048,3072,4096,5120,6144,7168,8192,9216,10240,11264,12288,13312,14336,15360,16384,17408, // 18432,19456,20480,21504,22528,23552,24576,25600,26624,27648,28672,29696,30720,31744}; //DATA r[nx]={0}; /*锁相环的设置*/ PLL_Config myConfig = { 0, //IAI: the PLL locks using the same process that was underway //before the idle mode was entered 1, //IOB: If the PLL indicates a break in the phase lock, //it switches to its bypass mode and restarts the PLL phase-locking //sequence 24, //PLL multiply value; multiply 24 times 1 //Divide by 2 PLL divide value; it can be either PLL divide value //(when PLL is enabled), or Bypass-mode divide value //(PLL in bypass mode, if PLL multiply value is set to 1) }; unsigned int play_mode; // 0:play 1:record and play MCBSP_Config Mcbsptest; /*McBSP set,we use mcbsp1 to send and recieve the data between DSP and AIC23*/ MCBSP_Config Mcbsp1Config = { MCBSP_SPCR1_RMK( MCBSP_SPCR1_DLB_OFF, /* DLB = 0,禁止自闭环方式 */ MCBSP_SPCR1_RJUST_LZF, /* RJUST = 2 */ MCBSP_SPCR1_CLKSTP_DISABLE, /* CLKSTP = 0 */ MCBSP_SPCR1_DXENA_ON, /* DXENA = 1 */ 0, /* ABIS = 0 */ MCBSP_SPCR1_RINTM_RRDY, /* RINTM = 0 */ 0, /* RSYNCER = 0 */ MCBSP_SPCR1_RRST_DISABLE /* RRST = 0 */ ), MCBSP_SPCR2_RMK( MCBSP_SPCR2_FREE_NO, /* FREE = 0 */ MCBSP_SPCR2_SOFT_NO, /* SOFT = 0 */ MCBSP_SPCR2_FRST_FSG, /* FRST = 0 */ MCBSP_SPCR2_GRST_CLKG, /* GRST = 0 */ MCBSP_SPCR2_XINTM_XRDY, /* XINTM = 0 */ 0, /* XSYNCER = N/A */ MCBSP_SPCR2_XRST_DISABLE /* XRST = 0 */ ), /*单数据相,接受数据长度为16位,每相2个数据*/ MCBSP_RCR1_RMK( MCBSP_RCR1_RFRLEN1_OF(1), /* RFRLEN1 = 1 */ MCBSP_RCR1_RWDLEN1_16BIT /* RWDLEN1 = 2 */ ), MCBSP_RCR2_RMK( MCBSP_RCR2_RPHASE_SINGLE, /* RPHASE = 0 */ MCBSP_RCR2_RFRLEN2_OF(0), /* RFRLEN2 = 0 */ MCBSP_RCR2_RWDLEN2_8BIT, /* RWDLEN2 = 0 */ MCBSP_RCR2_RCOMPAND_MSB, /* RCOMPAND = 0 */ MCBSP_RCR2_RFIG_YES, /* RFIG = 0 */ MCBSP_RCR2_RDATDLY_1BIT /* RDATDLY = 1 */ ), MCBSP_XCR1_RMK( MCBSP_XCR1_XFRLEN1_OF(1), /* XFRLEN1 = 1 */ MCBSP_XCR1_XWDLEN1_16BIT /* XWDLEN1 = 2 */ ), MCBSP_XCR2_RMK( MCBSP_XCR2_XPHASE_SINGLE, /* XPHASE = 0 */ MCBSP_XCR2_XFRLEN2_OF(0), /* XFRLEN2 = 0 */ MCBSP_XCR2_XWDLEN2_8BIT, /* XWDLEN2 = 0 */ MCBSP_XCR2_XCOMPAND_MSB, /* XCOMPAND = 0 */ MCBSP_XCR2_XFIG_YES, /* XFIG = 0 */ MCBSP_XCR2_XDATDLY_1BIT /* XDATDLY = 1 */ ), MCBSP_SRGR1_DEFAULT, MCBSP_SRGR2_DEFAULT, MCBSP_MCR1_DEFAULT, MCBSP_MCR2_DEFAULT, MCBSP_PCR_RMK( MCBSP_PCR_IDLEEN_RESET, /* IDLEEN = 0 */ MCBSP_PCR_XIOEN_SP, /* XIOEN = 0 */ MCBSP_PCR_RIOEN_SP, /* RIOEN = 0 */ MCBSP_PCR_FSXM_EXTERNAL, /* FSXM = 0 */ MCBSP_PCR_FSRM_EXTERNAL, /* FSRM = 0 */ 0, /* DXSTAT = N/A */ MCBSP_PCR_CLKXM_INPUT, /* CLKXM = 0 */ MCBSP_PCR_CLKRM_INPUT, /* CLKRM = 0 */ MCBSP_PCR_SCLKME_NO, /* SCLKME = 0 */ MCBSP_PCR_FSXP_ACTIVEHIGH, /* FSXP = 0 */ MCBSP_PCR_FSRP_ACTIVEHIGH, /* FSRP = 1 */ MCBSP_PCR_CLKXP_FALLING, /* CLKXP = 1 */ MCBSP_PCR_CLKRP_RISING /* CLKRP = 1 */ ), MCBSP_RCERA_DEFAULT, MCBSP_RCERB_DEFAULT, MCBSP_RCERC_DEFAULT, MCBSP_RCERD_DEFAULT, MCBSP_RCERE_DEFAULT, MCBSP_RCERF_DEFAULT, MCBSP_RCERG_DEFAULT, MCBSP_RCERH_DEFAULT, MCBSP_XCERA_DEFAULT, MCBSP_XCERB_DEFAULT, MCBSP_XCERC_DEFAULT, MCBSP_XCERD_DEFAULT, MCBSP_XCERE_DEFAULT, MCBSP_XCERF_DEFAULT, MCBSP_XCERG_DEFAULT, MCBSP_XCERH_DEFAULT }; /* This next struct shows how to use the I2C API */ /* Create and initialize an I2C initialization structure */ I2C_Setup I2Cinit = { 0, /* 7 bit address mode */ 0, /* own address - don't care if master */ 84, /* clkout value (Mhz) */ 50, /* a number between 10 and 400*/ 0, /* number of bits/byte to be received or transmitted (8)*/ 0, /* DLB mode on*/ 1 /* FREE mode of operation on*/ }; I2C_Config testI2C; /*数字音频接口格式设置 AIC23为主模式,数据为DSP模式,数据长度16位*/ Uint16 digital_audio_inteface_format[2]={0x0e,0x53}; /*AIC23的波特率设置,采样率为8K*/ Uint16 sample_rate_control[2] = {0x10,0x22}; /*AIC23寄存器复位*/ Uint16 reset[2] ={0x1e,0x00}; /*AIC23节电方式设置,所有部分均所与工作状态*/ Uint16 power_down_control[2] ={0x0c,0x00}; /*AIC23模拟音频的控制 DAC使能,ADC输入选择为Line,mic输入,增益为0*/ Uint16 analog_aduio_path_control[2] ={0x08,0x1c}; /*AIC23数字音频通路的控制*/ Uint16 digital_audio_path_control[2] ={0x0a,0x05}; /*AIC23数字接口的使能*/ Uint16 digital_interface_activation[2] ={0x12,0x01}; /*AIC23左通路音频调节*/ Uint16 left_line_input_volume_control[2] ={0x00,0x17}; /*AIC23右通路音频调节*/ Uint16 right_line_input_volume_control[2] ={0x02,0x17}; /*AIC23耳机左通路音频调节*/ Uint16 left_headphone_volume_control[2] ={0x05,0xFF}; /*AIC23耳机右通路音频调节*/ Uint16 right_headphone_volume_control[2] = {0x07,0xFF}; /*定义McBSP的句柄*/ MCBSP_Handle hMcbsp; Uint16 i2c_status; Uint16 i,temp; DATA aic23data = 0; DATA aic23data1[nx] = {0}; DATA aic23data2[nx] = {0}; void delay(Uint32 k) { while(k--); } void main(void) { i2c_status = 1; /* Initialize CSL library - This is REQUIRED !!! */ /*初始化CSL库*/ CSL_init(); /*设置系统的运行速度为140MHz*/ PLL_config(&myConfig); /* Initialize I2C, using parameters in init structure */ /*初始化I2C的格式*/ // I2C_config(&Config); // I2C_start(); // I2C_getConfig(&Config1); /*I2C is undet reset*/ I2C_RSET(I2CMDR,0); /*设置预分频寄存器,I2C的mode clock is 10MHz*/ delay(100); I2C_RSET(I2CSAR,0x001A); I2C_RSET(I2CMDR,0x0620); I2C_setup(&I2Cinit); /*设置I2C的Mater clock*/ I2C_RSET(I2CCLKL,100); I2C_RSET(I2CCLKH,100); I2C_getConfig(&testI2C); /*初始化McBSP0*/ hMcbsp = MCBSP_open(MCBSP_PORT1,MCBSP_OPEN_RESET); /*设置McBSP0*/ MCBSP_config(hMcbsp,&Mcbsp1Config); /*启动McBSP0*/ MCBSP_start(hMcbsp, MCBSP_RCV_START | MCBSP_XMIT_START, 0); MCBSP_getConfig(hMcbsp,&Mcbsptest); /*reset AIC23*/ i2c_status = I2C_write( reset, //pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); delay(1000); /*设置AIC23各部分均工作*/ i2c_status = I2C_write( power_down_control,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); /*设置AIC23的数字接口*/ i2c_status = I2C_write( digital_audio_inteface_format,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); /*设置AIC23模拟通路*/ i2c_status = I2C_write( analog_aduio_path_control,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); /*设置数字通路*/ i2c_status = I2C_write( digital_audio_path_control,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); /*设置AIC23的采样率*/ i2c_status = I2C_write( sample_rate_control,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); /*设置耳机音量*/ i2c_status = I2C_write( left_headphone_volume_control,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); i2c_status = I2C_write( right_headphone_volume_control,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); /*设置Line输入的音量*/ i2c_status = I2C_write( left_line_input_volume_control,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); i2c_status = I2C_write( right_line_input_volume_control,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); /*启动AIC23*/ i2c_status = I2C_write( digital_interface_activation,//pointer to data array 2, //length of data to be transmitted 1, //master or slaver CODEC_ADDR, //slave address to transmit to 1, //transfer mode of operation 30000 //time out for bus busy ); /*回放音频*/ // int i = 0; // while(i<102400) while(TRUE) { //sine(xx,r,nx); // for (i=0;i<1024;i++){ while(!MCBSP_xrdy(hMcbsp)){}; aic23data = MCBSP_read16(hMcbsp); gengxin(aic23data1,aic23data); // gengxin(aic23data2,aic23data); // rfft(aic23data1,nx, SCALE); //for(temp=3000;temp>0;temp--); // delay(350); while(!MCBSP_rrdy(hMcbsp)){}; MCBSP_write16(hMcbsp,aic23data); // for (i=0;i |
|
相关推荐
2个回答
|
|
|
|
|
|
根据您提供的信息,您正在使用DSP5509A和AIC23B音频芯片来采集500Hz的正弦信号,但是Graph显示的频率为400多Hz。采样频率为8k。以下是可能的原因:
1. 采样频率不足:采样定理(Nyquist定理)指出,为了准确重建信号,采样频率至少应该是信号最高频率的两倍。在这种情况下,500Hz的信号需要至少1000Hz的采样频率。然而,您使用的采样频率为8k,这可能不足以准确捕捉信号的所有细节。这可能导致信号的混叠现象,从而影响频率的准确测量。 2. 滤波器设置不正确:在采集信号时,通常需要使用低通滤波器来去除高于奈奎斯特频率的信号分量。如果滤波器设置不正确,可能导致信号失真,从而影响频率的准确测量。 3. 信号处理算法问题:在信号处理过程中,可能存在算法错误或实现问题,导致频率测量不准确。例如,FFT(快速傅里叶变换)算法可能没有正确实现,或者窗口函数选择不当,导致频率测量误差。 4. Graph显示问题:Graph显示的频率可能受到显示设置或分辨率的影响,导致显示的频率与实际频率不符。检查Graph的设置,确保其正确显示频率信息。 为了解决这个问题,您可以尝试以下方法: 1. 增加采样频率:将采样频率提高到至少16k,以满足采样定理的要求。 2. 检查滤波器设置:确保低通滤波器正确设置,以去除高于奈奎斯特频率的信号分量。 3. 检查信号处理算法:检查FFT算法的实现,确保其正确执行。同时,选择合适的窗口函数,以减少频率测量误差。 4. 检查Graph显示设置:检查Graph的设置,确保其正确显示频率信息。 通过以上方法,您应该能够更准确地测量和显示500Hz的正弦信号频率。 |
|
|
|
只有小组成员才能发言,加入小组>>
341 浏览 1 评论
539 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
781 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
655 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1138 浏览 1 评论
AT32F407在USART2 DMA发送数据时,接包接到了要发送的数据,程序还是处于等待传输完成的标识判断中,为什么?
69浏览 29评论
216浏览 23评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
257浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
205浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
65浏览 13评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 12:42 , Processed in 1.043096 second(s), Total 84, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号