Subckt design in SPICE

spice

How can I do my own sub ckt for SPICE. I want to design a potentiometer(for eg). Assuming it in the form of a block model – it will have 3 pins – 2 pins for the resistor and 1 pin for the centre tap that can vary the resistor value. If I warite a subckt, how do I proceed with it please ?
Is there any suitable tutorial ?
Also, for eg – I would like to design a subckt for a variable resistor.This is time based(at time t0 it has a specific value,t1 it has specific value and so on and so forth). I have a formula for it. How can I implement this formula sub-ckt ?
I am look at the syntax for this please.

Best Answer

Since you're apparently asking about PSpice (based on your other question):

.subckt VARIRES 1 2 CTRL
R1 1 2 1E10
G1 1 2 Value = {V(1,2)/(V(CTRL)+1ยต)}
.ENDS

This is from http://powerelectronics.com/site-files/powerelectronics.com/files/archive/powerelectronics.com/mag/503PET07.pdf

The above a 1 ohm (variable) resistor. G1 is a (controlled) current source. The (current) value it returns is based on dividing the voltage between the nodes 1 and 2 (the ends of the pot) by the value of the controlling voltage applied at node CTRL (the pot cursor/wiper). R1 (which has a huge value) is simply there to measure the voltage from 1 to 2. To actually change the current (resistor value), you need go change G1.

That frankly struck me as not the most obvious approach. The more obvious way is using two resistors:

.subckt SCHEMATIC1_R1 1 2 t
RT_R1 1 t {(1K*(1-X))+.001}
RB_R1 t 2 {(1K*X)+.001}
.ends SCHEMATIC1_R2

From https://www.ece.vt.edu/tutorials/download/Sweeping_POT.pdf

This is a 1K variable resistor and uses the X parameter (between 0 and 1) to set the position of the pot.