zoukankan      html  css  js  c++  java
  • DAC的使用用法

    基本用法
    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

  • 相关阅读:
    读你必须知道的.NET(二)
    读你必须知道的.NET(四)
    读你必须知道的.NET(三)
    顺序表(线性表)操作的思想及实现之C#版
    HBase原理、基本概念、基本架构3
    HBase学习之深入理解Memstore6
    hadoop学习笔记之hbase完全分布模式安装5
    hbase学习 rowKey的设计4
    WPF开源收集
    请注释你那该死的代码(转载类)
  • 原文地址:https://www.cnblogs.com/xxosu/p/9075320.html
Copyright © 2011-2022 走看看