electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


Goto page 1, 2  Next
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR
Author Message
gentxtelmer2003



Joined: 27 Jun 2005
Posts: 17
Helped: 1


Post08 Feb 2006 18:08   

ad9850 bascom


we are having hard time in writting the program in PIC together with the AD9850 which is a programable waveform generator IC.

The components of the Project are:


(3x4)KEYPAD - TO input the DESIRE frequency in HERTZ.
(HD44780)LCD - Display the FREQUENCY INPUTED in the KEYPAD.
AD9850 - the programable waveform generator IC from analog devices.


requirements:
max freq = 5MHz
frequency resolution of = 1Hz


The AD9850 is connected in parrallel with the PORT D of the PIC16F877A with a 20Mhz Clock. The reference clock of the AD9850 is 50MHz. The IC is 40bit programable.


If we input a certain frequency in the keypad it will generate a 40bit code for it to be loaded in the AD9850 also at the same time it will display the inputed frequency in the LCD display.


Help us in writting the program.
Back to top
rfmw



Joined: 10 May 2001
Posts: 520
Helped: 38


Post08 Feb 2006 19:43   

dds vfo with pic16f84 and ad9850


And your programming language is? Looks like you're beginner at PIC, so why don't you search the internet for the same, already functioning, projects?
Back to top
gentxtelmer2003



Joined: 27 Jun 2005
Posts: 17
Helped: 1


Post09 Feb 2006 0:49   

ad9850 filter


programing language is C.

im a newbie in this pic hobby.
Back to top
gentxtelmer2003



Joined: 27 Jun 2005
Posts: 17
Helped: 1


Post11 Feb 2006 7:23   

ad9850 pic


im using Microchip MPLAB IDE for programming and HI-TECH PICCLITE compiler... we will will load the tuning word for the AD9850 five times in 8-bit parallel with PORTD.. how are we going to load a value 0xFFFFFFFF(32bits) in four 8 bits.. bit31-bit23 will be loaded first..
Back to top
naj.cuizon



Joined: 04 Jul 2005
Posts: 23
Helped: 7


Post13 Feb 2006 2:28   

frequency generator bascom


problems also with the keypad input and LCD display..

Added after 2 minutes:

we are using a 50Mhz reference clock for the AD9850 and our PIC16F877A uses 20MHz...
Back to top
Code Warrior



Joined: 30 Dec 2004
Posts: 224
Helped: 7


Post13 Feb 2006 2:50   

ad9850 tuning word


I am also starting same type of projects using AD9850 and PIC. But my output frequency will be different. Where are you from Mr. gentxtelmer2003. Can you PM me.
Back to top
silvio



Joined: 31 Dec 2001
Posts: 801
Helped: 90


Post13 Feb 2006 7:35   

ad9850 pic16f877a


gentxtelmer2003 wrote:
how are we going to load a value 0xFFFFFFFF(32bits) in four 8 bits.. bit31-bit23 will be loaded first..


The AD9850 contains a 40-bit register that is used to program the 32-bit frequency control word.
You have a value stored in 32-bit variable that have to be sent to the 40-bit register of AD9850.
Probably you're in doubt where the 8-bit difference is coming from. It's one byte which includes 5-bit phase modulation, 1-bit power-down function and 2-bit factory reserved codes.
And this is the first byte among 5 that must be loaded first, followed by the rest of 4 meaning the frequency.

In order to load 5 bytes into 40-bit register you have to raise the level of pin 8 (FQ_UD) to "1" logic. That will reset the address pointer to the first register inside AD9850.
Reset to "0" the pin 8.
Now, load the PORTD with the first byte W0 which contains the phase, power-down and control bits as explained above and give a pulse 0 -> 1 -> 0 on pin 7 (W_CLK).
This will load the byte into 40-bit register and move the pointer to the next register.
Load the PORTD with b31-b24 and give another pulse on pin W_CLK.
and so on up to the fifth and last byte.
Finnaly raise again to "1" logic the pin (FQ_UD), then back to "0". After 18 clock cycles (on CLKIN) the frequency will be updated.

Because PIC16F877 is an 8-bit microcontroller, your 32-bit variable is stored in four concatened registers.
I'm confident that you know how to split in C such kind of variable in order to load the 8-bit PORTD, four subsequent times.

You can see a similar project with 4x4 keyboard, LCD and DDS here:
http://www.qsl.net/pa3ckr/signalgenerator/index.html
but wrote in assembler for PIC16F84 and AD9850 loaded serial rather than parallel.
Back to top
Code Warrior



Joined: 30 Dec 2004
Posts: 224
Helped: 7


Post13 Feb 2006 20:17   

ad9850


Mr. silvio thanks for nice description about AD9850 and other info. I want to know from where I will get optical rotary encoder for this project.
Back to top
silvio



Joined: 31 Dec 2001
Posts: 801
Helped: 90


Post13 Feb 2006 23:55   

ad9850 c source code


Code Warrior wrote:
I want to know from where I will get optical rotary encoder for this project.


From the same author : http://www.qsl.net/pa3ckr/bascom%20and%20avr/encoders/index.html

He starts with a Bourns ECW1J-B24-AC0024 contacting encoder with a rotational life of 200,000 shaft revolutions, 24 cycles/revolution and 120 RPM

Then he tried an optical encoder (needless contact bounce and increased rotational life) from Agilent.

However, you can use any industrial encoder with A/B output and resolution according to your needs.
Back to top
Google
AdSense
Google Adsense




Post13 Feb 2006 23:55   

Ads




Back to top
Code Warrior



Joined: 30 Dec 2004
Posts: 224
Helped: 7


Post14 Feb 2006 5:35   

bascom source code ad9850


Thanks silvio for the information. Actually I am making DDS based VFO for HAM purpose. May be you aware of HAM radio. There for I need more info and help in this direction. If possible PM me.
Back to top
naj.cuizon



Joined: 04 Jul 2005
Posts: 23
Helped: 7


Post14 Feb 2006 11:26   

ad9850 signal generator


silvio:
Because PIC16F877 is an 8-bit microcontroller, your 32-bit variable is stored in four concatened registers.
I'm confident that you know how to split in C such kind of variable in order to load the 8-bit PORTD, four subsequent times.


sir, this is our problem.. we do not know how to split in C such kind of variable.
Back to top
silvio



Joined: 31 Dec 2001
Posts: 801
Helped: 90


Post14 Feb 2006 15:02   

ad9850 applications


naj.cuizon wrote:
we do not know how to split in C such kind of variable.


Code:

unsigned long tuning_freq;               
unsigned long temp;                           
unsigned char your_PORTD;

temp = tuning_freq & 0xFF000000;                         
your_PORTD = temp >> 24;  /* your_PORTD variable contains now bits b31-b24 */

temp = tuning_freq & 0x00FF0000;
your_PORTD = temp >> 16;  /* your_PORTD variable contains now bits b23-b16 */

temp = tuning_freq & 0x0000FF00;
your_PORTD = temp >> 8;  /* your_PORTD variable contains now bits b15-b8 */

temp = tuning_freq & 0x000000FF;
your_PORTD = temp;       /* your_PORTD variable contains now bits b7-b0 */
Back to top
naj.cuizon



Joined: 04 Jul 2005
Posts: 23
Helped: 7


Post14 Feb 2006 17:14   

programming ad9850


thank you so much! you've been very helpful.. i'll try this one..
Back to top
naj.cuizon



Joined: 04 Jul 2005
Posts: 23
Helped: 7


Post15 Feb 2006 16:05   

ham radio ad9850 signal generator


silvio:

Probably you're in doubt where the 8-bit difference is coming from. It's one byte which includes 5-bit phase modulation, 1-bit power-down function and 2-bit factory reserved codes.

Sir, we would like to ask wat would be the value for the 5-bit phase modulation and 1-bit power-down function. it is not found in the datasheet. only the 2-bit factory reserved codes can be found (01 or 10).
Back to top
silvio



Joined: 31 Dec 2001
Posts: 801
Helped: 90


Post15 Feb 2006 23:26   

Re: HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


http://www.analog.com/UploadedFiles/Data_Sheets/34008438159094AD9850_h.pdf
Figure 8 and 9 from page 11 shows effects of writing XXXXX100 and XXXXX000 data W0 as internal clocks are disabled and enabled accordingly.
On bottom of page 1, first column :
Quote:

The device also provides five bits of digitally controlled phase modulation, which enables phase shifting of its output in increments of 180°, 90°, 45°, 22.5°, 11.25°, and any combination thereof.

For 0° phase shifting, W0 = 00000000
For 11.25°phase shifting, W0 = 00001000
For 180° W0 = 10000000
For 191.25° W0 = 10001000 and so on.
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 566


Post16 Feb 2006 1:58   

Re: HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


Code Warrior wrote:
Actually I am making DDS based VFO for HAM purpose. May be you aware of HAM radio. There for I need more info and help in this direction. If possible PM me.

The 2006 ARRL Handbook describes several DDS applications and construction projects for ham radio.
http://www.arrl.org/catalog/9485/
Back to top
Code Warrior



Joined: 30 Dec 2004
Posts: 224
Helped: 7


Post16 Feb 2006 4:52   

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


Mr. echo47 you have ARRL hand book in PDF format? Can you send me that.
Back to top
naj.cuizon



Joined: 04 Jul 2005
Posts: 23
Helped: 7


Post17 Feb 2006 17:21   

Re: HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


I made this simple test program using MPLAB IDE from Microchip with HiTech PICCLite Compiler. This didn't work in our hardware testing. We wanted to use parallel loading method of loading the values to the AD9850 from the PIC16F877A with RC2 as FQ_UD, RC3 as W_CLK and all the 8pins of PORTD as one to contain the DATA. pls comment and i welcome suggestions/corrections.


#include<pic.h>
#include<delay.h>
#include<delay.c>


void main(void)
{
TRISC=0x00;
PORTC=0x00;
TRISD=0x00;
PORTD=0x00;

DelayMs(200); //set a delay of 200ms

RC2=0; DelayUs(4); RC2=1; DelayUs(4); RC2=0; DelayUs(3); //RC2-FQ_UD, RC3-W_CLK
PORTD=0x00; DelayUs(1); RC3=1; DelayUs(2); RC3=0; DelayUs(1); //W0 control - 00 (or 11)
// power-down - 0 (internal clocks enabled
PORTD=0x00; DelayUs(1); RC3=1; DelayUs(2); RC3=0; DelayUs(1); //W1 b31-b24 tuning word
PORTD=0x83; DelayUs(1); RC3=1; DelayUs(2); RC3=0; DelayUs(1); //W2 b23-b16
PORTD=0x12; DelayUs(1); RC3=1; DelayUs(2); RC3=0; DelayUs(1); //W3 b15-b8
PORTD=0x6E; DelayUs(1); RC3=1; DelayUs(2); RC3=0; DelayUs(2); //W4 b7-b0
RC2=1; DelayUs(4); RC2=0; DelayUs(4);

for(;Wink; //loop forever

}
Back to top
rfmw



Joined: 10 May 2001
Posts: 520
Helped: 38


Post17 Feb 2006 19:43   

Re: HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


hi,

I did a few years back exactly the thing you're trying to build. I used pic16f877 + ad9850 + hi-tech picc compiler.

I used this function to load the DDS (4MHz clock):

void send2dds()
{
unsigned char data;
dds_fqud=0;
dds_wclk=0;
data=0;
PORTD=data;
dds_wclk=1;
dds_wclk=0;

data=word >> 24;
PORTD=data;
dds_wclk=1;
dds_wclk=0;

data=word >> 16;
PORTD=data;
dds_wclk=1;
dds_wclk=0;

data=word >> 8;
PORTD=data;
dds_wclk=1;
dds_wclk=0;

data=word;
PORTD=data;
dds_wclk=1;
dds_wclk=0;
dds_fqud=1;
PORTD=0;
}

hope it helps Wink
Back to top
naj.cuizon



Joined: 04 Jul 2005
Posts: 23
Helped: 7


Post17 Feb 2006 21:22   

Re: HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


Another thing is we are using a keypad as input and there we input a decimal value. How do we convert a DEC value to HEX in C?

Ex:
temp = tuning_freq & 0xFF000000;
your_PORTD = temp >> 24;

the tuning_freq has to be HEX, right?? our program takes what is inputed as DEC.. therefore, we hav to convert the input value to HEX in order to be manipulated, right?? really need guidance on this..
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 566


Post17 Feb 2006 22:04   

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


You should grab a good book for learning C. Search around for recommendations.

C does not have HEX or DEC variables. The variable tuning_freq is an unsigned long int. In most C compilers, that is a 32-bit binary value.

If you explain exactly how you stored your keypad input digits, someone can help you convert it to the required format for the DDS.

Don't forget - if your enter Hertz into your keypad, you must scale that value before writing the bytes to the DDS.
Back to top
naj.cuizon



Joined: 04 Jul 2005
Posts: 23
Helped: 7


Post18 Feb 2006 1:52   

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


maybe it doesnt matter if in C i have decimal values or hexadecimal, right? i mean, in C, i can do an AND operation between a decimal (ex. 100Hz*prescale) and a hexadecimal (0xFF000000), right? i think it doesnt matter coz the compiler will convert all values to zeros and ones, right? am i right? at least, that's what i think.. hehhehe..
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 566


Post20 Feb 2006 5:10   

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


Yes, you can use decimal and hex constants in your C source code. The compiler converts them to binary for its internal use.

However, you haven't explained the format of your keypad digits, or how you stored them in memory. We need that info to help you convert it to DDS format.
Back to top
gentxtelmer2003



Joined: 27 Jun 2005
Posts: 17
Helped: 1


Post22 Feb 2006 17:12   

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


sir,

how can we design an effective LOWPASS FILTER?

we are having problems in minimizing the distortion of the output signals.

any suggestions?
Back to top
naj.cuizon



Joined: 04 Jul 2005
Posts: 23
Helped: 7


Post22 Feb 2006 18:23   

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


the suggested filter to use in the datasheet was a 5-pole elliptical low pass filter 42MHz.. how do we implement this? our sine wave output needs a lot of work.. its not really distorted, its a DAC sine wave output, we have a hard time refining the signal to have a smooth sine wave..
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 566


Post23 Feb 2006 19:39   

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


What is your difficulty in implementing the filter? The datasheet gives a schematic, parts list, and PCB layout. Use good RF construction techniques, not a rat's-nest breadboard.

If you are using a slower clock than the datasheet example (100 MHz), don't forget to proportionally scale down the low-pass filter frequency. The filter needs to pass your highest desired sinewave frequency, and block everything above the clock frequency minus your highest desired sinewave frequency.
Back to top
gentxtelmer2003



Joined: 27 Jun 2005
Posts: 17
Helped: 1


Post24 Feb 2006 0:20   

HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


we dnt have an instrument that can measure inductance in nH.

can we use gauge 18 magnetic wire for our inductor?

if its possible how many turns to make 960nH and 680nH?

do we need a core for our inductor?
Back to top
alirezaregister



Joined: 26 Aug 2005
Posts: 5


Post25 Feb 2006 15:40   

Re: HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


Hi ..
i just know a thing about PIC
which pic mcu compatibility USB in high speed with a sample frimware ?
and
if i want compare PIC with AVR which them is nice for waste time and learn?
Back to top
gentxtelmer2003



Joined: 27 Jun 2005
Posts: 17
Helped: 1


Post27 Feb 2006 19:42   

Re: HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


can someone help me send the 40 bits tuning word of the AD9850 correctly via serial loading from PIC16F877A? I used this style below but my output frequency is far from the expected output frequency. When i input 1 from my keypad(interfaced on the microcontroller), about 128Hz is produced. Likewise, 10Hz input outputs about 1.28kHz.

INPUT is the value entered from keypad. TUNINGWORD is my 32bit tuning word. Since my desired frequency resolution is 1Hz, I multiplied/scale my INPUT.

TUNINGWORD=INPUT*53.687091;
//53.687091 is from the formula 32bit tuning word = Fout X 2^32 / ref. clock of the DDS
//Fout of course is 0.000001MHz(1Hz resolution), ref. clock is 80MHz

This is the C code i used to send the 40bits(32bits tuning word + 8 bits phase control word).

#define data RC0
#define w_clk RC1
#define fq_ud RC2

unsigned int x,y;
unsigned long TUNINGWORD,INPUT;
unsigned char temp;

void send40bit(void)
{
fq_ud=0;
for(x=0;x<32;x++) //32bits tuning word
{
temp=TUNINGWORD>>x;
data=temp;
w_clk=1; w_clk=0;
}
for(y=0;y<8;y++) //8bits phase control all zeros
{
data=0;
w_clk=1; w_clk=0;
}
fq_ud=1;
}
Back to top
silvio



Joined: 31 Dec 2001
Posts: 801
Helped: 90


Post28 Feb 2006 12:38   

Re: HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR


Do you have a C debugger in order to watch the variables contents ?

1. Do you need to cast "INPUT*53.687091" ? Try to direct assign 53 to TUNINGWORD before calling send40bit function and notes the Fout value.
2. Are you sure after shifting TUNINGWORD "x" times to right, the temp variable (unsigned char) hold b7-b0 of 32bits TUNINGWORD ?
3. Are you sure after "data=temp" the RC0 (it's only a bit) will get the LSBit of "temp" (unsigned char) ? How the C compiler handles these assignments ? Have you ever killed your curiosity about how the compiled code looks in assembler ?

This is a stupid sequence or a bad C skill programmer (and as a result a waste of memory code ) if I'm doing this way ?
Definitely shifting 4 concatenated registers (TUNINGWORD>>31) will be waste of execution times rather than memory code.
Code:

for (i = 0; i < 32; i++)
   {
      if ((TUNINGWORD & 1) == 1)
         data=1;     //the most stupid embedded C assignment
      else
         data=0;
      tuning_word = tuning_word >> 1;
   w_clk=1; w_clk=0;  //these are stupid as well, you can write in assembler as well
   }


If you're not sure how C compiler handles the code (and never complains about them) let's write in HighLevelLanguage style.
I mean "if"......"else"...... rather than skip next instruction if bit is set or reset (assembler style).

You wrote that for input 1 you got 128 Hz and for input 10 -> output 1,28KHz.
It's quite linear, isn't ?. Hence a straight look at the bit streams delivered to AD9850 will clear your confussion :
it's a bug in code or AD9850 don't behaves as expected ?

For input 1 the bit stream should look like 0000000000110101 or 53 decimal for 0,987Hz output frequency, but you got 128Hz output.
If the bit stream looks like 0001101011010111 or 6871 decimal (for input 1), then you have a software bug.

Just play a little and can solve the problem yourself.
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> HELP on PIC PROGRAMING with AD9850 SIGNAL GENERATOR
Page 1 of 2 All times are GMT + 1 Hour
Goto page 1, 2  Next
Similar topics:
PIC-Based Signal Generator --- help! ^__^ (26)
programing pic with c (2)
Questions about in ciruit programing with PIC 16f877? (2)
AD9850 interfaced with PIC16F877A (7)
looking for a pic-based signal generator (4)
signal generator with max038 (4)
Switch pic micro ON/OFF with output signal from another pic (1)
Need help with digital and programing (1)
DDS sinewave generator with PIC (6)
TACHO generator digital readout with PIC or what? (1)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS