Go Down

Topic: How much can 328p handle? (Read 2 times) previous topic - next topic


May 05, 2013, 07:21 pm Last Edit: May 07, 2013, 12:20 am by pito Reason: 1

You need to do this calculation in 64-bit integer arithmetic (which makes using the Due look better!)

This works on the Uno:

Code: [Select]

unsigned long long DDSword, freq, DDSclock;
DDSclock = 125000000LL;
freq = 50000000LL;  // required freq
DDSword = (0x100000000LL) * freq ;
DDSword = DDSword / DDSclock;

The above works :)
You may do a check with:
Code: [Select]
Serial.println((long)DDSword, 16);



Hi Folks. Thanks a lot for the inputs! I'm still digesting how to use the code snip-its provided.

I also noticed the 2^32 calculation and sent the update (int32_t freq = frequency * 4294967296LL/125000000L;). My freq counter is limited to 10 Hz resolution , so perhaps I am just not able to measure the difference - the output is 9,999,96 Hz when set to 10 MHz output. I'll have to dig out another counter...

I see what you're saying pito, thanks.

I'm still trying to get the faster code to run, and also played with putting the sendfreq call in an encoder interrupt, and that did nothing?



"This is the 8-bit data port for iteratively loading the 32-bit frequency and the 8-bit phase/control word."

I don't see that you have an control word being created in the array data.
See pages 9-10 of the data sheet.

I think your formula is not correct
int32_t freq = frequency * 4294967295/125000000;

page 8 says Freq out = (tuning word * clock in(MHz))/2^32
                                     = (32-bit word*125,000,000)/0xFFFFFFFF
                                     = (32-bit word * 125,000,000) >> 32
so you probably need a 64 bit to start with for the multiplication, that gets shifted down for the 2^32 divide.
125,000,000 = 0x0773,5940
So it would seem that the the tuning word would have to be some minimum amount to avoid getting divided down to 0, yes?
Like 23 or more:
0x0773 5940 x 22 = 0xFD51 DA80 >> 32 = 0
0x773 5940 * 23 = 0x1 04C5 33C0 >> 32 = 1
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.


Oh, this is like the opening scene with Mr. Roarke and Tattoo...

Is this not the control word in the array: dataArray[4] = 0x000;   // Final control byte, all 0 for 9850 chip

The formula does seem messed up, not only the value. I'm surprised I'm getting output. I'll change that tonight and see how it pans out, but, is it not this way because we are calculating the tuning word value based on frequency? And there was something about the largest 32-bit integer value being 2^32-1.

I know decimal math, if I plug in a tuning word value of "1", I get a frequency value of 0.0291, which is the minimum frequency resolution of the DDS (spec). If the tuning word value is 34.35974, the frequency value is 1. If the tuning word value is 0, then I suspect DC output?


May 06, 2013, 10:08 pm Last Edit: May 06, 2013, 10:54 pm by pito Reason: 1
Again, simply verify your DDSword calculation (see my post above). When it is correct (it MUST be the same as the calc result on the ADI page above), try to pass it to the DDS chip.

Do NOT expect you will see an accurate DDS output frequency on the freqmeter, because you do NOT know the actual frequency of your 125MHz DDSclock. It could be 125.009.447,786 Hz - this DDSclock needs to be

a) measured by the freqmeter and its value has to be changed in the code accordingly, or,

b) "calibration mode": set the DDSfreq to ie. 10.000.000Hz output, pass it to DDS chip, do measure the DDS output freq (you may see something like "9.997.234Hz"), and do change the DDSclock value such until you see "10.000.000Hz" on the freqmeter (provided your freqmeter is precise enough), and do save the new DDSclock value somewhere.

I used that "calibration" mode with my DDS stuff I did long time back (so I did not care what the actual DDSclock freq was like, and, the actual DDSclock hex value was saved into an EEPROM after the calibration - btw. you can do the calibration anytime then, even when your DDS generator is already built into a nice shiny case :) )..

Go Up