本帖最后由 一路向北lm 于 2019-6-17 13:53 编辑
第二次调试
为了响应广大网友的号召,将采样点数增加10倍,一个周期内的点数为360个点。好多网友说正弦波可以采用查表的方式,对于方波、三角波、锯齿波就没有必要采用查表的方式了。这里我主要是采用DMA搬运列表数据到DA外设的方式,这样就不会占用CPU的资源了。为了后面的LCD和串口接受部分程序顺利执行,使用DMA搬运是比较好的方法。当然使用操作系统也可以,根据自己的方式,找到最适合自己的方法。 增加到360点的正弦波,matlab生成的波形和数据点如下,这样一看,哇!波形不错啊,不知道stm32可以增加到多少个点!360个点不少了!再多了,我怕DMA被累死了! %用于产生正弦数据表,输出到文件sinWave.c 文件中,复制到c语言数组即可
n = 2*pi/360 : 2*pi/360 : 2*pi %分成36等份
a = sin(n)+1; %求取sin函数值并向上平移一个单位,消除负数值
a = a * 3.3/2; %调整幅值,使范围限制为0~3.3
r = a* (2.^12) /3.3 %求取dac数值,12位dac LSB = 6.3/2.^12
r = uint16(r); %把double型数据转化成16位整型数据
for i = 1:360
if r(i) > 4095 %限制数据最大不超过4095
r(i) = 4095
end
end
dlmwrite('C:\Users\JY-LM\Desktop\21ic第三届大赛\波形发生器\教程提到的正弦波表制作脚本\matlab脚本\sinWave.c',r); %把数据写入到文件,方便添加到stm32工程中
plot(n,r,'.') %把这些点画出来
庞大的数据集………..DMA来也………. const uint16_t Sine12bit[POINT_NUM] =
{
2084,2119,2155,2191,2226,2262,2298,2333,2368,2404,
2439,2474,2509,2543,2578,2613,2647,2681,2715,2748,
2782,2815,2848,2881,2914,2946,2978,3009,3041,3072,
3103,3133,3163,3193,3223,3252,3281,3309,3337,3364,
3392,3418,3445,3471,3496,3521,3546,3570,3594,3617,
3640,3662,3684,3705,3726,3746,3766,3785,3803,3822,
3839,3856,3873,3889,3904,3919,3933,3947,3960,3972,
3984,3996,4007,4017,4026,4035,4044,4051,4058,4065,
4071,4076,4081,4085,4088,4091,4093,4095,4095,4095,
4095,4095,4093,4091,4088,4085,4081,4076,4071,4065,
4058,4051,4044,4035,4026,4017,4007,3996,3984,3972,
3960,3947,3933,3919,3904,3889,3873,3856,3839,3822,
3803,3785,3766,3746,3726,3705,3684,3662,3640,3617,
3594,3570,3546,3521,3496,3471,3445,3418,3392,3364,
3337,3309,3281,3252,3223,3193,3163,3133,3103,3072,
3041,3009,2978,2946,2914,2881,2848,2815,2782,2748,
2715,2681,2647,2613,2578,2543,2509,2474,2439,2404,
2368,2333,2298,2262,2226,2191,2155,2119,2084,2048,
2012,1977,1941,1905,1870,1834,1798,1763,1728,1692,
1657,1622,1587,1553,1518,1483,1449,1415,1381,1348,
1314,1281,1248,1215,1182,1150,1118,1087,1055,1024,
993, 963, 933, 903, 873, 844, 815, 787, 759, 732,
704, 678, 651, 625, 600, 575, 550, 526, 502, 479,
456, 434, 412, 391, 370, 350, 330, 311, 293, 274,
257, 240, 223, 207, 192, 177, 163, 149, 136, 124,
112, 100, 89, 79, 70, 61, 52, 45, 38, 31,
25, 20, 15, 11, 8, 5, 3, 1, 0, 0,
0, 1, 3, 5, 8, 11, 15, 20, 25, 31,
38, 45, 52, 61, 70, 79, 89, 100, 112, 124,
136, 149, 163, 177, 192, 207, 223, 240, 257, 274,
293, 311, 330, 350, 370, 391, 412, 434, 456, 479,
502, 526, 550, 575, 600, 625, 651, 678, 704, 732,
759, 787, 815, 844, 873, 903, 933, 963, 993, 1024,
1055,1087,1118,1150,1182,1215,1248,1281,1314,1348,
1381,1415,1449,1483,1518,1553,1587,1622,1657,1692,
1728,1763,1798,1834,1870,1905,1941,1977,2012,2048
};
从matlab 绘制的正弦波来看,还是有模有样的! 示波器输出波形如下,没看出来与36点的区别,方正现在可以称得上是正弦波了吧!
360点的正弦波
360点的方波
360点的三角波
360点的锯齿波
你怕,你怕,生活欺骗了你,所以你不敢想象,你不敢去尝试。如今,我尝试了,为什么波还是那个波,没有什么起色呢?也许是生活又欺骗了你吧!
|
666