AD9833 16 bit SPI

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
elsam
Flowcode V4 User
Posts: 3
Joined: Mon Jul 16, 2012 7:17 am
Contact:

AD9833 16 bit SPI

Post by elsam »

Hi All,

I'm a Flowcode 4.5 user that want to ask some about SPI communication.

I have one DDS chip to generate 400hz sine waves that need 16 bit control via SPI. I have certainly confused to doing comunication DDS AD9833 with the PIC16F877A :roll:

what I have done were connect :
Pin RC3 to SCLK
Pin RC5 to SDATA
Pin RE2 as FSYNC (chip select).

I also split the large integer(16 bit) into 2 byte as High_byte and Low_byte in my program so that them could send via SPI.

Ok, here I have attached the following instruction from the application note AN-1070 and my program below.

https://docs.google.com/viewer?url=http ... N-1070.pdf

Really appreciate to any advise and would be great if some of you can help me.
Attachments
AN-1070.fcf
(13.65 KiB) Downloaded 355 times

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: AD9833 16 bit SPI

Post by DavidA »

Hi elsam,

Could you please sign up as a Flowcode v4 user, this will allow us to offer you a better level of support.

Here are some instructions on how to sign up:

http://www.matrixmultimedia.com/mmforum ... =29&t=8762

Once you have done this, reply to this topic and i will move this to the appropriate forum.

elsam
Flowcode V4 User
Posts: 3
Joined: Mon Jul 16, 2012 7:17 am
Contact:

Re: AD9833 16 bit SPI

Post by elsam »

DavidA

Ok thank you for your fast reply.

I will do it:D

gumilard

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: AD9833 16 bit SPI

Post by Enamul »

Hi,
I have a quick look at your FC and datasheet linked..

i have seen couple of mistake..you didn't mention about RESET pin..what you did to that pin as this is very important..can you please post the schematic of the circuit you are using?

Another issue is the code..

Code: Select all

Freg = (Fout * 2^28)/Fmclk
This will not work at all..I can't find out Fmclk in program..

I understand what you are trying to do..I can help you but it is possible if you post schematic and make me clear you have connected IC properly..

Thanks,
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

elsam
Flowcode V4 User
Posts: 3
Joined: Mon Jul 16, 2012 7:17 am
Contact:

Re: AD9833 16 bit SPI

Post by elsam »

Hi Enamul,

Since I read the manual, I have connect all the DDS's Pin to my PIC micro. Maybe I did a mistake? Please see the attachment below. But I thought there's no Reset pin :( only 3 Pins I have (may I'm wrong).

Yes, and about the code I have inserted, I know that will not work. I just inserted because for my further development. If that is take and effect to the program, I can delete it. Sorry


Many Thanks to you Enamul.

Cheers,
Gumilard
Attachments
AD9833.pdf
(37.7 KiB) Downloaded 455 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: AD9833 16 bit SPI

Post by Benj »

Sending a single 16-bit SPI transaction should work just fine as two byte operations.

You can split the 16-bit value into two bytes like this.

bytel = int
byteh = int >> 8

and then recombine like this.

int = bytel
int = int | (byteh << 8 )

If you keep the chip select low while you send out or receive the two bytes then this should work fine. You could even create a Flowcode macro to send or receive a 16-bit value on the SPI which automatically converts from 16 to 8 bit and back again.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: AD9833 16 bit SPI

Post by Enamul »

Hi,
I am working on that it seems that it will take sometime..

I will post the FC after completion..

Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

gumilard
Posts: 16
Joined: Wed Nov 24, 2010 1:41 am
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: AD9833 16 bit SPI

Post by gumilard »

Hi Benj,

Please see my attachment. Look at my calculation code, is that same with what you said? :|

Hi Enamul,

Ok, I will waiting patiently :D

thanks for your time all :D


Cheers
Gumilard

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: AD9833 16 bit SPI

Post by Enamul »

Hi Gumilard,
I have modified very few things. You can now have a try..I took out all macro out of free running loop because once you complete the sequence you don't need to run it again unless you want to change any feature during runtime. I guess as a start you should just be able to see 400Hz sine wave at output first. Then the code can be modified to advanced level to adopt with frequency change and you might add option for triangular signal...

Please let me know how is it going> :)
Enamul
Attachments
AN-1070.fcf
(16.97 KiB) Downloaded 351 times
Enamul
University of Nottingham
enamul4mm@gmail.com

gumilard
Posts: 16
Joined: Wed Nov 24, 2010 1:41 am
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: AD9833 16 bit SPI

Post by gumilard »

Hi Enamul.

Wow bit seem light to me :D thank you. but Why I can't open that Flowcode in my computer?? that will given error message.

cheers
Gumilard

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: AD9833 16 bit SPI

Post by Enamul »

Hi,
Which version of Flowcode you are using? FC V 4.5?
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

gumilard
Posts: 16
Joined: Wed Nov 24, 2010 1:41 am
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: AD9833 16 bit SPI

Post by gumilard »

HI Enamul

Wait.. wait... I can open it Now. Sorry :D I'm using FC V4.5

OK, first I don't see anything on my scope.. I do a little change on the SPI Configuration:
Fosc/4 changed to Fosc/16
change clock polarity Idle_low changed to Idle_high

and I just want to say WOW ! it's work just fine :D I can see 400hz Sinewave on my scope

you are amazing enamul.

Thank you
Gumilard

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: AD9833 16 bit SPI

Post by Enamul »

Hi,
That's great! I could see the smile at your face. :D
If you need any particular change in the program please let me know. Enjoy your good works.
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: AD9833 16 bit SPI

Post by Enamul »

Hi,
I will send a program to-night with buttons to set frequency and phase of the sinewave. I will also send a schematic for that.
My plan is to use one LCD, and may some buttons for controlling to generate sinewave only. Do you have a better Idea for hardware configuration and for the software development?
Please just wait few hours :)
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: AD9833 16 bit SPI

Post by Enamul »

Hi,
After few hours of effort I have managed to make an FC for you. You can now see the frequency in LCD (2*16). You can set the frequency you want from the AD9833. Although you can set upto 9.99 KHz but in hardware it will work from 0.01 KHz upto 1.52 KHz. If you are interested in higher frequency range, please let me know. The problem is in V4 INT variable only supports 32767 and LSB Freq register has 14 bit for frequency which can be 2^14 = 16384. So from the equation Freq = (Freg*2^28)/25MHz => Freq = 1.52 KHz
I don't know is that enough for you or not.
Connection:
LCD:
FC uses last 4 pin of data bus DB4:DB7 which to be connected in RB0:Rb3
RS>RB4
R/W>GND
E>RB5
Contrast(LCD pin 3): some lcd works if you connect to GND but in most you have to put a pot (10K). central terminal at pin 3 and rest of the two to Vcc and GND.
Keys:
UP> RD0
DOWN>RD1
SET>RD2
CANCEL>RD3
Switches should be normally low but high when pressed..Vcc>390 ohm>SW>10K>GND ...connect to port pin in the middle of lower sw terminal and 10K.
Feel free to ask me if you are not clear. :)
Enamul
Attachments
AN-1070.fcf
(36.71 KiB) Downloaded 284 times
Enamul
University of Nottingham
enamul4mm@gmail.com

gumilard
Posts: 16
Joined: Wed Nov 24, 2010 1:41 am
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: AD9833 16 bit SPI

Post by gumilard »

Hi

Enamul,

I have just downloaded the code, and I will try and it look interesting to me :D and inform to you..

thanks
Gumilard

gumilard
Posts: 16
Joined: Wed Nov 24, 2010 1:41 am
Has thanked: 5 times
Been thanked: 3 times
Contact:

Re: AD9833 16 bit SPI

Post by gumilard »

Hi

Enamul

Oh yea, and about the INT variable, if so my project would not be able to be made? because I hope I can generate 0.01 Hz until at least 2 MHz. Is it possible to me If I use the FCV5 now?

regards,
Gumilard

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: AD9833 16 bit SPI

Post by Enamul »

Hi gumilard,
Yes.. If you move to FC5 then it's easily possible..
Oh yea, and about the INT variable, if so my project would not be able to be made? because I hope I can generate 0.01 Hz until at least 2 MHz. Is it possible to me If I use the FCV5 now?
Please let me know whether you moving to v5 or not.
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply