Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

sine wave genrator using ad9833 with 89c52

Status
Not open for further replies.

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
hi i want to generate sine wave of 100khz using 89c52 with ad9833 i wrote code for it but its not working any one help me i am geting .31offset voltage at output of ad9833 here is my code....



#include <reg51.h>
sbit dds_en=P3^2; //it spi pin fsync or chip select
sbit dds_clk=P3^1; // it is input clk for ad9833
sbit dds_dat=P3^0; //ad9833 data pin
unsigned char control;
void delay(unsigned int i)
{
while(i)
{
i--;
}
}
void write_data(unsigned int a) //write 2 byte to dds

{
unsigned char i;
dds_clk=1; //set all control pin high for initalization
dds_dat=1;
dds_en=1;
control=0;
delay(1000);
dds_clk=1;
delay(2);
dds_en=0;
for(i=0;i<16;i++) //take 16 bit data to write
{
if(a&0x8000)
{
dds_dat=1;
}
else dds_dat=0;
dds_clk=0;
delay(5);
dds_clk=1;
a=a<<1;
}
delay(2);
dds_en=1;
dds_clk=0;
delay(1000);
control=1;
}

void init_dds(void)
{
write_data(0x2100); //to wite
write_data(0x2000); //reset ad9833
write_data(0x400B); //ferq0 reg msb value
write_data(0x4000); // ferq0 reg lsb value
write_data(0x800B);
write_data(0x8000);
write_data(0xC000); //phase0 reg
write_data(0xE000); // phase1 reg
write_data(0x2000); // reset ad9833
}
void output(unsigned long freq_value)
{
unsigned long dds;
unsigned int dds1,dds2;
dds=freq_value*10;//set output freuency0 reg equetion
dds=dds<<2; //shift that 2 bit
dds1=dds; //save that data
dds2=dds>>16; //shift dds value 16 data
dds1=dds1>>2; //take 2 controlbit
dds2=dds2&0x7FFF; //mask all bits
dds2=dds2|0x4000; //
dds1=dds1&0x7FFF;
dds1=dds1|0x4000;
write_data(0x2000);
write_data(dds1);
write_data(dds2);
}



void main()
{
//
init_dds();
output(1) ;





}
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
hi pls Any one suggest me how to modified in my code plsss need help its urgent
pls guys need help and ideas from u fast
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
hi any buddy hav working code for sine wave genrator
pls help me in this code pls
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
hi i am getting sine wave but its frequency doesn't change can any one have working code for ad9833 for 89s52.. please need help imadiatly
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top