diff options
Diffstat (limited to 'MIL_testing')
| -rw-r--r-- | MIL_testing/hp_memristor.cir | 45 | ||||
| -rw-r--r-- | MIL_testing/integration_test.py | 14 | ||||
| -rw-r--r-- | MIL_testing/memristor_waveforms.png | bin | 202901 -> 0 bytes | |||
| -rw-r--r-- | MIL_testing/ng_test1.cir | 25 | ||||
| -rw-r--r-- | MIL_testing/reading_output.py | 36 | ||||
| -rw-r--r-- | MIL_testing/simulation.cir | 34 | ||||
| -rw-r--r-- | MIL_testing/simulation.raw | bin | 16065842 -> 0 bytes | |||
| -rw-r--r-- | MIL_testing/spice_backend.py | 73 |
8 files changed, 0 insertions, 227 deletions
diff --git a/MIL_testing/hp_memristor.cir b/MIL_testing/hp_memristor.cir deleted file mode 100644 index 1865a7a..0000000 --- a/MIL_testing/hp_memristor.cir +++ /dev/null @@ -1,45 +0,0 @@ -* HP Memristor SPICE Model -* For Transient Analysis only -* created by Zdenek and Dalibor Biolek -************************** -* Ron, Roff - Resistance in ON / OFF States -* Rinit - Resistance at T=0 -* D - Width of the thin film -* uv - Migration coefficient -* p - Parameter of the WINDOW-function -* for modeling nonlinear boundary conditions -* x - W/D Ratio, W is the actual width -* of the doped area (from 0 to D) -* -.SUBCKT memristor Plus Minus PARAMS: -+ Ron=1K Roff=100K Rinit=80K D=10N uv=10F p=1 -*********************************************** -* DIFFERENTIAL EQUATION MODELING * -*********************************************** -Gx 0 x value={ I(Emem)*uv*Ron/D^2*f(V(x),p)} -Cx x 0 1 IC={(Roff-Rinit)/(Roff-Ron)} -Raux x 0 1T - -* RESISTIVE PORT OF THE MEMRISTOR * -******************************* -Emem plus aux value={-I(Emem)*V(x)*(Roff-Ron)} -Roff aux minus {Roff} -*********************************************** -*Flux computation* -*********************************************** -*does not work with ngspice -*Eflux flux 0 value={SDT(V(plus,minus))} -*********************************************** -*Charge computation* -*********************************************** -*does not work with ngspice -*Echarge charge 0 value={SDT(I(Emem))} -*********************************************** -* WINDOW FUNCTIONS -* FOR NONLINEAR DRIFT MODELING * -*********************************************** -*window function, according to Joglekar -.func f(x,p)={1-(2*x-1)^(2*p)} -*proposed window function -;.func f(x,i,p)={1-(x-stp(-i))^(2*p)} -.ENDS memristor diff --git a/MIL_testing/integration_test.py b/MIL_testing/integration_test.py deleted file mode 100644 index 7c8e2fa..0000000 --- a/MIL_testing/integration_test.py +++ /dev/null @@ -1,14 +0,0 @@ -import subprocess - -result = subprocess.run( - ["ngspice", "-b", "ng_test1.cir"], - capture_output=True, - text=True -) - -print("Return code:", result.returncode) -print(result.stdout) - -if result.stderr: - print("Errors:") - print(result.stderr) diff --git a/MIL_testing/memristor_waveforms.png b/MIL_testing/memristor_waveforms.png Binary files differdeleted file mode 100644 index 54cd69e..0000000 --- a/MIL_testing/memristor_waveforms.png +++ /dev/null diff --git a/MIL_testing/ng_test1.cir b/MIL_testing/ng_test1.cir deleted file mode 100644 index 892a284..0000000 --- a/MIL_testing/ng_test1.cir +++ /dev/null @@ -1,25 +0,0 @@ -* RC Charging Circuit - -V1 in 0 PULSE(0 5 1u 1u 1u 100m 200m) - -R1 in out 1k - -C1 out 0 1u - -.tran 10u 50m - -.control -run - -set finalindex = $&{length(v(in)) - 1} - -let final_vin = v(in)[$finalindex] -let final_vout = v(out)[$finalindex] -let final_current = v1#branch[$finalindex] - -echo "----- final time analysis -----" -print final_vin final_vout -print final_current - -.endc -.end diff --git a/MIL_testing/reading_output.py b/MIL_testing/reading_output.py deleted file mode 100644 index 3e37dfe..0000000 --- a/MIL_testing/reading_output.py +++ /dev/null @@ -1,36 +0,0 @@ -from spicelib import RawRead -import matplotlib.pyplot as plt - -raw = RawRead("simulation.raw") -print(raw.get_trace_names()) - -time = raw.get_trace("time").get_wave() -current = raw.get_trace("i(v.xmem.v_emem)").get_wave() -voltage = raw.get_trace("v(in)").get_wave() -state_variable = raw.get_trace("v(xmem.x)").get_wave() - -print(f"final current: {current[-1]}") - -print(f"state variable : {state_variable[-1]}") - -# Create a figure with two stacked subplots -fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 8), sharex=True) - -# 1. Plot Current vs Time -ax1.plot(time, current, color='blue', linewidth=2, label='Memristor Current') -ax1.set_ylabel('Current (A)') -ax1.set_title('Memristor Simulation Results') -ax1.grid(True, linestyle='--', alpha=0.7) -ax1.legend() - -# 2. Plot Voltage vs Time -ax2.plot(time, voltage, color='red', linewidth=2, label='Input Voltage v(in)') -ax2.set_xlabel('Time (s)') -ax2.set_ylabel('Voltage (V)') -ax2.grid(True, linestyle='--', alpha=0.7) -ax2.legend() - -# Adjust layout to prevent overlap and display the plot -plt.tight_layout() -plt.savefig("memristor_waveforms.png", dpi=300, bbox_inches='tight') -print("Saved waveforms to memristor_waveforms.png") diff --git a/MIL_testing/simulation.cir b/MIL_testing/simulation.cir deleted file mode 100644 index 8b0701d..0000000 --- a/MIL_testing/simulation.cir +++ /dev/null @@ -1,34 +0,0 @@ -* simulation.cir -* Testbench for HP Memristor -.options savecurrents -.save all - -.include "hp_memristor.cir" - -* Voltage source -.param Vin = ${VOLTAGE_IN} -.param Vlast = ${VOLTAGE_LAST} -V1 in 0 PULSE(VOLTAGE_LAST VOLTAGE_IN 0 1u 1u 1m 3m) - -* Memristor -XMEM in out memristor -+ Ron=1k -+ Roff=100k -+ Rinit=80k -+ D=10n -+ uv=10f -+ p=1 - -* Load resistor -Rload out 0 1k - -.tran 1u 100m uic - -.control - -run -write simulation.raw -quit - -.endc -.end diff --git a/MIL_testing/simulation.raw b/MIL_testing/simulation.raw Binary files differdeleted file mode 100644 index 0c51710..0000000 --- a/MIL_testing/simulation.raw +++ /dev/null diff --git a/MIL_testing/spice_backend.py b/MIL_testing/spice_backend.py deleted file mode 100644 index c6be8a1..0000000 --- a/MIL_testing/spice_backend.py +++ /dev/null @@ -1,73 +0,0 @@ -import subprocess -import re -from spicelib import RawRead - -class SpiceBackend: - """This is what actually does all of the spice stuff""" - def __init__(self, device_file: str): - self.conductance = 0 - self.voltage = 0 - self.current = 0 - self.time = 0 - self.state = None - self.dt = 1e-9 - - def simulate(self, voltage_signal: float, return_current: bool = False) -> float: - """runs the simulation for one time step""" - len_voltage_signal = 1 - try: - len_voltage_signal = len(voltage_signal) - except: - voltage_signal = [voltage_signal] - - if return_current: - current = np.zeros(len_voltage_signal) - - for t in enumerate(len_voltage_signal): - result = self.run_spice(voltage_signal) - - single_current = result.current - self.conductance = result.conductance - - if return_current: - current[t] = single_current - - if return_current: - return current - - - def set_conductance(self, conductance: float): - """Handled by spice now""" - """Could probably still add some safety checks just to be sure later""" - self.conductance = conductance - - def run_spice(self, voltage: float) -> float: - """returns the current after given a voltage signal""" - #need to find a way to pass voltage signal to ngspice here - #also maybe a time series resolution?? - result = subprocess.run( - ["ngspice" "-b" "simulation.cir"], - capture_output=True, - text=True - ) - if result.returncode != 0: - raise RuntimeError(result.stderr) - - # parse current into float variable - output = result.stdout - #is there a better (less rigid) way of grabbing the output - current_match = re.search("final_current = ([-\deE.+]+)", output) - if current_match is None: - raise RuntimeError("Could not find current in ngspice output") - - current = float(current_match.group(1)) - - if abs(voltage) > 1e-12: - conductance = current / voltage - else: - conductance = self.conductance - - return { - "current": current, - "conductance": conductance, - } |
