FPGARelated.com
Forums

Help wanted

Started by Roberto IZ5FCY March 2, 2006
Hi to all Newsgroup,

I need of your little help.

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

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.
Have you an solution??
Thanks in advance and sorry for bandwidth...

-- 
73's de IZ5FCY Roberto

Roberto IZ5FCY wrote:
> Hi to all Newsgroup, > > I need of your little help. > > 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 > > 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. > Have you an solution?? > Thanks in advance and sorry for bandwidth...
If you're using an 8-bit microprocessor, simply translate doing long division by hand into steps of subtract, store if positive/jump if negative, shift and bring in new bits. If you can't do long division by hand, you're hosed.
 
> If you're using an 8-bit microprocessor, simply translate doing long > division by hand into steps of subtract, store if positive/jump if > negative, shift and bring in new bits. If you can't do long division by > hand, you're hosed.
Thanks John, but in "C" language....?? -- 73's de IZ5FCY Roberto
Roberto IZ5FCY <iz5fcy_NOSPAMPLEASE_@arrl.net> wrote:
> Hi to all Newsgroup,
> I need of your little help.
> 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
> 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. > Have you an solution?? > Thanks in advance and sorry for bandwidth...
If you use a C compiler, it probably knows how to do math with long values... -- Uwe Bonnes bon@elektron.ikp.physik.tu-darmstadt.de Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt --------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
 
> If you use a C compiler, it probably knows how to do math with long values...
No dear Uwe, the 8bit PIC or AVR don't have 16bit math library.... -- 73's de IZ5FCY Roberto
Roberto IZ5FCY wrote:

> Thanks John, but in "C" language....??
What about "long long"? Depends on your compiler, but if it is available, it may be 64 bits wide. If there is no suitable data type, then you need to handle the carry-out manually. Unfortunately C does not let you access a carry flag inside the CPU. So you got two choices: Make the most significant bit the carry-out and handle it manually or use inline assembly. Inline assembly is quite easy to handle for GCC. But I think, we are very off-topic! Ralf
Uwe,

I actually had a real problem finding something that would deal with 48 
bit long words for integer division...and multiplication.

I like John's approach:  write a program to do what you would do by hand 
(in whatever language you like).

2E48 is only ~ 2.8E14.  It isn't the scientific notation value that is 
large (or small), it is the fact that you really want 48 digits of 
accuracy so that you are +/- 1/2 lsb, or within 3.6E-15 * fclk of the 
frequency you want. 100 Micro-hertz resolution in this case?

I think for Ham radio, 2E48 is a bit overkill, unless you are doing 
coherent detection...

Austin AB6VU

Uwe Bonnes wrote:

> Roberto IZ5FCY <iz5fcy_NOSPAMPLEASE_@arrl.net> wrote: > >>Hi to all Newsgroup, > > >>I need of your little help. > > >>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 > > >>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. >>Have you an solution?? >>Thanks in advance and sorry for bandwidth... > > > If you use a C compiler, it probably knows how to do math with long values... >
"Roberto IZ5FCY" <iz5fcy_NOSPAMPLEASE_@arrl.net> wrote in message
news:wzb56p4xowzg$.1um668ma1y2vm.dlg@40tude.net...
> > > If you're using an 8-bit microprocessor, simply translate doing long > > division by hand into steps of subtract, store if positive/jump if > > negative, shift and bring in new bits. If you can't do long division by > > hand, you're hosed. > > Thanks John, but in "C" language....??
int can_solve_problem(usenet_poster *op) { if (op->can_do_long_division) { think(op); write(op, SOME_CODE); return 1; } else { hosed++; return 0; } }
Hi there

wrong! AVR GCC suports int (16bit) long, and long long.

Aurash


Roberto IZ5FCY wrote:
> > >>If you use a C compiler, it probably knows how to do math with long values... > > > No dear Uwe, the 8bit PIC or AVR don't have 16bit math library.... >
If your PIC doesn't have a math library that can handle the large
numbers, do it with an array of 8-bit integers or chars.  Loop through
the 8-bit values the way you loop through the digits to do long
division.

If your base frequency will never change, however, forget calculating
2^n*Fout/Fclk but instead perform the multiplication of Fout*const
where const=2^n/Fclk.  You may need to calculate the constant by hand,
but you end up with a number that will give you your phase increment
value for your DDS with a simple multiplication.  If the PIC's C
support doesn't provide multiplies for numbers that big, try doing
multiplication "by hand" in C.