hadiabdi
10-09-2011, 14:30
سلام دوستان براي هر جووني مثل ماها يك سيگنال ژنراتور تو محيط كارگاه لازمه منم به اين فكر افتادم كه اين ايسي رو درايو كنم وقعا اين ايسي فوق العاده است باورتون نميشه چقدر عالي كار ميده تو هر رنج فركاسي از 1. هرتز تا 12.5 مگا هرتز جواب ميده مدل هاي بلاترش تا 40 مگه اميدوارم لذتش رو ببريد نوع شكل موج هايي رو كه با ايسي خودم گرفتم براتون ميزارم تا خيالتون از اين اي سي راحت بشه موفق مويد باشيد التماس دعا
#include "main.h"
#include <stdio.h>
#include <math.h>
#include <LCD.h>
#ZERO_RAM
#use spi(DI=PIN_C0, DO=PIN_D0, CLK=PIN_D1, BITS=16,CLOCK_LOW=150,IDLE=1)
#define FSYNC PIN_C3
#define RESEt_AD9833 0x0100 //0000 0001 0000 0000
#define Sinusoid_0 0x0000 //0000 0000 0000 0000
#define Sinusoid_1 0x0800 //0000 1000 0000 0000
#define Triangle_0 0x0002 //0000 0000 0000 0010
#define Triangle_1 0x0802 //0000 1000 0000 0010
#define square_0_MSB_d_2 0x0020 //0000 0000 0010 0000
#define square_1_MSB_d_2 0x0820 //0000 1000 0010 0000
#define square_0 0x0028 //0000 0000 0010 1000
#define square_1 0x0828 //0000 1000 0010 1000
#define frequency_0 0
#define frequency_1 1
//************************************************** **********
void init_FREQ0_AD9833();
void init_FREQ1_AD9833();
void write_command_AD9833(int16 c_o_m);
void load_FREQ_AD9833(float fe,int1 cs);
//************************************************** **********
void main()
{
port_b_pullups(TRUE);
setup_timer_0(RTCC_INTERNAL);
setup_oscillator(OSC_NORMAL);
cls();
delay_ms(100);
init_FREQ0_AD9833();
delay_ms(5000);
write_command_AD9833(Triangle_0);
delay_ms(5000);
write_command_AD9833(square_0);
delay_ms(5000);
write_command_AD9833(Sinusoid_0);
delay_ms(5000);
load_FREQ_AD9833(200.0,frequency_0);
while(TRUE);
}
//************************************************** **************
void init_FREQ0_AD9833(){
output_low (FSYNC);
spi_xfer(0x2100);// 0010 0001 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x4230);// 01 00 0010 0011 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x4000);// 01 00 0000 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0xC000);// 1100 0000 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x0000);// 0000 0000 0000 0000
output_high(FSYNC);
}
//************************************************** *
void init_FREQ1_AD9833(){
output_low (FSYNC);
spi_xfer(0x2900);// 0010 1001 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x8230);// 10 00 0010 0011 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x8000);// 10 00 0000 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0xC000);// 1100 0000 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x0800);// 0000 1000 0000 0000
output_high(FSYNC);
}
//************************************************** ******
void write_command_AD9833(int16 c_o_m){
output_low (FSYNC);
spi_xfer(c_o_m);
output_high(FSYNC);
}
//************************************************** ******
void load_FREQ_AD9833(float fe,int1 cs){
float32 res;
int32 res_f;
int16 l_b=0,m_b=0,LSB=0,MSB=0;
int8 i=0;
int1 te_0[28];
res=((fe*pow (2,28.0))/24E+6);
res = floor (res);
res_f=res;
while(i<14){
te_0[i]=bit_test(res_f,i);
i++;
}
while(i<28){
te_0[i]=bit_test(res_f,i);
i++;
}
i=0;
while(i<14){
if(te_0[i]==1) bit_set(l_b,i);
i++;
}
while(i<28){
if(te_0[i]==1) bit_set(m_b,i-14);
i++;
}
if(cs==0){
LSB=0x4000;
MSB=0x4000;
LSB|=l_b;
MSB|=m_b;
write_command_AD9833(0x2100);
write_command_AD9833(LSB);
write_command_AD9833(MSB);
write_command_AD9833(0xC000);
write_command_AD9833(0x0000);
}
if(cs==1){
LSB=0x8000;
MSB=0x8000;
LSB|=l_b;
MSB|=m_b;
write_command_AD9833(0x2900);
write_command_AD9833(LSB);
write_command_AD9833(MSB);
write_command_AD9833(0x0800);
}
}
#include "main.h"
#include <stdio.h>
#include <math.h>
#include <LCD.h>
#ZERO_RAM
#use spi(DI=PIN_C0, DO=PIN_D0, CLK=PIN_D1, BITS=16,CLOCK_LOW=150,IDLE=1)
#define FSYNC PIN_C3
#define RESEt_AD9833 0x0100 //0000 0001 0000 0000
#define Sinusoid_0 0x0000 //0000 0000 0000 0000
#define Sinusoid_1 0x0800 //0000 1000 0000 0000
#define Triangle_0 0x0002 //0000 0000 0000 0010
#define Triangle_1 0x0802 //0000 1000 0000 0010
#define square_0_MSB_d_2 0x0020 //0000 0000 0010 0000
#define square_1_MSB_d_2 0x0820 //0000 1000 0010 0000
#define square_0 0x0028 //0000 0000 0010 1000
#define square_1 0x0828 //0000 1000 0010 1000
#define frequency_0 0
#define frequency_1 1
//************************************************** **********
void init_FREQ0_AD9833();
void init_FREQ1_AD9833();
void write_command_AD9833(int16 c_o_m);
void load_FREQ_AD9833(float fe,int1 cs);
//************************************************** **********
void main()
{
port_b_pullups(TRUE);
setup_timer_0(RTCC_INTERNAL);
setup_oscillator(OSC_NORMAL);
cls();
delay_ms(100);
init_FREQ0_AD9833();
delay_ms(5000);
write_command_AD9833(Triangle_0);
delay_ms(5000);
write_command_AD9833(square_0);
delay_ms(5000);
write_command_AD9833(Sinusoid_0);
delay_ms(5000);
load_FREQ_AD9833(200.0,frequency_0);
while(TRUE);
}
//************************************************** **************
void init_FREQ0_AD9833(){
output_low (FSYNC);
spi_xfer(0x2100);// 0010 0001 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x4230);// 01 00 0010 0011 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x4000);// 01 00 0000 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0xC000);// 1100 0000 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x0000);// 0000 0000 0000 0000
output_high(FSYNC);
}
//************************************************** *
void init_FREQ1_AD9833(){
output_low (FSYNC);
spi_xfer(0x2900);// 0010 1001 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x8230);// 10 00 0010 0011 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x8000);// 10 00 0000 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0xC000);// 1100 0000 0000 0000
output_high(FSYNC);
output_low (FSYNC);
spi_xfer(0x0800);// 0000 1000 0000 0000
output_high(FSYNC);
}
//************************************************** ******
void write_command_AD9833(int16 c_o_m){
output_low (FSYNC);
spi_xfer(c_o_m);
output_high(FSYNC);
}
//************************************************** ******
void load_FREQ_AD9833(float fe,int1 cs){
float32 res;
int32 res_f;
int16 l_b=0,m_b=0,LSB=0,MSB=0;
int8 i=0;
int1 te_0[28];
res=((fe*pow (2,28.0))/24E+6);
res = floor (res);
res_f=res;
while(i<14){
te_0[i]=bit_test(res_f,i);
i++;
}
while(i<28){
te_0[i]=bit_test(res_f,i);
i++;
}
i=0;
while(i<14){
if(te_0[i]==1) bit_set(l_b,i);
i++;
}
while(i<28){
if(te_0[i]==1) bit_set(m_b,i-14);
i++;
}
if(cs==0){
LSB=0x4000;
MSB=0x4000;
LSB|=l_b;
MSB|=m_b;
write_command_AD9833(0x2100);
write_command_AD9833(LSB);
write_command_AD9833(MSB);
write_command_AD9833(0xC000);
write_command_AD9833(0x0000);
}
if(cs==1){
LSB=0x8000;
MSB=0x8000;
LSB|=l_b;
MSB|=m_b;
write_command_AD9833(0x2900);
write_command_AD9833(LSB);
write_command_AD9833(MSB);
write_command_AD9833(0x0800);
}
}