Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Home Electrical Circuit Simulation: Series-Parallel Configurations with Component Constraints and Diodes

Notes Apr 20 8

The home electrical circuit simulation program has been extended in two iterations.

Version 3 introduces a mutual exclusion switch with built-in current-limiting resistors (5 ohms between pins 1 and 2, 10 ohms between pins 1 and 3) and a controlled curtain device. The curtain (symbol 'S') operates at a minimum voltage of 50V. Its opening ratio is determined by the total light intensity (in lux) from all lamps as follows:

  • [0, 50): 1.0
  • [50, 100): 0.8
  • [100, 200): 0.6
  • [200, 300): 0.4
  • [300, 400): 0.2
  • [400, ∞): 0.0 If the voltage is below 50V, the curtain defaults to 1.0. This version also supports multiple parallel circuits connected in series.

Version 4 adds:

  • Pin voltage display: after each device's state, output the voltage for each pin (as an integer, truncated) in ascending order, separated by '-'.
  • Current limit check: if a component's current exceeds its maximum, append "exceeding current limit error" (with a space).
  • Short circuit detection: if a short circuit (infinite current) occurs, output "short circuit error" and skip all device outputs.
  • Nested parallel circuits: a parallel circuit may contain other parallel circuits (i.e., the series circuits forming a parallel circuit can themselves be parallel circuits).
  • Diodes (symbol 'P'): a two-pin component that conducts (0 resistance) when current flows from pin 1 to 2, and blocks (infinite resistance) when current flows from pin 2 to 1.

The system design uses:

  • A base class CircuitDevice for all component.
  • Control devices: switch (K), step dimmer (F), continuous dimmer (L), mutual exclusion switch (H).
  • Controlled devices: incandescent lamp (B), fluorescent lamp (R), ceiling fan (D), floor fan (A), controlled curtain (S), diode (P).
  • Series and parallel circuit classes (SeriesCircuit and ParallelCircuit), which are also CircuitDevice instances.

Control Device Behavior:

  • Switch (K):
    • Two pins: one input (to power) and one output (to ground).
    • State 0: output = 0V.
    • State 1: output = input voltage.
  • Mutual Exclusion Switch (H):
    • Three pins: 1 (main), 2 and 3 (branches).
    • The resistor between pin 1 and 2 is 5 ohms, and between pin 1 and 3 is 10 ohms.
    • The switch toggles between two states:
      • State 0: connects pin 1 to pin 2 (with 5 ohm resistor), pin 3 is open.
      • State 1: connects pin 1 to pin 3 (with 10 ohm resistor), pin 2 is open.

Input Format:

  • Device identifiers: K (switch), F (step dimmer), L (continuous dimmer), B (incandescent lamp), R (fluorescent lamp), D (ceiling fan), A (floor fan), H (mutual exclusion switch), S (controlled curtain), P (diode).
  • Connection: each line is a set of connected pins in brackets (e.g., [1 2 3]).
  • Control actions: #K<num>, #H<num>, #F<num>+/#F<num>-, #L<num>:<value>.
  • Power: VCC (220V) and GND (0V). Unconnected pins default to 0V.
  • Series circuit: a line with n connection info (from power to ground).
  • Parallel circuit: a line with the series circuit identifiers.

Output Format:

  • Order: by device type (switch, step dimmer, continuous dimmer, incandescent lamp, fluorescent lamp, ceiling fan, mutual exclusion switch, controlled curtain, diode) and within same type by increasing device number.
  • Format: @<id><num>:<value> <pin1_v>-<pin2_v>-...
  • For control devices:
    • Switch: state (0 or 1)
    • Step dimmer: step number
    • Continuous dimmer: continuous value
  • For lamps and fans: value is the brightness (0-1) or speed (0-1).
  • For curtain: value is the opening ratio (0.0 to 1.0).
  • For diode: value is "conduction" or "cutoff".
  • Pin voltages: integers (truncated), in ascending pin order.

Component Resistances (for non-control devices):

  • Incandescent lamp: 10 ohms
  • Fluorescent lamp: 5 ohms
  • Ceiling fan: 20 ohms
  • Floor fan: 20 ohms
  • Controlled curtain: 15 ohms

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Spring Boot MyBatis with Two MySQL DataSources Using Druid

Required dependencies application.properties: define two data sources and poooling Java configuration for both data sources MyBatis mappers for each data source Controller endpoints to verify both co...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.