DSP

DSP TMS320C5509A之DAC8164

2019-07-13 14:51发布

DAC8164,16位四通道SPI接口DAC,发热量较大,不推荐使用,程序如下: #include #include #include "IncDAC.h" void SENDtoAUDIO_DAC(Uint16 Value); void IniDAC8164D(void); void SendToDAC8164(Uint16 DAC_PORTX,Uint16 Value); MCBSP_Handle hDAC8164,hAudioDAC; /* */ MCBSP_Config DAC8164_Mcbsp2= { MCBSP_SPCR1_RMK( MCBSP_SPCR1_DLB_OFF, MCBSP_SPCR1_RJUST_RZF, MCBSP_SPCR1_CLKSTP_NODELAY,//MCBSP_SPCR1_CLKSTP_DELAY MCBSP_SPCR1_DXENA_NA, MCBSP_SPCR1_ABIS_DISABLE, MCBSP_SPCR1_RINTM_RRDY, 0, MCBSP_SPCR1_RRST_DISABLE ), MCBSP_SPCR2_RMK( MCBSP_SPCR2_FREE_NO, MCBSP_SPCR2_SOFT_NO, MCBSP_SPCR2_FRST_RESET, MCBSP_SPCR2_GRST_RESET, MCBSP_SPCR2_XINTM_XRDY, 0, MCBSP_SPCR2_XRST_DISABLE ), MCBSP_RCR1_RMK( MCBSP_RCR1_RFRLEN1_OF(0), MCBSP_RCR1_RWDLEN1_24BIT ), MCBSP_RCR2_RMK( MCBSP_RCR2_RPHASE_SINGLE, MCBSP_RCR2_RFRLEN2_OF(0), MCBSP_RCR2_RWDLEN2_8BIT, MCBSP_RCR2_RCOMPAND_MSB, MCBSP_RCR2_RFIG_YES, MCBSP_RCR2_RDATDLY_1BIT ), MCBSP_XCR1_RMK( MCBSP_XCR1_XFRLEN1_OF(0), MCBSP_RCR1_RWDLEN1_24BIT ), MCBSP_XCR2_RMK( MCBSP_XCR2_XPHASE_SINGLE, MCBSP_XCR2_XFRLEN2_OF(0), MCBSP_XCR2_XWDLEN2_8BIT, MCBSP_XCR2_XCOMPAND_MSB, MCBSP_XCR2_XFIG_YES, MCBSP_XCR2_XDATDLY_1BIT ), MCBSP_SRGR1_RMK( MCBSP_SRGR1_FWID_OF(1), MCBSP_SRGR1_CLKGDV_OF(1) //200M/(CLKGDV+1) = 200/(1+1) = 100M ), MCBSP_SRGR2_RMK( MCBSP_SRGR2_GSYNC_FREE, MCBSP_SRGR2_CLKSP_RISING, MCBSP_SRGR2_CLKSM_INTERNAL, MCBSP_SRGR2_FSGM_DXR2XSR, MCBSP_SRGR2_FPER_OF(15) ), MCBSP_MCR1_DEFAULT, MCBSP_MCR2_DEFAULT, MCBSP_PCR_RMK( 0, //IDLEEN = 0 MCBSP_PCR_XIOEN_SP, MCBSP_PCR_RIOEN_SP, MCBSP_PCR_FSXM_INTERNAL, MCBSP_PCR_FSRM_EXTERNAL, MCBSP_PCR_CLKXM_OUTPUT, MCBSP_PCR_CLKRM_INPUT, MCBSP_PCR_SCLKME_NO, 0, MCBSP_PCR_FSXP_ACTIVELOW, MCBSP_PCR_FSRP_ACTIVEHIGH, MCBSP_PCR_CLKXP_RISING, MCBSP_PCR_CLKRP_FALLING ), 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 }; MCBSP_Config Audio_Mcbsp1= { MCBSP_SPCR1_RMK( MCBSP_SPCR1_DLB_OFF, MCBSP_SPCR1_RJUST_RZF, MCBSP_SPCR1_CLKSTP_DELAY, //MCBSP_SPCR1_CLKSTP_DISABLE MCBSP_SPCR1_DXENA_NA, MCBSP_SPCR1_ABIS_DISABLE, MCBSP_SPCR1_RINTM_RRDY, 0, MCBSP_SPCR1_RRST_DISABLE ), MCBSP_SPCR2_RMK( MCBSP_SPCR2_FREE_NO, MCBSP_SPCR2_SOFT_NO, MCBSP_SPCR2_FRST_RESET, MCBSP_SPCR2_GRST_RESET, MCBSP_SPCR2_XINTM_XRDY, 0, MCBSP_SPCR2_XRST_DISABLE ), MCBSP_RCR1_RMK( MCBSP_RCR1_RFRLEN1_OF(0), MCBSP_RCR1_RWDLEN1_16BIT ), MCBSP_RCR2_RMK( MCBSP_RCR2_RPHASE_SINGLE, MCBSP_RCR2_RFRLEN2_OF(0), MCBSP_RCR2_RWDLEN2_8BIT, MCBSP_RCR2_RCOMPAND_MSB, MCBSP_RCR2_RFIG_YES, MCBSP_RCR2_RDATDLY_1BIT ), MCBSP_XCR1_RMK( MCBSP_XCR1_XFRLEN1_OF(0), MCBSP_XCR1_XWDLEN1_16BIT ), MCBSP_XCR2_RMK( MCBSP_XCR2_XPHASE_SINGLE, MCBSP_XCR2_XFRLEN2_OF(0), MCBSP_XCR2_XWDLEN2_8BIT, MCBSP_XCR2_XCOMPAND_MSB, MCBSP_XCR2_XFIG_YES, MCBSP_XCR2_XDATDLY_1BIT ), MCBSP_SRGR1_RMK( MCBSP_SRGR1_FWID_OF(1), MCBSP_SRGR1_CLKGDV_OF(1) ), MCBSP_SRGR2_RMK( MCBSP_SRGR2_GSYNC_FREE, MCBSP_SRGR2_CLKSP_RISING, MCBSP_SRGR2_CLKSM_INTERNAL, MCBSP_SRGR2_FSGM_DXR2XSR, MCBSP_SRGR2_FPER_OF(15) ), MCBSP_MCR1_DEFAULT, MCBSP_MCR2_DEFAULT, MCBSP_PCR_RMK( 0, //IDLEEN = 0 MCBSP_PCR_XIOEN_SP, MCBSP_PCR_RIOEN_SP, MCBSP_PCR_FSXM_INTERNAL, MCBSP_PCR_FSRM_EXTERNAL, MCBSP_PCR_CLKXM_OUTPUT, MCBSP_PCR_CLKRM_INPUT, MCBSP_PCR_SCLKME_NO, 0, MCBSP_PCR_FSXP_ACTIVELOW, MCBSP_PCR_FSRP_ACTIVEHIGH, MCBSP_PCR_CLKXP_RISING, MCBSP_PCR_CLKRP_FALLING ), 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 }; void IniDAC8164D(void) { //初始化DSP的相关寄存器 hDAC8164=MCBSP_open(MCBSP_PORT2,MCBSP_OPEN_RESET); /*设置McBSP1*/ MCBSP_config(hDAC8164,&DAC8164_Mcbsp2); MCBSP_start(hDAC8164, MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, 0x300); MCBSP_start(hDAC8164, MCBSP_XMIT_START, 0); } /* TMS320VC5501/5502/5509/5510 DSP */ /* Multichannel Buffered Serial Port (McBSP) */ /* Reference Guide */ void IniAudioDAC(void) { //初始化DSP的相关寄存器 hAudioDAC=MCBSP_open(MCBSP_PORT1,MCBSP_OPEN_RESET); /*设置McBSP1*/ MCBSP_config(hAudioDAC,&Audio_Mcbsp1); /*启动McBSP1*/ //MCBSP_write16(hMcbsp1,0); //发送数据 MCBSP_start(hAudioDAC, MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, 0x300); MCBSP_start(hAudioDAC, MCBSP_XMIT_START, 0); } void SendToDAC8164(Uint16 DAC_PORTX,Uint16 Value) { Uint32 output = 0; output = DAC_PORTX; output = ((output<<17)|(Value<<2)); while(0==MCBSP_xrdy(hDAC8164)); //1 = ready MCBSP_write32(hDAC8164,output); //发送数据 } void SendToIF(Uint32 Value) { while(0==MCBSP_xrdy(hDAC8164)); //1 = ready MCBSP_write32(hDAC8164,Value); //发送数据 } /**/ /* * FUNCTION: SENDtoAUDIO_DAC * * PARAMETERS: Value:输出的电压值 Gain:输出的增益系数,Q7 * * DESCRIPTION:发送数据到DAC,最终发送的数据是 * * RETURNS: * void SENDtoAUDIO_DAC(Uint16 Value) { //Value += 32768; //Value *= 10; while(0==MCBSP_xrdy(hMcbsp1)); //1 = ready MCBSP_write16(hMcbsp1,Value); //发送数据 }*/ 头文件如下: #include #include #ifndef __DAC_H__ #define __DAC_H__ #define DAC_PORTA 0x00 #define DAC_PORTB 0x01 #define DAC_PORTC 0x02 #define DAC_PORTD 0x03 #define DAC_MAX_OUT 8200 extern void IniADC(void); extern void IniDAC8164D(void); /* TMS320VC5501/5502/5509/5510 DSP */ /* Multichannel Buffered Serial Port (McBSP) */ /* Reference Guide */ extern void IniAudioDAC(void); extern void SendToDAC8164(Uint16 DAC_PORTX,Uint16 Value); extern void SendToIF(Uint32 Value); /* * FUNCTION: SENDtoAUDIO_DAC * * PARAMETERS: Value:输出的电压值 Gain:输出的增益系数,Q7 * * DESCRIPTION:发送数据到DAC,最终发送的数据是 * * RETURNS: * */ extern void SENDtoAUDIO_DAC(Uint16 Value); #endif