|
ad9851输出的频率一直是30.12M,求做过的大神帮忙看一下,我是第一次搞这个。
[复制链接]
3芯积分
本帖最后由 paulhyde 于 2014-9-15 03:15 编辑
void Delay(vu32 us)
{
unsigned char uscnt;
uscnt=us>>1;
while(--uscnt);
}
void AD9851_GPIOC_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
void AD9851_GPIOD_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOD,&GPIO_InitStructure);
}
//---------------------------------------------------//
// 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);
//rese
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_ud
AD9851_FQ_UD_H;
Delay(1);
AD9851_FQ_UD_L;
}
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;
}
//***************************************************//
// ad9851并行 写 //
//---------------------------------------------------//
void AD9851_WR_Parrel(unsigned char W0,double Frequence)
{
u8 Word;
u32 Frequency_Hex;
double Ratio;
//Frequence=Frequence*180000000/4294967296;
Ratio=4294967295/180
Frequence=Frequence/1000000;
Frequence=Frequence*Ratio;
Frequency_Hex=Frequence;
Word=W0;
AD9851_Write_Word(Word);
Word=(Frequency_Hex>>24);
AD9851_Write_Word(Word);
Word=(Frequency_Hex>>16);
AD9851_Write_Word(Word);
Word=(Frequency_Hex>>8);
AD9851_Write_Word(Word);
Word=(Frequency_Hex>>0);
AD9851_Write_Word(Word);
AD9851_FQ_UD_L;
AD9851_FQ_UD_H;
Delay(1);
AD9851_FQ_UD_L;
}
//***************************************************//
// ad9851串行 写 //
//---------------------------------------------------//
void AD9851_WR_Serial(unsigned char W0,double Frequence)
{
u8 Word;
u32 Frequency_Hex;
//double Ratio;
unsigned char i;
Frequence=Frequence*180000000/4294967296;
// Ratio=4294967295/180
// Frequence=Frequence/1000000;
// Frequence=Frequence*Ratio;
Frequency_Hex=Frequence;
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;
}
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;
}
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;
}
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;
}
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;
}
void Sweep_Frequency(double Start_Frequency,double End_Frequency,unsigned int Sweep_Speed_10Ms)
{
double Frequency;
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);
}
int main(void)
{
AD9851_GPIOD_Configuration();
AD9851_GPIOC_Configuration();
AD9851_Reset_Serial();
//AD9851_Reset();
GPIO_Write(GPIOC,0x0000);
GPIO_Write(GPIOD,0x0000);
// AD9851_WR_Parrel(0x02,1);
AD9851_WR_Serial(0x01,1);
//AD9851_WR_Parrel(0x11,100);
while(1);
}
/******************AD9851.H**************/
#define AD9851_W_FLK_H GPIO_ResetBits(GPIOB,GPIO_Pin_6);
#define AD9851_W_FLK_L GPIO_SetBits(GPIOB,GPIO_Pin_6);
//?μ?ê?üD?????D?o?£?é?éy??è·è?óDD§
#define AD9851_FQ_UD_L GPIO_SetBits(GPIOB,GPIO_Pin_7);
#define AD9851_FQ_UD_H GPIO_ResetBits(GPIOB,GPIO_Pin_7);
//?′????£?0
#define AD9851_RESET_L GPIO_SetBits(GPIOB,GPIO_Pin_8);
#define AD9851_RESET_H GPIO_ResetBits(GPIOB,GPIO_Pin_8);
//′?DDê?è???£?D7
#define AD9851_Bit_Set GPIO_SetBits(GPIOD,GPIO_Pin_14);
#define AD9851_Bit_Reset GPIO_ResetBits(GPIOD,GPIO_Pin_14);
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 Sweep_Frequency(double Start_Frequency,double End_Frequency,unsigned int Sweep_Speed_10Ms);
void AD9851_GPIOC_Configuration(void);
void AD9851_GPIOD_Configuration(void);
|
|