0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

4chデジタルポテンションメーター「AD5363」を使う

Last updated at Posted at 2022-05-21

はじめに
アナデバの4chデジタルポテンションメーター(デジタル可変抵抗)を使ったので使い方を書く
複数のオペアンプの入力バイアス電圧を同時に変更する時などに便利だ。
(ちなみにアナログの可変抵抗器は3ch以上の物は売っていなかった)

参考サイト様
デジタルポテンショメータの使い方(AD5820BRU20)

使用部材
・AD5263BRUZ50(デジタルポテンションメーター,4ch,50kΩ)
・XIAO RP2040(マイコン)
・抵抗 4.7kΩ

動作確認
AD5623は下図の通り、A1,W1,B1~A4,W4,B4の4chで構成されており、可変抵抗部に印加可能な電圧は0V~+15Vまたは-5V~+5Vとなっている。

スクリーンショット 2022-05-21 205527.png
まずは0~15Vの範囲で使用したい時の回路図は以下の通り
スクリーンショット 2022-05-21 204026.png

とりあえず動かす時のプログラム
抵抗値を変えるときはvalの変数を適当に変える

#include <Arduino.h>
#include <Wire.h>

byte val = 100;
const int ADD0 = 0;
const int ADD1 = 27;
const int DIS = 4;
//AD5263のI2Cアドレス
const byte AD5263 = 0x2C;

void setup()
{
  //AD5263のpin13,14のAD0,AD1はLow
  pinMode(ADD0, OUTPUT);
  digitalWrite(ADD0, LOW);
  pinMode(ADD1, OUTPUT);
  digitalWrite(ADD1, LOW);
  //書き込みはI2C
  pinMode(DIS, OUTPUT);
  digitalWrite(DIS, HIGH);
  Wire.begin();
  Serial.begin(115200);
  while (!Serial)
    ;
  Serial.println("シリアル通信Start");
}

void loop()
{
    //ch1
    Potentiometer_write(0x00 , val);
    //ch2
    Potentiometer_write(0x20 , val);
    //ch3
    Potentiometer_write(0x40 , val);
    //ch4
    Potentiometer_write(0x60 , val);
  delay(10);
}

//I2C書き込みの関数化
void Potentiometer_write(byte Inst , byte Data)
{
  Wire.beginTransmission(AD5263);
  Wire.write(Inst);
  Wire.write(Data);
  Wire.endTransmission();
}

I2Cの書き込み部は以下を参照
I2C書き込みモードの
Slave Address Byteは0x2C
InstructionByteは0x00(ch1)、0x20(ch2)、0x40(ch3)、0x60(ch4)
DataByteは設定したい抵抗値0~256の好きな値を入れる
スクリーンショット 2022-05-21 211307.png

ロータリーエンコーダで動かす
今回やりたい事は最大±5.0Vの信号の波高値を変更したい事なので、ロータリーエンコーダで抵抗を可変させていく
また、信号は-5Vの負電圧も扱うので、AD5623のVSSはGNDではなく、-5Vに接続する。
また、回路図には書き忘れたが、実際にはch2,ch3にも信号を入力している

回路図
スクリーンショット 2022-05-21 213602.png

プログラム
ロータリーエンコーダのライブラリは多分これ
https://github.com/mathertel/RotaryEncoder

#include <Arduino.h>
#include <RotaryEncoder.h>
#include <Wire.h>

#define ENC_A 1
#define ENC_B 2

int Pos = 100;
int newPos;
// Setup a RotaryEncoder with 2 steps per latch for the 2 signal input pins:
RotaryEncoder encoder(ENC_A, ENC_B, RotaryEncoder::LatchMode::TWO03);

byte val = 100;
const int ADD0 = 0;
const int ADD1 = 27;
const int DIS = 4;
const byte AD5263 = 0x2C;

void setup()
{
  pinMode(ADD0, OUTPUT);
  digitalWrite(ADD0, LOW);
  pinMode(ADD1, OUTPUT);
  digitalWrite(ADD1, LOW);
  pinMode(DIS, OUTPUT);
  digitalWrite(DIS, HIGH);
  Wire.begin();
  Serial.begin(115200);
  while (!Serial)
    ;
  Serial.println("シリアル通信Start");
  Serial.println(val);

}

void loop()
{
  encoder.tick();
  //前回のポジション(Pos)の値から値が変更された時、ENCを回したと判断する
  newPos = encoder.getPosition();
  if (Pos != newPos)
  {

    if (newPos < Pos)
    {
      val = val - 5;
      if (val < 6)
      {
        //値が0以下にならないように
        val = 5;
      }
    }

    if (newPos > Pos)
    {
      val = val + 5;
      if (val > 250)
      {
        //値が256以上にならないように
        val = 250;
      }
    }
    Pos = newPos;
    Potentiometer_write(0x00 , val);
    Potentiometer_write(0x20 , val);
    Potentiometer_write(0x40 , val);
    Serial.println(val);
  }
  delay(10);
}

//I2C書き込みの関数化
void Potentiometer_write(byte Inst , byte Data)
{
  Wire.beginTransmission(AD5263);
  Wire.write(Inst);
  Wire.write(Data);
  Wire.endTransmission();
}

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?