|
上午调通24L01无线模块,下午写了这个DDS程序,原本就非常简单,更改了一下,使移植到msp430上更简单。
为方便各位使用,增加了一些注释,也为日后方便自己。
详细请看程序注释,改天有空把24L01无线模块也整理发上来,欢迎拍砖。
/***********************************************************************
* ADI's AD9851 DDS driver
* READ THIS FIRST:
* These functions was implemented on TI‘s msp430f5438,but donot
* limitted to it,since it can be easily ports to other msp430 MCUs
* by just modifing the macros ahead accroading to your connections.
* You should use ad9851 by calling:
* 1、Init_AD9851();
* 2、Set_DDS(phase,frequency,1/0) or Set_AD9851
* 3、reset、power up/down functions if needed ...
* My compiler is IAR for msp430 V4.11b,
* below is a demo application:
* ************************
* #include<msp430x54x.h>
* #include"ad9851.h"
* int main( void )
* {
* // Stop watchdog timer to prevent time out reset
* WDTCTL = WDTPW + WDTHOLD;
* Init_AD9851();
* while(1){
* for(unsigned char i=0;i<40;i++)
* Set_DDS(22.5,10,1);
* }
* }
* ************************
* I've tried to write this program as portable and flexible as possible,
* so you may find it's easy to pick it up.
*
* Author: ZhouQiang
* University: UESTC
* Email: zhouq3132@gmail.com
*************************************************************************/
/*****************************************
* function prototype *
******************************************/
void AD9851_RST();
void AD9851_PU();
void AD9851_PD();
void Init_AD9851();
void Set_AD9851(unsigned char cfg_byte,unsigned long freq_b);
void Set_DDS(float phase,float frequency,unsigned char is_m);
/*****************************************
* Macros needed to modify when ports
******************************************/
#include<msp430x54x.h>
#define D_PORT P8OUT
#define D_DIR P8DIR
#define D_BITS 0xFF
#define WCLK_PORT P5OUT
#define WCLK_DIR P5DIR
#define WCLK_BIT BIT6
#define FQUD_PORT P5OUT
#define FQUD_DIR P5DIR
#define FQUD_BIT BIT7
#define RST_PORT P7OUT
#define RST_DIR P7DIR
#define RST_BIT BIT3
/**************************************
* macros below is no need to *
* modify when ports to other msp430 *
***************************************/
#define Init_AD9851_Port() \
D_DIR|=D_BITS;\
WCLK_DIR|=WCLK_BIT;\
FQUD_DIR|=FQUD_BIT;\
RST_DIR|=RST_BIT
#define WCLK_HIGH WCLK_PORT|=WCLK_BIT
#define WCLK_LOW WCLK_PORT&=~WCLK_BIT
#define FQUD_HIGH FQUD_PORT|=FQUD_BIT
#define FQUD_LOW FQUD_PORT&=~FQUD_BIT
#define RST_HIGH RST_PORT|=RST_BIT
#define RST_LOW RST_PORT&=~RST_BIT
/****************************
* reset ad9851 *
*****************************/
void AD9851_RST()
{
RST_HIGH;
_NOP();
_NOP();
_NOP();
RST_LOW;
_NOP();
}
/****************************
* power up function *
*****************************/
void AD9851_PU()
{
FQUD_LOW;
D_PORT=0x00;
WCLK_HIGH;
WCLK_LOW;
FQUD_HIGH;
FQUD_LOW;
}
/****************************
* power down function *
*****************************/
void AD9851_PD()
{
FQUD_LOW;
D_PORT=0x40;
WCLK_HIGH;
WCLK_LOW;
FQUD_HIGH;
FQUD_LOW;
}
/****************************
* initialize ad9851 *
*****************************/
void Init_AD9851()
{
Init_AD9851_Port();
AD9851_RST();
WCLK_LOW;
FQUD_HIGH;
}
/***************************************************************
* setup ad9851 parameters *
*Parameters: *
*cfg_byte: control byte 0(W0) *
*freq_b: the four frequency control bytes(W1W2W3W4) *
*Return: no *
****************************************************************/
void Set_AD9851(unsigned char cfg_byte,unsigned long freq_b)
{
FQUD_LOW;
D_PORT=cfg_byte;
WCLK_HIGH;
WCLK_LOW;
for(int i=24;i>=0;i=i-8)
{
D_PORT=(unsigned char)(freq_b>>i);
WCLK_HIGH;
WCLK_LOW;
}
FQUD_HIGH;
}
/***************************************************************
* setup ad9851 parameters directly *
*function: configure ad9851 parameters easily *
*Parameters: *
*phase: float value and must be n*360/32 (n<=32) *
*freq_m: frequnecy in float value and MHZ unit *
*is_m: MHZ or HZ unit *
*Return: no *
****************************************************************/
void Set_DDS(float phase,float frequency,unsigned char is_m)
{
unsigned char ph=((unsigned char)(phase/11.25)<<3)+0x01;
unsigned long fre;
if(is_m==1)
fre=(unsigned long)(23860929.422*frequency);
else
fre=(unsigned long)(22.755556*frequency);
Set_AD9851(ph,fre);
}
/************ end *********************/ |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|