library[mosmodels];
library[stdfunctions];

circuit[Lambda← 2.5, Temp← 25]= {

  Vdd: node;

! ThymeBasics.thy
! NMos4.0u25.thy

powerSupply: voltage[Vdd, Gnd]= 5.0;

Vb, PreC, Reset: node;

V2: Voltage[Vb, Gnd] = 1.1;
V3: OneShot[PreC|tRise←10ns, tFall←10ns, width←500ns];
Cc5: Capacitor[Reset, Gnd] = 0.1E-12;
t6: DTran[Reset, Vdd, Reset| L←16, W←2];

C1a, C2a, C3a, C4a, Outa, VPreCa: node;

C1, C2, C3, C4, Out, VPreC: node;

t1: ETran[Vb, C2, C1| L←2, W←8];
t2: ETran[PreC, Vdd, C1| L←2, W←8];
t3: DTran[C3, Vdd, C3| L←16, W←2];
t4: ETran[C1, C3, Gnd| L←2, W←4];
t5: ETran[C3a, C3, Gnd| L←2, W←4];
t7: ETran[C3, Reset, Gnd| L←2, W←8];
t8: DTran[Out, Vdd, Out| L←4, W←2];
t9: ETran[C3, Out, Gnd| L←2, W←4];
t10: ETran[PreC, C1, C4|L←4, W←2];
t11: ETran[VPreC, C4, Gnd|L←4, W←2];

Cc1: Capacitor[C1, Gnd] = 0.11E-12;
Cc2: Capacitor[C2, Gnd] = 6.4E-12;
Cc3: Capacitor[C3, Gnd] = 0.78E-12;
Cc4: Capacitor[Out, Gnd] = 0.1E-12;
V1: Current[C2, Gnd] = 0.5E-06;
V4: Voltage[VPreC, Gnd] = 3.5;

t1a: ETran[Vb, C2a, C1a| L←2, W←8];
t2a: ETran[PreC, Vdd, C1a| L←2, W←8];
t3a: DTran[C3a, Vdd, C3a| L←16, W←2];
t4a: ETran[C1a, C3a, Gnd| L←2, W←4];
t5a: ETran[C3, C3a, Gnd| L←2, W←4];
t7a: ETran[C3a, Reset, Gnd| L←2, W←8];
t8a: DTran[Outa, Vdd, Outa| L←4, W←2];
t9a: ETran[C3a, Outa, Gnd| L←2, W←4];
t10a: ETran[PreC, C1a, C4a|L←4, W←2];
t11a: ETran[VPreCa, C4a, Gnd|L←4, W←2];

Cc1a: Capacitor[C1a, Gnd] = 0.11E-12;
Cc2a: Capacitor[C2a, Gnd] = 6.4E-12;
Cc3a: Capacitor[C3a, Gnd] = 0.78E-12;
Cc4a: Capacitor[Outa, Gnd] = 0.1E-12;
V1a: Current[C2a, Gnd] = 0.5E-06;
V4a: Voltage[VPreCa, Gnd] = 0;

  };
ic[C2←0.28, C2a←0.28];

print[:100ns, C2, C1];
plot["Optical Mouse",  :1000ns, 0, 5, Out, C3, C2, C1, Outa, C3a, C2a, C1a];

run[tMax ← 2500ns];