With an 8 bit microcontroller I must to calculate the AD9558 DDS input data, with the formula: Data = (2^48/Fclk)*Fout
i.e. : Fclock =100MHz Fout = 11300000 Hz Data = 1CED 9168 72B0 (or 31.806.672.368.304) then Data_1 = 1CED Data_2 = 9168 Data_3 = 72B0
With an 16 bit processor I don't have any problem, but with an 8bit processor I don't find/know the right way to calculate the *exact* Data and Data_n.
Can you suggest me your "C" solution??
Thanks in advance and sorry for bandwidth...
73\'s de IZ5FCY Roberto
Didn't find your answer? Ask the community — no account required.
R
Rich Grise
Which 8-bit processor?
Maybe if you googled "multiple-precision arithmetic" you'd find some suggestions.
Or, since (2^45/Fclk) is invariant, what about just a LUT?
Good Luck! Rich
F
Frank Raffaeli
You will need to change it to 6 or 8 bytes from 4 bytes, but the theory is the same. Here is a code segment from a multimeter that uses the routine "Ratio" to divide two 32-bit numbers when calculating ohms. It is written for an 8-bit "AVR". Sorry it's not "C". if it's a homework problem, it's just a constant anyway ;-)
formatting link
Regards,
Frank Raffaeli
formatting link
R
Roberto IZ5FCY
Good idea, dear Sphero! Many thanks !!
73\'s de IZ5FCY Roberto
S
Spehro Pefhany
You need an exact 48-bit answer, so with either an 8-bit, 16-bit or
32-bit processor you will need to use multiple precision math. In C, that means you *may* need something bigger than 'long' (check your limits.h file, but it's only guaranteed to be 32 bits). Similarly, the mantissa of floating point type 'double' is only guaranteed to be about 30 bits. If your compiler supports long long 64 bit (minimum) integers as defined in the C99 standard, then you can directly use the below, otherwise it's probably easiest to just drop one or two little assembler math routines in (you can also do it in C with partial products and 32-bit math, but I'll leave that as a tedious exercise).
First factor the Fclock (presumably fixed, right?) to
Fclock = 2^8 * 390625 = 2^8 * 0x5F5E1
Then you can write
Data = Fout* (2^40/0x5F5E1) = (Fout * ((2^40 * 2^k)/0x5F5E1))/2^k
Round and use the smallest value of k that gives you accuracy down to the last bit. You can reduce this to shifts and multiplication by a constant, which might be desirable since divide is typically quite slow.
R
Roberto IZ5FCY
Il Fri, 3 Mar 2006 16:16:05 +0100, nonostante la corrente di placca pericolosamente elevata, Roberto IZ5FCY, senza effettuare gli accordi, volle trasmettere :
.. ehmm... sorry ! Sephro ;-)
73\'s de IZ5FCY Roberto
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.