程序如下,各位老大看看行不?
unsigned long dds; unsigned long ddsold; unsigned long ddsadd;
void main(void) { dds = 0xFFFFFFFF; ddsadd = 0x00030303;
for(;;) { ddsold = dds; dds += ddsadd; if ( dds < ddsold){ PTBD_PTBD7 = ~PTBD_PTBD7; } } }
如你的mcu运算一个32位的加法是1uS,那以上程序就是一个分辨率0.000232831Hz,最大1MHz的DDS了,原理不详细解释了。
FFFFFFFF 除数(HEX) 除数(OCT) 商(要多少微秒溢出) 一秒钟有几微秒 频率 频率增量 4294967295 0x00000001 1 4294967295 1000000 0.000232831 4294967295 0x00000002 2 2147483648 1000000 0.000465661 0.000232831 4294967295 0x00000003 3 1431655765 1000000 0.000698492 0.000232831 4294967295 0x00000103 259 16582885.31 1000000 0.060303137 0.059604645 4294967295 0x00000203 515 8339742.32 1000000 0.119907782 0.059604645 4294967295 0x00000303 771 5570645 1000000 0.179512426 0.059604645 4294967295 0x00010303 66307 64773.96497 1000000 15.43830149 15.25878907 4294967295 0x00020303 131843 32576.37717 1000000 30.69709056 15.25878907 4294967295 0x00030303 197379 21760.00129 1000000 45.95587962 15.25878907 4294967295 0x01030303 16974595 253.0232559 1000000 3952.205881 3906.250001 4294967295 0x02030303 33751811 127.251462 1000000 7858.455881 3906.250001 4294967295 0x03030303 50529027 85 1000000 11764.70588 3906.250001 4294967295 0x13030303 318964483 13.46534653 1000000 74264.7059 62500.00001 4294967295 0x23030303 587399939 7.311827955 1000000 136764.7059 62500.00001 4294967295 0x33030303 855835395 5.018450183 1000000 199264.7059 62500.00001 4294967295 0x43030303 1124270851 3.820224718 1000000 261764.7059 62500.00001 4294967295 0x53030303 1392706307 3.083900226 1000000 324264.706 62500.00001 4294967295 0x63030303 1661141763 2.58555133 1000000 386764.706 62500.00001 4294967295 0x73030303 1929577219 2.225859247 1000000 449264.706 62500.00001 4294967295 0x83030303 2198012675 1.954022988 1000000 511764.706 62500.00001 4294967295 0x93030303 2466448131 1.741357234 1000000 574264.706 62500.00001 4294967295 0xA3030303 2734883587 1.570438799 1000000 636764.706 62500.00001 4294967295 0xB3030303 3003319043 1.430073606 1000000 699264.706 62500.00001 4294967295 0xC3030303 3271754499 1.312741312 1000000 761764.7061 62500.00001 4294967295 0xD3030303 3540189955 1.213202497 1000000 824264.7061 62500.00001 4294967295 0xE3030303 3808625411 1.127694859 1000000 886764.7061 62500.00001 4294967295 0xF3030303 4077060867 1.05344694 1000000 949264.7061 62500.00001
|