Ad9851 dds
g3cwi
Posts: 262
Hi all
I am trying to get to grips with sending data to an AD9851 DDS chip. However, being completely new to things here (and to the Propellor) it is proving problematic.
http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9851/products/product.html
The chip needs a 40 bit binary word which can either be transmitted serially or as 5 x 8 bit bytes (much faster). Only the 32 LSBs of the 40 bit word are reqired to define the frequency. These 32 bits are calculated by the formula 32bits = (F_out x 2^32) / F_clock. F_out is the desired frequency.
For an example, using a clock of 125MHz, the words for 10MHz are:
W0 00
W1 14
W2 7A
W3 E1
W4 48
lhttp://designtools.analog.com/dt/dds/ad9851.html
The first problem is calculating the word as the Spin compiler does not like the decimal representation of 2^32 (4294967296). I can fix that by approximating the number to 4294967295, or perhaps pre-dividing by F_clock which is another constant. I then end up with a decimal number representing the 32 bit word.
It could be that it is already the binary number I need but I'm guessing that it's not as it is probably stored in a clever way to account for decimal places and pos/neg (?). If so I need to clean it up so that I can send it out (another puzzle at this stage).
I have looked about on t'internet for code for this application; there is plenty of PIC stuff and some C, but neither helps me at all. Has anyone got anything they would care to share or can anyone give me one or two clues as to some of the Spin elements that I need to get familiar with!
I'm on a steep learning curve here and I'm close to the bottom at the moment, hanging on by my finger nails...
Any clues would be much appreciated.
Thanks
Richard
I am trying to get to grips with sending data to an AD9851 DDS chip. However, being completely new to things here (and to the Propellor) it is proving problematic.
http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9851/products/product.html
The chip needs a 40 bit binary word which can either be transmitted serially or as 5 x 8 bit bytes (much faster). Only the 32 LSBs of the 40 bit word are reqired to define the frequency. These 32 bits are calculated by the formula 32bits = (F_out x 2^32) / F_clock. F_out is the desired frequency.
For an example, using a clock of 125MHz, the words for 10MHz are:
W0 00
W1 14
W2 7A
W3 E1
W4 48
lhttp://designtools.analog.com/dt/dds/ad9851.html
The first problem is calculating the word as the Spin compiler does not like the decimal representation of 2^32 (4294967296). I can fix that by approximating the number to 4294967295, or perhaps pre-dividing by F_clock which is another constant. I then end up with a decimal number representing the 32 bit word.
It could be that it is already the binary number I need but I'm guessing that it's not as it is probably stored in a clever way to account for decimal places and pos/neg (?). If so I need to clean it up so that I can send it out (another puzzle at this stage).
I have looked about on t'internet for code for this application; there is plenty of PIC stuff and some C, but neither helps me at all. Has anyone got anything they would care to share or can anyone give me one or two clues as to some of the Spin elements that I need to get familiar with!
I'm on a steep learning curve here and I'm close to the bottom at the moment, hanging on by my finger nails...
Any clues would be much appreciated.
Thanks
Richard
Comments
Word_to_send := ((F_out << 16) / F_clk) << 16
You may not want 16 in both places. The two numbers should add up to 32, though. The first one should be small enough that F_out won't overflow a 32-bit number, but otherwise as large as possible.
Looking at the operators it looks like a bitwise reverse, used with a bitwise encode, a test and a shift left might be a way of shifting out a number correctly. There has to be an easier way though. It looks way too clumsy.
I really need to re-learn my binary maths!
Cheers.
I think that I can use & to do my testing:
If (DDS_word & $0001) > 0 'then LSB is 1
maybe?
It is set to run slow for testing. I dont have an AD9851 here as yet to test it.
I will report back once I am able to test it "live".
Regards
Richard
Regards
Richard
PS I have no idea how Chris' divide and multiply code actually works. I would love some pointers to that!
Regards
Richard
The second question is does a call to an object always return from that object irrespective of what the object does?
I would welcome advice on any other errors you see!
Cheers
Richard
AD9851_Demo - Archive [Date 2012.05.23 Time 20.38].zip