logo资料库

DDS(AD9851)驱动程序.docx

第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
资料共6页,全文预览结束
/*本驱动程序在 STM32 平台上测试通过,前面部分为头文件,后面部分为驱动主函数,如 要用在 51 平台上,只需要#define AD9851_W_FLK_H GPIO_ResetBits(GPIOB,GPIO_Pin_B)改为 相应的引脚定义即可,比如可以换为 sbit W_FLK P0^0 ; #define AD9851_W_FLK_H W_FLK=0; 引脚需做相应修改*/ #ifndef _DDS_H #define _DDS_H #define AD9851_W_FLK_H #define AD9851_W_FLK_L #define AD9851_FQ_UD_L #define AD9851_FQ_UD_H #define AD9851_RESET_L #define AD9851_RESET_H #define AD9851_Bit_Set #define AD9851_Bit_Reset GPIO_ResetBits(GPIOD,GPIO_Pin_15); GPIO_ResetBits(GPIOB,GPIO_Pin_10); GPIO_SetBits(GPIOB,GPIO_Pin_10); GPIO_SetBits(GPIOB,GPIO_Pin_11); GPIO_ResetBits(GPIOB,GPIO_Pin_11); GPIO_SetBits(GPIOB,GPIO_Pin_13); GPIO_ResetBits(GPIOB,GPIO_Pin_13); GPIO_SetBits(GPIOD,GPIO_Pin_15); void AD9851_Reset(void); void AD9851_Reset_Serial(void); void AD9851_Write_Word(unsigned char Word); void AD9851_WR_Parrel(unsigned char W0,double Frequence); void AD9851_WR_Serial(unsigned char W0,double Frequence); void Start_Frequency,double Sweep_Speed_10Ms); Sweep_Frequency(double #endif End_Frequency,unsigned int /*9851 是最较简单的 DDS,只有频率字跟相位字,将上面的头文件直接包含进工程的 main 文 件里面,就可以直接调用下面的函数体了*/ #include "DDS.h" #include extern void Delay(vu32 nCount); //---------------------------------------------------// // ad9851 复位(并口模式) //---------------------------------------------------// void AD9851_Reset(void) { AD9851_W_FLK_L; AD9851_FQ_UD_L; AD9851_RESET_L; AD9851_RESET_H; //
Delay(1); AD9851_RESET_L; Delay(1); } //***************************************************// // ad9851 复位(并口模式) // //---------------------------------------------------// void AD9851_Reset_Serial(void) { AD9851_W_FLK_L; AD9851_FQ_UD_L; AD9851_Write_Word(0X03); //rest 信号 AD9851_RESET_L; AD9851_RESET_H; Delay(1); AD9851_RESET_L; Delay(1); //w_clk 信号 AD9851_W_FLK_H; Delay(1); AD9851_W_FLK_L; //fq_up 信号 AD9851_FQ_UD_H; Delay(1); AD9851_FQ_UD_L; } __inline void AD9851_Write_Word(unsigned char Word) { u16 Port_Data; Port_Data=Word; Port_Data=Port_Data<<8; GPIO_Write(GPIOD, Port_Data); Delay(1); AD9851_W_FLK_L; AD9851_W_FLK_H; Delay(1); AD9851_W_FLK_L; } //***************************************************// // // //---------------------------------------------------// void AD9851_WR_Parrel(unsigned char W0,double Frequence) { 向 ad9851 中写命令与数据(并口)
u8 Word; u32 Frequency_Hex; double Ratio; Ratio=4294967295/180;//适合 180M 晶振 Frequence=Frequence/1000000; Frequence=Frequence*Ratio; Frequency_Hex=Frequence; //写 w0 数据 Word=W0; AD9851_Write_Word(Word); //写 w1 数据 Word=(Frequency_Hex>>24); AD9851_Write_Word(Word); //写 w2 数据 Word=(Frequency_Hex>>16); AD9851_Write_Word(Word); //写 w3 数据 Word=(Frequency_Hex>>8); AD9851_Write_Word(Word); //写 w4 数据 Word=(Frequency_Hex>>0); AD9851_Write_Word(Word); //移入始能 AD9851_FQ_UD_L; AD9851_FQ_UD_H; Delay(1); AD9851_FQ_UD_L; } //***************************************************// // // //---------------------------------------------------// void AD9851_WR_Serial(unsigned char W0,double Frequence) { 向 ad9851 中写命令与数据(串口) u8 Word; u32 Frequency_Hex; double Ratio; unsigned char i; Ratio=4294967295/180;//适合 180M 晶振 Frequence=Frequence/1000000; Frequence=Frequence*Ratio; Frequency_Hex=Frequence; //写 w4 数据
Word=(Frequency_Hex>>=0); for(i=0;i<8;i++) { if((Word>>i)&0x01) { AD9851_Bit_Set; } else { AD9851_Bit_Reset; } AD9851_W_FLK_H; Delay(1); AD9851_W_FLK_L; } //写 w3 数据 Word=(Frequency_Hex>>=8); for(i=0;i<8;i++) { if((Word>>i)&0x01) { AD9851_Bit_Set; } else { AD9851_Bit_Reset; } AD9851_W_FLK_H; Delay(1); AD9851_W_FLK_L; } //写 w2 数据 Word=(Frequency_Hex>>=16); for(i=0;i<8;i++) { if((Word>>i)&0x01) { AD9851_Bit_Set; } else { AD9851_Bit_Reset; } AD9851_W_FLK_H; Delay(1);
AD9851_W_FLK_L; } //写 w1 数据 Word=(Frequency_Hex>>=24); for(i=0;i<8;i++) { if((Word>>i)&0x01) AD9851_Bit_Set; { } else { AD9851_Bit_Reset; } AD9851_W_FLK_H; Delay(1); AD9851_W_FLK_L; } //写 w0 数据 Word=W0; for(i=0;i<8;i++) { if((Word>>i)&0x01) AD9851_Bit_Set; { } else { AD9851_Bit_Reset; } AD9851_W_FLK_H; Delay(1); AD9851_W_FLK_L; } //移入始能 AD9851_FQ_UD_H; Delay(1); AD9851_FQ_UD_L; } Sweep_Frequency(double void Sweep_Speed_10Ms) { double Frequency; Start_Frequency,double End_Frequency,unsigned int
unsigned int i; Frequency=Start_Frequency; do { AD9851_WR_Parrel(0x01,Frequency); for(i=Sweep_Speed_10Ms;i>0;i--) { Delay(10000); } Frequency=Frequency+20; } while(Frequency<=End_Frequency); }
分享到:
收藏