芯片是STM32F103VC
采样点是1305,DAC_OUT1产生正弦波20HZ.为什么产生的频率不稳定?请高手指点.谢谢!以下是我的编程,
#include "stm32f10x.h"
#define DAC_DHR12RD_Address 0x40007420
DAC_InitTypeDef DAC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
const uint16_t Sine12bit[1305] = {
2048 ,2058 ,2068 ,2078 ,2087 ,2097 ,2107 ,2117 ,2127 ,2137 ,2147 ,2156 ,2166 ,2176 ,2186 ,2196 ,
2206 ,2215 ,2225 ,2235 ,2245 ,2255 ,2265 ,2274 ,2284 ,2294 ,2304 ,2313 ,2323 ,2333 ,2343 ,2353 ,
2362 ,2372 ,2382 ,2391 ,2401 ,2411 ,2421 ,2430 ,2440 ,2450 ,2459 ,2469 ,2479 ,2488 ,2498 ,2507 ,
2517 ,2527 ,2536 ,2546 ,2555 ,2565 ,2574 ,2584 ,2594 ,2603 ,2613 ,2622 ,2631 ,2641 ,2650 ,2660 ,
2669 ,2679 ,2688 ,2697 ,2707 ,2716 ,2725 ,2735 ,2744 ,2753 ,2762 ,2772 ,2781 ,2790 ,2799 ,2808 ,
2817 ,2827 ,2836 ,2845 ,2854 ,2863 ,2872 ,2881 ,2890 ,2899 ,2908 ,2917 ,2926 ,2935 ,2944 ,2952 ,
2961 ,2970 ,2979 ,2988 ,2996 ,3005 ,3014 ,3023 ,3031 ,3040 ,3048 ,3057 ,3066 ,3074 ,3083 ,3091 ,
3100 ,3108 ,3116 ,3125 ,3133 ,3142 ,3150 ,3158 ,3167 ,3175 ,3183 ,3191 ,3199 ,3207 ,3216 ,3224 ,
3232 ,3240 ,3248 ,3256 ,3264 ,3272 ,3280 ,3287 ,3295 ,3303 ,3311 ,3319 ,3326 ,3334 ,3342 ,3349 ,
3357 ,3364 ,3372 ,3379 ,3387 ,3394 ,3402 ,3409 ,3417 ,3424 ,3431 ,3438 ,3446 ,3453 ,3460 ,3467 ,
3474 ,3481 ,3488 ,3495 ,3502 ,3509 ,3516 ,3523 ,3530 ,3537 ,3543 ,3550 ,3557 ,3563 ,3570 ,3577 ,
3583 ,3590 ,3596 ,3603 ,3609 ,3615 ,3622 ,3628 ,3634 ,3640 ,3647 ,3653 ,3659 ,3665 ,3671 ,3677 ,
3683 ,3689 ,3695 ,3701 ,3706 ,3712 ,3718 ,3723 ,3729 ,3735 ,3740 ,3746 ,3751 ,3757 ,3762 ,3768 ,
3773 ,3778 ,3783 ,3789 ,3794 ,3799 ,3804 ,3809 ,3814 ,3819 ,3824 ,3829 ,3834 ,3839 ,3843 ,3848 ,
3853 ,3857 ,3862 ,3867 ,3871 ,3876 ,3880 ,3884 ,3889 ,3893 ,3897 ,3902 ,3906 ,3910 ,3914 ,3918 ,
3922 ,3926 ,3930 ,3934 ,3937 ,3941 ,3945 ,3949 ,3952 ,3956 ,3960 ,3963 ,3967 ,3970 ,3973 ,3977 ,
3980 ,3983 ,3986 ,3990 ,3993 ,3996 ,3999 ,4002 ,4005 ,4008 ,4010 ,4013 ,4016 ,4019 ,4021 ,4024 ,
4027 ,4029 ,4032 ,4034 ,4036 ,4039 ,4041 ,4043 ,4045 ,4048 ,4050 ,4052 ,4054 ,4056 ,4058 ,4060 ,
4061 ,4063 ,4065 ,4067 ,4068 ,4070 ,4071 ,4073 ,4074 ,4076 ,4077 ,4078 ,4080 ,4081 ,4082 ,4083 ,
4084 ,4085 ,4086 ,4087 ,4088 ,4089 ,4090 ,4090 ,4091 ,4092 ,4092 ,4093 ,4094 ,4094 ,4094 ,4095 ,
4095 ,4095 ,4096 ,4096 ,4096 ,4096 ,4096 ,4096 ,4096 ,4096 ,4096 ,4095 ,4095 ,4095 ,4095 ,4094 ,4094 ,4093 ,
4093 ,4092 ,4092 ,4091 ,4090 ,4089 ,4089 ,4088 ,4087 ,4086 ,4085 ,4084 ,4083 ,4081 ,4080 ,4079 ,
4078 ,4076 ,4075 ,4074 ,4072 ,4071 ,4069 ,4067 ,4066 ,4064 ,4062 ,4060 ,4059 ,4057 ,4055 ,4053 ,
4051 ,4049 ,4047 ,4044 ,4042 ,4040 ,4038 ,4035 ,4033 ,4030 ,4028 ,4025 ,4023 ,4020 ,4017 ,4015 ,
4012 ,4009 ,4006 ,4003 ,4000 ,3997 ,3994 ,3991 ,3988 ,3985 ,3982 ,3978 ,3975 ,3972 ,3968 ,3965 ,
3961 ,3958 ,3954 ,3951 ,3947 ,3943 ,3939 ,3936 ,3932 ,3928 ,3924 ,3920 ,3916 ,3912 ,3908 ,3904 ,
3899 ,3895 ,3891 ,3887 ,3882 ,3878 ,3873 ,3869 ,3864 ,3860 ,3855 ,3850 ,3846 ,3841 ,3836 ,3831 ,
3827 ,3822 ,3817 ,3812 ,3807 ,3802 ,3796 ,3791 ,3786 ,3781 ,3776 ,3770 ,3765 ,3760 ,3754 ,3749 ,
3743 ,3738 ,3732 ,3726 ,3721 ,3715 ,3709 ,3703 ,3698 ,3692 ,3686 ,3680 ,3674 ,3668 ,3662 ,
3656 ,3650 ,3643 ,3637 ,3631 ,3625 ,3618 ,3612 ,3606 ,3599 ,3593 ,3586 ,3580 ,3573 ,3567 ,3560 ,
3553 ,3547 ,3540 ,3533 ,3526 ,3519 ,3513 ,3506 ,3499 ,3492 ,3485 ,3478 ,3471 ,3464 ,3456 ,3449 ,
3442 ,3435 ,3428 ,3420 ,3413 ,3406 ,3398 ,3391 ,3383 ,3376 ,3368 ,3361 ,3353 ,3345 ,3338 ,3330 ,
3322 ,3315 ,3307 ,3299 ,3291 ,3283 ,3276 ,3268 ,3260 ,3252 ,3244 ,3236 ,3228 ,3220 ,3212 ,3203 ,
3195 ,3187 ,3179 ,3171 ,3162 ,3154 ,3146 ,3137 ,3129 ,3121 ,3112 ,3104 ,3095 ,3087 ,3078 ,3070 ,
3061 ,3053 ,3044 ,3035 ,3027 ,3018 ,3009 ,3001 ,2992 ,2983 ,2974 ,2966 ,2957 ,2948 ,2939 ,2930 ,
2921 ,2912 ,2903 ,2894 ,2886 ,2876 ,2867 ,2858 ,2849 ,2840 ,2831 ,2822 ,2813 ,2804 ,2795 ,2785 ,
2776 ,2767 ,2758 ,2748 ,2739 ,2730 ,2721 ,2711 ,2702 ,2693 ,2683 ,2674 ,2664 ,2655 ,2646 ,2636 ,
2627 ,2617 ,2608 ,2598 ,2589 ,2579 ,2570 ,2560 ,2551 ,2541 ,2531 ,2522 ,2512 ,2503 ,2493 ,2483 ,
2474 ,2464 ,2454 ,2445 ,2435 ,2425 ,2416 ,2406 ,2396 ,2387 ,2377 ,2367 ,2357 ,2348 ,2338 ,2328 ,
2318 ,2309 ,2299 ,2289 ,2279 ,2269 ,2260 ,2250 ,2240 ,2230 ,2220 ,2211 ,2201 ,2191 ,2181 ,2171 ,
2161 ,2151 ,2142 ,2132 ,2122 ,2112 ,2102 ,2092 ,2083 ,2073 ,2063 ,2053 ,2043 ,2033 ,2023 ,2013 ,
2004 ,1994 ,1984 ,1974 ,1964 ,1954 ,1945 ,1935 ,1925 ,1915 ,1905 ,1895 ,1885 ,1876 ,1866 ,1856 ,
1846 ,1836 ,1827 ,1817 ,1807 ,1797 ,1787 ,1778 ,1768 ,1758 ,1748 ,1739 ,1729 ,1719 ,1709 ,1700 ,
1690 ,1680 ,1671 ,1661 ,1651 ,1642 ,1632 ,1622 ,1613 ,1603 ,1593 ,1584 ,1574 ,1565 ,1555 ,1545 ,
1536 ,1526 ,1517 ,1507 ,1498 ,1488 ,1479 ,1469 ,1460 ,1450 ,1441 ,1432 ,1422 ,1413 ,1403 ,1394 ,
1385 ,1375 ,1366 ,1357 ,1348 ,1338 ,1329 ,1320 ,1311 ,1301 ,1292 ,1283 ,1274 ,1265 ,1256 ,1247 ,1238 ,
1229 ,1220 ,1211 ,1202 ,1193 ,1184 ,1175 ,1166 ,1157 ,1148 ,1139 ,1130 ,1122 ,1113 ,1104 ,1095 ,
1087 ,1078, 1069 ,1061 ,1052 ,1043 ,1035 ,1026 ,1018 ,1009 ,1001 ,992 ,984 ,975 ,967 ,959 ,
950 ,942 ,934 ,925 ,917 ,909 ,901 ,893 ,884 ,876 ,868 ,860 ,852 ,844 ,836 ,828 ,
820 ,813 ,805 ,797 ,789 ,781 ,774 ,766 ,758 ,751 ,743 ,735 ,728 ,720 ,713 ,705 ,
698 ,690 ,683 ,676 ,668 ,661 ,654 ,647 ,640 ,632 ,625 ,618 ,611 ,604 ,597 ,590 ,
583 ,577 ,570 ,563 ,556 ,549 ,543 ,536 ,529 ,523 ,516 ,510 ,503 ,497 ,490 ,484 ,
478 ,471 ,465 ,459 ,453 ,446 ,440 ,434 ,428 ,422 ,416 ,410 ,404 ,398 ,393 ,387 ,
381 ,375 ,370 ,364 ,358 ,353 ,347 ,342 ,336 ,331 ,326 ,320 ,315 ,310 ,305 ,300 ,
294 ,289 ,284 ,279 ,274 ,269 ,265 ,260 ,255 ,250 ,246 ,241 ,236 ,232 ,227 ,223 ,
218 ,214 ,209 ,205 ,201 ,197 ,192 ,188 ,184 ,180 ,176 ,172 ,168 ,164 ,160 ,157 ,
153 ,149 ,145 ,142 ,138 ,135 ,131 ,128 ,124 ,121 ,118 ,114 ,111 ,108 ,105 ,102 ,
99 ,96 ,93 ,90 ,87 ,84 ,81 ,79 ,76 ,73 ,71 ,68 ,66 ,63 ,61 ,58 ,
56 ,54 ,52 ,49 ,47 ,45 ,43 ,41 ,39 ,37 ,36 ,34 ,32 ,30 ,29 ,27 ,
25 ,24 ,22 ,21 ,20 ,18 ,17 ,16 ,15 ,13 ,12 ,11 ,10 ,9 ,8 ,7 ,
7 ,6 ,5 ,4 ,4 ,3 ,3 ,2 ,2 ,1 ,1 ,1 ,1 ,
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
1 ,1 ,1 ,2 ,2 ,2 ,3 ,4 ,4 ,5 ,
6 ,6 ,7 ,8 ,9 ,10,11 ,12 ,13 ,14 ,15 ,16 ,18 ,19 ,20 ,22 ,
23 ,25 ,26 ,28 ,29 ,31 ,33 ,35 ,36 ,38 ,40 ,42 ,44 ,46 ,48 ,51 ,
53 ,55 ,57 ,60 ,62 ,64 ,67 ,69 ,72 ,75 ,77 ,80 ,83 ,86 ,88 ,91 ,
94 ,97 ,100,103, 106,110 ,113 ,116 ,119 ,123 ,126 ,129 ,133 ,136 ,140 ,144 ,
147 ,151 ,155 ,158 ,162 ,166 ,170 ,174 ,178 ,182 ,186 ,190 ,194 ,199 ,203 ,207 ,
212 ,216 ,220 ,225 ,229 ,234 ,239 ,243 ,248 ,253 ,257 ,262 ,267 ,272 ,277 ,282 ,
287 ,292, 297 ,302 ,307 ,313 ,318 ,323 ,328 ,334 ,339 ,345 ,350 ,356 ,361 ,367 ,
372 ,378 ,384 ,390 ,395 ,401 ,407 ,413 ,419 ,425 ,431 ,437 ,443 ,449 ,456 ,462 ,
468 ,474 ,481 ,487 ,493 ,500 ,506 ,513 ,519 ,526 ,533 ,539 ,546 ,553 ,559 ,566 ,
573 ,580 ,587 ,594 ,601 ,608 ,615 ,622 ,629 ,636 ,643 ,650 ,658 ,665 ,672 ,679 ,
687 ,694 ,702 ,709 ,717 ,724 ,732 ,739 ,747 ,754 ,762 ,770 ,777 ,785 ,793 ,801 ,
809 ,816 ,824 ,832 ,840 ,848 ,856 ,864 ,872 ,880 ,888 ,897 ,905 ,913 ,921 ,929 ,
938 ,946 ,954 ,963 ,971 ,979 ,988 ,996 ,1005,101,1022,1030, 1039,1048, 1056,1065,
1073,1082, 1091,1100 ,1108 ,1117 ,1126 ,1135 ,1144 ,1152 ,1161 ,1170 ,1179 ,1188 ,1197 ,1206 ,
1215 ,1224 ,1233 ,1242 ,1251 ,1260 ,1269 ,1279,1288 ,1297 ,1306 ,1315 ,1324 ,1334 ,1343 ,1352 ,
1361 ,1371 ,1380 ,1389 ,1399 ,1408 ,1417 ,1427 ,1436 ,1446 ,1455 ,1465 ,1474 ,1483 ,1493 ,1502 ,
1512 ,1522 ,1531 ,1541 ,1550 ,1560 ,1569 ,1579 ,1588 ,1598 ,1608 ,1617 ,1627 ,1637 ,1646 ,1656 ,
1666 ,1675 ,1685 ,1695 ,1705 ,1714 ,1724 ,1734 ,1743 ,1753 ,1763 ,1773 ,1783 ,1792 ,1802 ,1812 ,
1822 ,1831 ,1841 ,1851 ,1861 ,1871 ,1881 ,1890 ,1900 ,1910 ,1920 ,1930 ,1940 ,1949 ,1959 ,1969 ,
1979 ,1989 ,1999 ,2009 ,2018 ,2028 ,2038
};
uint32_t DualSine12bit[1305];
uint16_t Idx = 0;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void Delay(__IO uint32_t nCount);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* System Clocks Configuration */
RCC_Configuration();
/* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
connected to the DAC converter. In order to avoid parasitic consumption,
the GPIO pin should be configured in analog */
GPIO_Configuration();
/* TIM2 Configuration */
/* Time base configuration */
//TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period =1;
TIM_TimeBaseStructure.TIM_Prescaler = 1379;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
/* TIM2 TRGO selection */
TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);
/* DAC channel1 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;
DAC_InitStructure.DAC_WaveGeneration =DAC_WaveGeneration_Triangle ; //DAC_WaveGeneration_None
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* DAC channel2 Configuration */
// DAC_Init(DAC_Channel_2, &DAC_InitStructure); xiaolin
/* Fill Sine32bit table */
// for (Idx = 0; Idx < 32; Idx++) xiaolin
// for (Idx = 0; Idx < 255; Idx++)
for (Idx = 0; Idx < 1305; Idx++)
{
DualSine12bit[Idx] = (Sine12bit[Idx] |