Skip to content
LIBRARY
Analog.Basic.Tests.Potentiometer.md

Analog.Basic.Tests.Potentiometer

Test circuit for Potentiometer.

A constant 10 V source is applied across pin_p and pin_n of a 100 Ω potentiometer. A 1 kΩ load resistor is connected from the contact (wiper) to ground. The wiper position ramps from 0 to 1 over 1 s.

At r=0 the contact is at pin_n (ground), so V_contact ≈ 0 V. At r=1 the contact is at pin_p, and V_contact = V_source * R_load / (Rp + R_load) where Rp → 0 as r → 1, so V_contact → 10 V.

A small capacitor across the load provides a differential state.

Usage

ElectricalComponents.Analog.Basic.Tests.Potentiometer()

Behavior

[connect(constsig+y,vs+V)connect(vs+p,pot+pinp)connect(vs+n,ground+g)connect(pot+pinn,ground+g)connect(Rload+n,cap+n,ground+g)connect(ramp+y,pot+r)connect(fixedtemp+port,pot+heatport)connect(pot+contact,Rload+p,cap+p)constsig.y(t)=constsig.kvs.v(t)=vs.n.v(t)+vs.p.v(t)vs.i(t)=vs.p.i(t)vs.n.i(t)+vs.p.i(t)=0vs.v(t)=vs.uVvs.V(t)pot.pinn.i(t)+pot.contact.i(t)+pot.pinp.i(t)=0pot.Rp(t)=pot.R(1+(pot.Tref+pot.heatport.T(t))pot.alpha)(1min(1,max(0,pot.r(t))))pot.Rn(t)=pot.R(1+(pot.Tref+pot.heatport.T(t))pot.alpha)min(1,max(0,pot.r(t)))pot.pinp.v(t)pot.contact.v(t)=pot.Rp(t)pot.pinp.i(t)pot.contact.v(t)+pot.pinn.v(t)=pot.pinn.i(t)pot.Rn(t)pot.LossPower(t)=pot.pinn.i(t)(pot.contact.v(t)+pot.pinn.v(t))+pot.pinp.i(t)(pot.pinp.v(t)pot.contact.v(t))pot.heatport.Q_flow(t)=pot.LossPower(t)Rload.v(t)=Rload.n.v(t)+Rload.p.v(t)Rload.i(t)=Rload.p.i(t)Rload.n.i(t)+Rload.p.i(t)=0Rload.v(t)=Rload.RRload.i(t)cap.v(t)=cap.n.v(t)+cap.p.v(t)cap.i(t)=cap.p.i(t)cap.p.i(t)+cap.n.i(t)=0cap.Cdcap.v(t)dt=cap.i(t)ramp.y(t)=ifelse(ramp.starttime<t,ifelse(t<ramp.duration+ramp.starttime,ramp.offset+ramp.height(ramp.starttime+t)ramp.duration,ramp.height+ramp.offset),ramp.offset)fixedtemp.port.T(t)=fixedtemp.Tground.g.v(t)=0]

Source

dyad
"""
Test circuit for Potentiometer.

A constant 10 V source is applied across pin_p and pin_n of a 100 Ω
potentiometer. A 1 kΩ load resistor is connected from the contact
(wiper) to ground. The wiper position ramps from 0 to 1 over 1 s.

At r=0 the contact is at pin_n (ground), so V_contact ≈ 0 V.
At r=1 the contact is at pin_p, and V_contact = V_source * R_load / (Rp + R_load)
where Rp → 0 as r → 1, so V_contact → 10 V.

A small capacitor across the load provides a differential state.
"""
test component Potentiometer
  "Constant signal: 10 V"
  const_sig = BlockComponents.Sources.Constant(k = 10) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -20, "y1": 380, "x2": 80, "y2": 480, "rot": 0}
      },
      "tags": []
    }
  }
  "Voltage source"
  vs = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 480, "x2": 220, "y2": 380, "rot": 90}
      },
      "tags": []
    }
  }
  "Potentiometer under test (100 Ω)"
  pot = ElectricalComponents.Analog.Basic.Potentiometer(R = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 410, "x2": 550, "y2": 310, "rot": 0}
      },
      "tags": []
    }
  }
  "Load resistor (1 kΩ) on wiper"
  R_load = ElectricalComponents.Analog.Basic.Resistor(R = 1000) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 500, "x2": 450, "y2": 600, "rot": 270}
      },
      "tags": []
    }
  }
  "Small capacitor for dynamics"
  cap = ElectricalComponents.Analog.Basic.Capacitor(C = 1e-6) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 740, "y1": 500, "x2": 640, "y2": 600, "rot": 270}
      },
      "tags": []
    }
  }
  "Ramp for wiper position: 0.01 to 0.99 over 1 s"
  ramp = BlockComponents.Sources.Ramp(height = 0.98, offset = 0.01, duration = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 220, "x2": 290, "y2": 320, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed temperature for thermal port"
  fixed_temp = ThermalComponents.Sources.FixedTemperature(T = 293.15) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 90, "x2": 550, "y2": 190, "rot": 90}
      },
      "tags": []
    }
  }
  "Ground reference"
  ground = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 840, "x2": 550, "y2": 940, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial cap.v = 0
  guess pot.pin_p.i = 0.1
  guess pot.pin_n.i = 0
  guess pot.contact.i = 0
  connect(const_sig.y, vs.V) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(vs.p, pot.pin_p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 170, "y": 360}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(vs.n, ground.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 170, "y": 810}, {"x": 500, "y": 810}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(pot.pin_n, ground.g) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 870, "y": 360}, {"x": 870, "y": 810}, {"x": 500, "y": 810}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(R_load.n, cap.n, ground.g) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 500, "y": 625}], "E": -1},
        {"S": -1, "M": [{"x": 690, "y": 625}], "E": 2},
        {"S": 3, "M": [{"x": 500, "y": 732.5}, {"x": 590, "y": 732.5}], "E": -1}
      ],
      "junctions": [{"x": 590, "y": 625}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, pot.r) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 450, "y": 270}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(fixed_temp.port, pot.heat_port) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(pot.contact, R_load.p, cap.p) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 550, "y": 260}, {"x": 640, "y": 260}, {"x": 640, "y": 450}],
          "E": -1
        },
        {"S": -1, "M": [{"x": 500, "y": 450}], "E": 2},
        {"S": 3, "M": [{"x": 690, "y": 450}], "E": -1}
      ],
      "junctions": [{"x": 550, "y": 450}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["pot.contact.v", "pot.Rp", "pot.Rn", "R_load.i"]}
      }
    }
  }
}
end
Flattened Source
dyad
"""
Test circuit for Potentiometer.

A constant 10 V source is applied across pin_p and pin_n of a 100 Ω
potentiometer. A 1 kΩ load resistor is connected from the contact
(wiper) to ground. The wiper position ramps from 0 to 1 over 1 s.

At r=0 the contact is at pin_n (ground), so V_contact ≈ 0 V.
At r=1 the contact is at pin_p, and V_contact = V_source * R_load / (Rp + R_load)
where Rp → 0 as r → 1, so V_contact → 10 V.

A small capacitor across the load provides a differential state.
"""
test component Potentiometer
  "Constant signal: 10 V"
  const_sig = BlockComponents.Sources.Constant(k = 10) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -20, "y1": 380, "x2": 80, "y2": 480, "rot": 0}
      },
      "tags": []
    }
  }
  "Voltage source"
  vs = ElectricalComponents.Analog.Sources.VoltageSource() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 480, "x2": 220, "y2": 380, "rot": 90}
      },
      "tags": []
    }
  }
  "Potentiometer under test (100 Ω)"
  pot = ElectricalComponents.Analog.Basic.Potentiometer(R = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 410, "x2": 550, "y2": 310, "rot": 0}
      },
      "tags": []
    }
  }
  "Load resistor (1 kΩ) on wiper"
  R_load = ElectricalComponents.Analog.Basic.Resistor(R = 1000) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 500, "x2": 450, "y2": 600, "rot": 270}
      },
      "tags": []
    }
  }
  "Small capacitor for dynamics"
  cap = ElectricalComponents.Analog.Basic.Capacitor(C = 1e-6) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 740, "y1": 500, "x2": 640, "y2": 600, "rot": 270}
      },
      "tags": []
    }
  }
  "Ramp for wiper position: 0.01 to 0.99 over 1 s"
  ramp = BlockComponents.Sources.Ramp(height = 0.98, offset = 0.01, duration = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 220, "x2": 290, "y2": 320, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed temperature for thermal port"
  fixed_temp = ThermalComponents.Sources.FixedTemperature(T = 293.15) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 90, "x2": 550, "y2": 190, "rot": 90}
      },
      "tags": []
    }
  }
  "Ground reference"
  ground = ElectricalComponents.Analog.Basic.Ground() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 840, "x2": 550, "y2": 940, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial cap.v = 0
  guess pot.pin_p.i = 0.1
  guess pot.pin_n.i = 0
  guess pot.contact.i = 0
  connect(const_sig.y, vs.V) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(vs.p, pot.pin_p) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 170, "y": 360}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(vs.n, ground.g) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 170, "y": 810}, {"x": 500, "y": 810}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(pot.pin_n, ground.g) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 870, "y": 360}, {"x": 870, "y": 810}, {"x": 500, "y": 810}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(R_load.n, cap.n, ground.g) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 500, "y": 625}], "E": -1},
        {"S": -1, "M": [{"x": 690, "y": 625}], "E": 2},
        {"S": 3, "M": [{"x": 500, "y": 732.5}, {"x": 590, "y": 732.5}], "E": -1}
      ],
      "junctions": [{"x": 590, "y": 625}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, pot.r) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 450, "y": 270}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(fixed_temp.port, pot.heat_port) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(pot.contact, R_load.p, cap.p) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 550, "y": 260}, {"x": 640, "y": 260}, {"x": 640, "y": 450}],
          "E": -1
        },
        {"S": -1, "M": [{"x": 500, "y": 450}], "E": 2},
        {"S": 3, "M": [{"x": 690, "y": 450}], "E": -1}
      ],
      "junctions": [{"x": 550, "y": 450}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["pot.contact.v", "pot.Rp", "pot.Rn", "R_load.i"]}
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt