Arduino与Proteus仿真实例-AD5206数字电位计驱动仿真 AD5206数字电位计驱动仿真 1、AD5206/介绍 AD5206 提供 4 通道/6 通道、256 位数控可变电阻器 (VR) 器件。 这些设备执行与电位计或可变电阻器相同的电子调节功能。 AD5206 的每个通道都包含一个带有滑动触点的固定电阻器,该触点在由加载到 SPI 兼容串行输入寄存器中的数字代码确定的点上分接固定电阻器值。 游标和固定电阻器的任一端点之间的电阻相对于传输到 VR 锁存器的数字代码呈线性变化。 可变电阻器在 A 端子和游标之间或 B 端子和游标之间提供完全可编程的电阻值。 10 kΩ、50 kΩ 或 100 kΩ 的固定 A 到 B 终端电阻具有 700 ppm/°C 的标称温度系数。
每个 VR 都有自己的 VR 锁存器,用于保存其编程电阻值。 这些 VR 锁存器由从标准 3 线串行输入数字接口加载的内部串行到并行移位寄存器更新。 11 个数据位组成了时钟输入串行输入寄存器的数据字。 当 CS 选通返回逻辑高电平时,前三位被解码以确定哪个 VR 锁存器加载数据字的最后八位。 串行寄存器另一端的串行数据输出引脚(仅限 AD5204)允许在多个 VR 应用中进行简单的菊花链连接,而无需额外的外部解码逻辑。
AD5206的引脚功能如下:
2、仿真电路原理图
3、仿真代码实现 本次实例使用到如下开源库:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 // // FILE: AD5204\_demo\_HWSPI.ino // AUTHOR: Rob Tillaart // PURPOSE: demo // DATE: 2021-08-19 // URL: https://github.com/RobTillaart/AD520X #include "AD520X.h" uint32\_t start, stop; // param: select, reset, shutdown, data, clock // AD5204 pot(10, 255, 255, 8, 9); // SW SPI AD5206 pot = AD5206(10, 12, 13); // HW SPI void setup() { Serial.begin(9600); //Serial.println(\_\_FILE\_\_); Serial.print("AD520X\_LIB\_VERSION:\t"); Serial.println(AD520X_LIB_VERSION); pot.begin(6); pot.setSPIspeed(16000000); /\* Serial.print("\tusesHWSPI:\t"); Serial.println(pot.usesHWSPI()); pot.setSPIspeed(500000); test\_timing(); pot.setSPIspeed(1000000); test\_timing(); pot.setSPIspeed(2000000); test\_timing(); pot.setSPIspeed(4000000); test\_timing(); pot.setSPIspeed(8000000); test\_timing(); pot.setSPIspeed(16000000); // no effect on 16 MHz UNO test\_timing(); Serial.println("\nDone...");\*/ } void loop() { test\_sinus(); } // connect all A GND and B 5V // every W will have a different signal (same freq). void test\_sinus() { //Serial.println(\_\_FUNCTION\_\_); //delay(10); start = millis(); uint32\_t i = 0; while (millis() - start < 500) { uint8\_t value = 127 \* sin(i \* TWO_PI / 100); pot.setValue(0, 128 + value); pot.setValue(1, 128 + value / 2); pot.setValue(2, 64 + value / 2); pot.setValue(3, 192 + value / 2); pot.setValue(4, 224 + value / 4); pot.setValue(5, 128 - value); Serial.print("port 0 :"); Serial.println(pot.getValue(0)); Serial.print("port 1 :"); Serial.println(pot.getValue(1)); Serial.print("port 2 :"); Serial.println(pot.getValue(2)); Serial.print("port 3 :"); Serial.println(pot.getValue(3)); Serial.print("port 4 :"); Serial.println(pot.getValue(4)); Serial.print("port 5 :"); Serial.println(pot.getValue(5)); Serial.print("port 6 :"); Serial.println(pot.getValue(6)); i++; } }
4、仿真结果
文章来源: https://iotsmart.blog.csdn.net/article/details/121652808
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!