4345|5

73

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

单片机数模转换输出正弦波的问题? [复制链接]

怎样计算正弦波?把正弦波的采样坐标点放到一个数组里,然后如何实现正弦波的输出?
下面有一个公式望各位大侠给菜鸟指导一下,谢谢!
y=sin(3.1415*2*i/256)*2048+2048(注:256为数组的大小)
请问2048是什么意思?为什么要乘上它?麻烦给菜鸟解释一下这个公式。

最新回复

正解 lz用MATLAB吧! 计算起来很方便的! 兄弟帮你入门! 以下为MATLAB命令行:(以下计算为256个数据,半个周期,赋值为0~2048) >>a=(-pi/2):pi/255:(pi/2) >>b=sin(a) >>c=b*1024+1024 >>d=floor(c) 结果如下: 0,0,0,0,1,1,2,3,4,6,7,9,11,13,15,17,19,22,25,27,30,34,37,40,44,48,52,56,60,64,69,73,78,83,88,93,99,104,110,115,121,127,134,140,146,153,160,166,173,180,188,195,203,210,218,226,234,242,250,258,267,275,284,293,302,311,320,329,338,348,357,367,377,386,396,406,417,427,437,447,458,468,479,490,501,512,522,534,545,556,567,578,590,601,613,624,636,648,659,671,683,695,707,719,731,743,755,768,780,792,804,817,829,842,854,866,879,891,904,916,929,942,954,967,979,992,1005,1017,1030,1042,1055,1068,1080,1093,1105,1118,1131,1143,1156,1168,1181,1193,1205,1218,1230,1243,1255,1267,1279,1292,1304,1316,1328,1340,1352,1364,1376,1388,1399,1411,1423,1434,1446,1457,1469,1480,1491,1502,1513,1525,1536,1546,1557,1568,1579,1589,1600,1610,1620,1630,1641,1651,1661,1670,1680,1690,1699,1709,1718,1727,1736,1745,1754,1763,1772,1780,1789,1797,1805,1813,1821,1829,1837,1844,1852,1859,1867,1874,1881,1887,1894,1901,1907,1913,1920,1926,1932,1937,1943,1948,1954,1959,1964,1969,1974,1978,1983,1987,1991,1995,1999,2003,2007,2010,2013,2017,2020,2022,2025,2028,2030,2032,2034,2036,2038,2040,2041,2043,2044,2045,2046,2046,2047,2047,2047,2048  详情 回复 发表于 2009-8-12 10:59
点赞 关注

回复
举报

80

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
2048,该是和它的DA的分辨率有关...因为sin计算的结果有负值,所以要加上一个偏移(2048),
它的DA有12-BIT,接受0-4095的输入数值...
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
y=sin(3.1415*2*i/256)*2048+2048
一般按这个公式把i从0到255对应的值计算出来存放到一个表里面,然后在Timer中断里面把这个表里面的数值依次送给DA,DA的输出就是sin波形了.
 
 
 

回复

66

帖子

0

TA的资源

一粒金砂(初级)

4
 
我直接做了一个软件,专门算正弦波,方波的查找表的。任意位数的da,任意的采样数都可以直接生成数组
 
 
 

回复

72

帖子

0

TA的资源

一粒金砂(初级)

5
 
这软件给我用下行不,谢谢!yanhuoyuan8812@yahoo.cn
 
 
 

回复

68

帖子

0

TA的资源

一粒金砂(初级)

6
 
引用 1 楼 great_bug 的回复:
2048,该是和它的DA的分辨率有关...因为sin计算的结果有负值,所以要加上一个偏移(2048),
它的DA有12-BIT,接受0-4095的输入数值...


正解

lz用MATLAB吧!
计算起来很方便的!

兄弟帮你入门!

以下为MATLAB命令行:(以下计算为256个数据,半个周期,赋值为0~2048)

>>a=(-pi/2):pi/255:(pi/2)
>>b=sin(a)
>>c=b*1024+1024
>>d=floor(c)

结果如下:
0,0,0,0,1,1,2,3,4,6,7,9,11,13,15,17,19,22,25,27,30,34,37,40,44,48,52,56,60,64,69,73,78,83,88,93,99,104,110,115,121,127,134,140,146,153,160,166,173,180,188,195,203,210,218,226,234,242,250,258,267,275,284,293,302,311,320,329,338,348,357,367,377,386,396,406,417,427,437,447,458,468,479,490,501,512,522,534,545,556,567,578,590,601,613,624,636,648,659,671,683,695,707,719,731,743,755,768,780,792,804,817,829,842,854,866,879,891,904,916,929,942,954,967,979,992,1005,1017,1030,1042,1055,1068,1080,1093,1105,1118,1131,1143,1156,1168,1181,1193,1205,1218,1230,1243,1255,1267,1279,1292,1304,1316,1328,1340,1352,1364,1376,1388,1399,1411,1423,1434,1446,1457,1469,1480,1491,1502,1513,1525,1536,1546,1557,1568,1579,1589,1600,1610,1620,1630,1641,1651,1661,1670,1680,1690,1699,1709,1718,1727,1736,1745,1754,1763,1772,1780,1789,1797,1805,1813,1821,1829,1837,1844,1852,1859,1867,1874,1881,1887,1894,1901,1907,1913,1920,1926,1932,1937,1943,1948,1954,1959,1964,1969,1974,1978,1983,1987,1991,1995,1999,2003,2007,2010,2013,2017,2020,2022,2025,2028,2030,2032,2034,2036,2038,2040,2041,2043,2044,2045,2046,2046,2047,2047,2047,2048
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表