DDS,即数字直接合成,产生各种波形。DDS芯片有很多,比较常用的是AD公司的AD9833。
电路如下:
其中:
FCS 片选信号
SCLK 数据传输时钟
SDA 数据线
MCLK 芯片主频,接一个25M的晶振模块
控制程序如下:
环境:
Keil C 8.02
C8051F020 @ 20M
//代码
sbit FCS1 = P3^1;
sbit SCL = P3^4;
sbit SDA = P3^5;
#define B28 0x2000 //complete word or two seperate byte
#define HLB 0x1000 //H/L Byte sequience input
#define FSEL 0x0800 //Freq0 or Freq1
#define PSEL 0x0400 //Phase0 or Phase1
#define REST 0x0100 //1: Reset
#define SLP1 0x0080 //1: Internal MCLK Disable
#define SLP2 0x0040 //1: PowerDown Onchip DAC
#define OPBITEN 0x0020 //VOUT connect to MSB/2
#define DIV2 0x0004 //when opbiten,
#define MODE 0x0002 //
#define ASTR 0x0000
#define AFREQ0 0x4000
#define AFREQ1 0x8000
#define APHS0 0xD000
#define APHS1 0xF000
void spi_delay(unsigned int n)
{
unsigned int i,j = n*10;
for(i=0; i<j; i++){_nop_();};
}
void spi_initialize()
{
unsigned char i,j;
WDTCN = 0xDE;
WDTCN = 0xAD;
XBR0 = 0x05;
XBR2 = 0x40;
P3MDOUT = 0xFF;
P3 = 0xFF;
return;
}
void spi_sendword(unsigned int wData)
{
unsigned int bitTest=wData;
unsigned char i;
SCL = 1;
SDA = 1;
FCS1 = 1;
spi_delay(10);
FCS1 = 0;
spi_delay(5);
for(i=0; i<16; i++)
{
if((bitTest & 0x8000))
{
SDA = 1;
}
else
{
SDA = 0;
}
SCL = 0;
spi_delay(5);
SCL = 1;
spi_delay(4);
bitTest <<= 1;
}
spi_delay(2);
FCS1 = 1;
spi_delay(2);
SCL = 1;
return;
}
void main()
{
unsigned int a,b;
spi_initialize();
//初始化,所有寄存器清零
spi_sendword(ASTR | B28 | REST);
spi_sendword(AFREQ0 | 0);
spi_sendword(AFREQ0 | 0);
spi_sendword(ASTR | B28 |REST | FSEL);
spi_sendword(AFREQ1 | 0);
spi_sendword(AFREQ1 | 0);
spi_sendword(APHS0 | 0);
spi_sendword(APHS1 | 0);
//产生正弦波;先写指令寄存器,后写频率寄存器;高14位在前,低14位在后
spi_sendword(ASTR | B28);
spi_sendword(AFREQ0 | 0x49B); //200k sine wave
spi_sendword(AFREQ0 | 0x83);
while(1)
{
_nop_();
}
}
用户85560 2009-7-14 13:10
用户85560 2009-7-14 13:07
用户150704 2009-6-23 22:42
用户1406757 2009-6-11 18:34