|
|
View previous topic :: View next topic |
Author |
Message |
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
DDS AD9835 |
Posted: Sat Aug 07, 2004 8:59 pm |
|
|
I found code for ad9850 at lpt port
Does anybody can help me write code for AD9835 for PIC or LPT.
(better PIC)/
Code: |
/* dds2.c - program to configure AD8750 via the PC printer port */
/*
** Port bit 0 - DATA
** Port bit 1 - W_CLK
** Port bit 2 - FQ_UD
** Port bit 3 - RESET
*/
#include <stdio.h>
#include <PC.H>
#include <math.h>
#define PORT 0x378
main()
{
int i;
float clock_in;
float F_out;
unsigned int delta_phase;
/* set all pins low */
outportb(PORT, 0x00);
/* get clock frequency from user */
printf("Clock frequency? ");
scanf("%f", &clock_in);
/* main program loop */
for (;;)
{
/* get output frequency from user, abort if -ve */
printf("\n\nOutput frequency? ");
scanf("%f", &F_out);
if (F_out < 0.0)
exit(0);
/* calculate AD9850 32-bit tuning word */
delta_phase = (F_out * pow(2, 32)) / clock_in;
/* output bit stream to AD9850 */
tuning_word_out(delta_phase);
/* output control byte */
byte_out(0x00);
/* latch frequency data - pulse FQ_UD high */
outportb(PORT, 0x04);
outportb(PORT, 0x00);
}
}
/* output byte, MSB first */
byte_out(byte)
unsigned char byte;
{
int i;
for (i = 0; i < 8; i++)
{
if ((byte & 1) == 1)
one();
else
zero();
byte = byte >> 1;
}
}
/* output 32-bit tuning word, MSB first */
tuning_word_out(tuning_word)
unsigned int tuning_word;
{
int i;
for (i = 0; i < 32; i++)
{
if ((tuning_word & 1) == 1)
one();
else
zero();
tuning_word = tuning_word >> 1;
}
}
/* output a '1' to AD9850 */
one()
{
outportb(PORT, 1);/* CLOCK low and DATA high - 01 */
outportb(PORT, 3);/* CLOCK and DATA high - 11 */
outportb(PORT, 0);/* CLOCK low and DATA low - 00 */
}
/* output a '0' to AD9850 */
zero()
{
outportb(PORT, 0);/* CLOCK low and DATA low - 00 */
outportb(PORT, 2);/* CLOCK high and DATA low - 10 */
outportb(PORT, 0);/* CLOCK low and DATA low - 00 */
}
|
from:
Leon's home page: http://www.geocities/SiliconValley/Code/1835/index.html |
|
|
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Sun Aug 08, 2004 6:42 am |
|
|
Hi
I have written routines for the AD9834 DDS because these devices are very similar (but not the same), the AD9834 uses a 28 bit freq register versus the 32 bit for the AD9835 You will have to modify my routines to suit your needs.
+++++++++++++++++++++++++++++++++++++++++++++++
//**********************************************
//* Driver for AD9834 DDS Device
//*
//*
//*
//*
//* Carlos Barberis June, 2004
//**********************************************
#define CH0MASK 0X4000
#define CH1MASK 0X8000
#define NCORATIO 5.36870912
#define INITWORD 0X2000
#define TRIANGLE 0X2002
#bit FSYNC = 0xF81.4 // we have chosen RB4 for the enable pin
#bit RESET = 0xF81.5 // we have chosen RB5 for the reset pin, these
// maybe changed to any other I/O pin
// Make sure to init SPI port as below
// setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4|SPI_SS_DISABLED);
unsigned int32 Ftune;
int16 lsw;
int16 msw;
// Func prototypes
void InitDds(void);
void CalcTuneWords_F0(float Freq0);
void CalcTuneWords_F1(float Freq1);
void WriteToCtrlreg(unsigned int16 value);
void OutputSine(void);
void OutputTriangle(void);
void InitDds()
{
int8 i;
RESET = OFF;
for(i=0; i<4; i++)
{ WriteToCtrlreg(INITWORD);
delay_us(20); }
delay_us(100);
for(i=0; i<2; i++)
{ WriteToCtrlreg(INITWORD);
delay_us(20); }
delay_us(30);
RESET = ON;
delay_us(50);
RESET = OFF;
}
void CalcTuneWords_F0(float Freq0)
{
float tunning;
tunning = Freq0 * NCORATIO;
Ftune = (unsigned int32)tunning;
lsw = (int16)Ftune & 0X3FFF;
lsw = lsw | CH0MASK;
Ftune = Ftune & 0XFFFC000;
Ftune>>=6;
Ftune>>=8;
msw = (int16)Ftune | CH0MASK;
}
void CalcTuneWords_F1(float Freq1)
{
float tunning;
tunning = Freq1 * NCORATIO; // Calculate tunning word
Ftune = (unsigned int32)tunning; // into a 32 bit word
lsw = (int16)Ftune & 0X3FFF; // Extract lower 16 bit word
lsw = lsw | CH1MASK; // Mask b15 and b14 leaving 14 lsb's
Ftune = Ftune & 0XFFFC000; // Extract upper 16 bit word
Ftune>>=6; // Shift lower bits out to make 16 bit word
Ftune>>=8;
msw = (int16)Ftune | CH1MASK; // Mask b15 and b14 leaving 14 msb's
}
void WriteToFreg()
{
int8 lsb1, msb1,lsb2,msb2;
lsb1 = (int8)lsw; // convert 16bit word
msb1 = lsw >> 8; // into two bytes
lsb2 = (int8)msw;
msb2 = msw >> 8;
FSYNC = OFF; // Bring enable line low to start write of first word
delay_us(5);
spi_write(msb1); // load msb of low word
spi_write(lsb1); // load lsb of low word
delay_us(5);
FSYNC = ON; // Bring enable line high to end first word write
delay_us(5); // add some dead time between words
FSYNC = OFF; // Bring enable line low to start write of second word
spi_write(msb2); // load msb of high word
spi_write(lsb2); // load lsb of high word
delay_us(5);
FSYNC = ON; // Bring enable line high to end second word write
}
void WriteToCtrlreg(unsigned int16 value)
{
int8 clsb, cmsb;
clsb = (int8)value;
cmsb = value >> 8;
FSYNC = OFF;
delay_us(5);
spi_write(cmsb); // load low word
spi_write(clsb); // load low word // load control word
delay_us(5);
FSYNC = ON;
}
void OutputSine()
{ WriteToCtrlreg(INITWORD); }
void OutputTriangle()
{ WriteToCtrlreg(TRIANGLE); } |
|
|
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
Thanks for code |
Posted: Sun Aug 08, 2004 5:05 pm |
|
|
Thanks for code!
I don't have Hardware SPI in my PIC .
Can I use software SPI ? How I can do it in this project?
Where is 28 bit freq register out to DDS in this code? How change for 32bit? |
|
|
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
Ok |
Posted: Tue Aug 10, 2004 3:44 pm |
|
|
Ok how about 9850 ? Is that is same codes? |
|
|
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
Th |
Posted: Wed Aug 11, 2004 1:04 pm |
|
|
I talk to myself. please tell how about Init for ad9835 whithout SPI? |
|
|
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
ot |
Posted: Sat Aug 14, 2004 11:14 am |
|
|
Or tell me what is defer register and what I must to program in it. |
|
|
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
I found |
Posted: Sat Aug 14, 2004 12:58 pm |
|
|
I found new program but on BASIC
this:
regfile = "8515def.dat"
$crystal = 8000000
Config Pind.7 = Output 'Sclk
Config Pind.6 = Output 'SData
Config Pind.5 = Output 'Fsync
Sclk Alias Portd.7
Sdata Alias Portd.6
Fsync Alias Portd.5
Set Sclk 'Set initial pin
state
Set Fsync 'Set initial pin
state
'#######################################################################
'End Hardware Configuration
Dim Fword0 As Long At &H60
Dim Low_byte0 As Byte At &H60 Overlay
Dim Low_mid_byte0 As Byte At &H61 Overlay
Dim High_mid_byte0 As Byte At &H62 Overlay
Dim High_byte0 As Byte At &H63 Overlay
Fword0 = &H346DC
Dim Setfreq As Long
Dim Freq As Single
Dim Count As Single
Setfreq = 400 'Change this
value
to the required Freq. in Hertz
Count = 536.870912 'This is count
for
1 Hz at 8 MHz MCLK input
Freq = Setfreq * Count
Fword0 = Freq
'Declare subroutines
'#######################################################################
Declare Sub Send_dds(byval Sw As Word)
'#######################################################################
'End Declare subroutines
'Start sending commands to the DDS
'#######################################################################
Call Send_dds(&Hf800) 'Resets DDS and
puts it into standby
Call Send_dds(&H3000 + Low_byte0) 'These 4 lines
sends the freq. to the DDS
Call Send_dds(&H2100 + Low_mid_byte0) 'These 4 lines
sends the freq. to the DDS
Call Send_dds(&H3200 + High_mid_byte0) 'These 4 lines
sends the freq. to the DDS
Call Send_dds(&H2300 + High_byte0) 'These 4 lines
sends the freq. to the DDS
Call Send_dds(&H8000) 'Sets SYNC and
SELSRC registers to 0
Call Send_dds(&H5000) 'Sets SELSRC
registers to 0
Call Send_dds(&Hc000) 'Brings DDS out
of
standby
'#######################################################################
'End sending commands to the DDS
Powerdown 'Put CPU in
Powerdown state for less noise
End 'End program
'########################################################################
'This is the subroutine that send the data to the DDS
'########################################################################
Sub Send_dds(byval Sw As Word)
Reset Fsync
Waitus 1
Shiftout Portd.6 , Portd.7 , Sw , 0 , 16 , 15
Set Fsync
End Sub
does exist a prof. man. that can do it on ccs |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 15, 2004 3:43 pm |
|
|
There are some drivers available on the net for AD9832, which
is very similar to the AD9835.
Go to this page and download the file, lwex.zip, which is near the bottom.
http://home.swipnet.se/~w-41522/minidds/minidds.html
It's written for the CC5X compiler, so you would have to translate it
to CCS. It has a lot of ASM code within the C functions, so you might
have to make some changes there, to allow it to be compiled by CCS.
Here is a AD9835 driver. It's not in the public domain, and it's also
in ASM. But you could translate it to C, or at least use it as a guide
when writing your own C driver.
http://www.min.at/OE1RIB/DDS/AD9835.asm
http://www.min.at/OE1RIB/DDS/AD9835.h
But you keep saying this:
Your post already has at least 235 Views. So maybe 50-100 different
people have looked at your request. If they had CCS code, they would
have posted it by now, if they wanted to.
Analog Devices has some good appnotes on the device.
http://www.analog.com/UploadedFiles/Application_Notes/522433833AN621_0.pdf
http://www.analog.com/library/analogDialogue/archives/38-08/dds.html
You should read these appnotes and look at the sample drivers at
the links given above and write your own driver.
Or, here is a thought: The sample driver in the link above is for
the CC5X compiler. You can download a free CC5X compiler here:
http://www.bknd.com/cc5x/index.shtml
Then you don't need to convert it to CCS. |
|
|
Userrr
Joined: 09 Jul 2004 Posts: 40 Location: Europe
|
Ok I admit my mistakes, no any question |
Posted: Mon Aug 16, 2004 11:27 am |
|
|
Ok I admit my mistakes, no any question .
///(maybe) |
|
|
just4hoi
Joined: 26 Apr 2006 Posts: 3
|
AD9835 example |
Posted: Thu Jun 14, 2012 6:56 pm |
|
|
Here is an ad9835 example:
Code: | #include <16F917.H>
#fuses EC_io,PROTECT,nowdt //,WDT
#use delay(clock=20000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <math.h>
#BYTE porta=0x05
#BYTE portb=0x06
#BYTE portc=0x07
#BYTE portd=0x08
#BYTE porte=0x09
#bit WRSTB = portb.4 //WRSTB pin
//#bit FRLD = portb.5 //FRLD pin //not implemented
//#bit CSEL = porte.0 //CSEL pin //not implemented
#bit FSYNC = portc.5 // FSYNC pin
#bit Ar0 = portb.0 //Address 0
#bit Ar1 = portb.1 //Address 1
#bit Ar2 = portb.2 //Address 2
#bit Ar3 = portb.3 //Address 3
#define high0 | 0x01
#define high1 | 0x02
#define high2 | 0x04
#define high3 | 0x08
#define high4 | 0x10
#define high5 | 0x20
#define high6 | 0x40
#define high7 | 0x80
#define low0 & 0xFE
#define low1 & 0xFD
#define low2 & 0xFB
#define low3 & 0xF7
#define low4 & 0xEF
#define low5 & 0xDF
#define low6 & 0xBF
#define low7 & 0x7F
#define on 1
#define off 0
#zero_ram
int8 byte0, byte1, byte2, byte3, commd, i;
int32 freq32_in;
float freq, freqf_in;
/*
C3 C2 C1 C0
0 0 0 0 Write 16 Phase bits in Defer Register)
REG.
0 0 0 1 Write 8 Phase bits
0 0 1 0 Write 16 Frequency
+ 8 Bits in Defer
FREQ REG.
0 0 1 1 Write 8 Frequency
0 1 0 0 Bits D9 (PSEL0)
used to Select the
SELSRC = 1. When
PHASE REG is
PSEL0 and PSEL1
0 1 0 1 Bit D11 is used to
when SELSRC =
the FREQ REG
FSELECT.
0 1 1 0 This command is
PSEL0, PSEL1
using only one write.
are used to select
Bit 11 is used to
when SELSRC =
the PHASE REG
pins PSEL0 and
REG is selected
0 1 1 1 Reserved. Configures
Test Purposes.
A3 A2 A1 A0
0 0 0 0 FREG0 REG 8 L LSBs
0 0 0 1 FREG0 REG 8 H LSBs
0 0 1 0 FREG0 REG 8 L MSBs
0 0 1 1 FREG0 REG 8 H MSBs
0 1 0 0 FREG1 REG 8 L LSBs
0 1 0 1 FREG1 REG 8 H LSBs
0 1 1 0 FREG1 REG 8 L MSBs
0 1 1 1 FREG1 REG 8 H MSBs
1 0 0 0 PHASE0 REG 8 LSBs
1 0 0 1 PHASE0 REG 8 MSBs
1 0 1 0 PHASE1 REG 8 LSBs
1 0 1 1 PHASE1 REG 8 MSBs
1 1 0 0 PHASE2 REG 8 LSBs
1 1 0 1 PHASE2 REG 8 MSBs
1 1 1 0 PHASE3 REG 8 LSBs
1 1 1 1 PHASE3 REG 8 MSBs
The frequency word is the 32-bit word which the user
inputs into the frequency register. This determines the
output frequency and is based on the ratio of the required
output frequency to the reference clock frequency. In the
example below, the reference clock is 25 MHz. The required
output needs to be 5 MHz, so the frequency word
is calculated as:
ENTIRE COMMAND SEQUENCE FOR 5 MHz PROGRAM
(5/25) x (4294967296) = 858993459 = 110011 00110011 00110011 00110011
0xF800 Binary (1111 1000 0000 0000)
0x3333 Binary (0011 0011 0011 0011)
0x2233 Binary (0010 0010 0011 0011)
0x3133 Binary (0011 0001 0011 0011)
0x2033 Binary (0010 0000 0011 0011)
0xC000 Binary (1100 0000 0000 0000)
*/
void WriteReg( int8 cmd, int8 data)
{
FSYNC = OFF;
delay_us(5);
spi_write(cmd); // load command, address
spi_write(data); // load data
delay_us(5);
FSYNC = ON;
}
void WriteFreq( float value) {
int32 freq32;
float freqf;
//value = value/2; //for 100MHz clock
value = value; //for 50MHz clock
freqf = value/50;
freqf=freqf*429496;
freq32 = freqf;
freq32 =freq32*10000;
byte0 = make8(freq32,0);
byte1 = make8(freq32,1);
byte2 = make8(freq32,2);
byte3 = make8(freq32,3);
commd = 0b11111000;
WriteReg( commd, 0);
commd = 0b00110011;
WriteReg( commd, byte3); //byte3 of frequency
commd = 0b00100010;
WriteReg( commd, byte2); //byte2 of frequency
commd = 0b00110001;
WriteReg( commd, byte1); //byte1 of frequency
commd = 0b00100000;
WriteReg( commd, byte0); //byte0 of frequency
commd = 0b11000000;
WriteReg( commd, 0);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//Main routine
//////////////////////////////////////////////////////////////////////////////////////////////////
void main(void) {
SET_TRIS_a( 0b00001111 );
SET_TRIS_b( 0b11111111 );
SET_TRIS_c( 0b10000000 );
SET_TRIS_d( 0b11111111 );
SET_TRIS_e( 0b00000000 );
//enable_interrupts(global);
//ext_int_edge(L_to_H);
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_16|SPI_SS_DISABLED);
delay_ms(100);
freq = 10; //MHz
WriteFreq(freq); //30MHz at 50MHz clock
while(1) {
///*
while(WRSTB == 1) { } //wait for strobe
while(WRSTB == 0) { } //wait for strobe
if(Ar0 == 0 && Ar1 == 0) { byte0 = portd; }
if(Ar0 == 1 && Ar1 == 0) { byte1 = portd; }
if(Ar0 == 0 && Ar1 == 1) { byte2 = portd; }
if(Ar0 == 1 && Ar1 == 1) { byte3 = portd;
freq32_in = make32(byte3, byte2, byte1, byte0);
//freq32_in = 805306368;
//freq32_in = 1073741824;
freq32_in = freq32_in / 100000;
freq32_in = freq32_in * 1862;
freq32_in = freq32_in / 1000;;
freqf_in = freq32_in;
freqf_in = freqf_in / 1000;
WriteFreq(freqf_in);
// porte = porte high1; DELAY_mS(1); porte = porte low1; DELAY_mS(1); //test
}
//*/
}
} |
|
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Fri Jun 15, 2012 1:06 am |
|
|
PCM programmer wrote: |
But you keep saying this:
Your post already has at least 235 Views. So maybe 50-100 different
people have looked at your request. If they had CCS code, they would
have posted it by now, if they wanted to.
|
Or, the poster's original message read more like, "I don't know how to do this -- will someone do it for me?"
And there's no faster way to turn off the users of a forum than to jump in and ask/demand someone to write for you or give up code they worked hard to make successful.
Just a thought for the original poster. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Jun 15, 2012 5:39 am |
|
|
The original post was in 2004. I imagine the OP has either solved his problem or lost interest by now. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Sat Jun 16, 2012 9:56 am |
|
|
SherpaDoug wrote: | The original post was in 2004. I imagine the OP has either solved his problem or lost interest by now. |
Hahaha... I didn't even see...
"lost interest" indeed.
That's what I get for posting before bed (when I'm sleeeeepppyyy)
Hahaha..
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|