欢迎访问:dacmax505使用方法_科技生活_生活服务_自居生活网
  • 微信客服微信客服
  • 微信公众号微信公众号

dacmax505使用方法

收藏  分享
网友发布网友发布

dacmax505使用方法

基本用法

from pyb import DAC

dac = DAC(1) # create DAC 1 on pin X5

dac.write(128) # write a value to the DAC (makes X5 1.65V)

dac = DAC(1, bits=12) # use 12 bit resolution

dac.write(4095) # output maximum value, 3.3V

输出正弦波

import math

from pyb import DAC

# create a buffer containing a sine-wave

buf = bytearray(100)

for i in range(len(buf)):

buf = 128 + int(127 * math.sin(2 * math.pi * i / len(buf)))

# output the sine-wave at 400Hz

dac = DAC(1)

dac.write_timed(buf, 400 * len(buf), mode=DAC.CIRCULAR)

输出12位精度正弦波

import math

from array import array

from pyb import DAC

# create a buffer containing a sine-wave, using half-word samples

buf = array('H', 2048 + int(2047 * math.sin(2 * math.pi * i / 128)) for i in range(128))

# output the sine-wave at 400Hz

dac = DAC(1, bits=12)

dac.write_timed(buf, 400 * len(buf), mode=DAC.CIRCULAR)

class pyb.DAC(port, bits=8)

定义DAC

port,1或2,对应X5(PA4)/X6(PA5)

bits,输出精度,可以是8或12

dac.init(bits=8)

初始化DAC

dac.noise(freq)

以指定频率,产生伪随机噪声信号

dac.triangle(freq)

以指定频率产生三角波

dac.write(value)

写入参数。在8bits时,参数范围[0-255];在12bits时,参数范围[0..4095]

dac.write_timed(data, freq, *, mode=DAC.NORMAL)

使用DMA方式周期写入数据

data,缓冲区数组

freq,默认使用Timer(6),用指定频率更新。也可以指定另外的定时器,有效的定时器是[2, 4, 5, 6, 7, 8]

mode,DAC.NORMAL or DAC.CIRCULAR

标签: 噪声 也可以 用法
 
更多>最新的资讯
推荐图文
推荐生活服务
点击排行