基本用法 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)
定义DAC 初始化DAC
以指定频率,产生伪随机噪声信号
以指定频率产生三角波
写入参数。在8bits时,参数范围[0-255];在12bits时,参数范围[0..4095]
使用DMA方式周期写入数据
data,缓冲区数组 freq,默认使用Timer(6),用指定频率更新。也可以指定另外的定时器,有效的定时器是[2, 4, 5, 6, 7, 8]。 mode,DAC.NORMAL or DAC.CIRCULAR |