Trying to make my way up the learning curve, I found this LTspice model for a solar-powered battery charger:
http://www.linear.com/docs/40736 (http://www.linear.com/docs/40736)
What I'm interested in is the input source from the U2 diode(?) on the left, and what appears to be its definition just below:
SYMATTR InstName U2
SYMATTR Value PhotoCell
SYMATTR Prefix X
.subckt PhotoCell B A
C1 A B 1n
V1 N001 B PWL(0 0 3u 17.7)
D1 N001 A S2
R1 A N001 75
.model S2 D(Ron=.1 Ilimit=1.2 epsilon=.5)
.ends
Could someone explain what's going on here? What is a .model S2 D? Is there a way to see this subcircuit - how C1, V1, D1 and R1 are connected?
Sorry, I don't have a video link for you as I learnt it the easy(ish) way of RTFM, research and experimenting, rather than the hard way of trying to replicate the steps in a Youtube video on a 'Monkey see, Monkey do' basis.
The netlist for the PhotoCell model is given between the .subckt line and the .ends line. Its name and pins in order are given on the .subckt line.
To reverse engineer it back to a schematic, start with a blank schematic in a new folder. This time, lets name the folder "revengnetlist" (no quotes).
Step1: add net labels of port type Bi-Direct for each pin named on the .subckt line (unless the pin is always an input or output, in which case you use those port types). All 'boxed' net labels become a subcircuit pin.
Step2: add 'C1 A B 1n' by placing a 1n capacitor, and connecting it to A and B. Check the new netlist (Menu: View: SPICE Netlist). If C1's connections are in the wrong order, flip it.
Step3: add 'V1 N001 B PWL(0 0 3u 17.7)' by placing a Voltage source V1 with value PWL(0 0 3u 17.7). Connect one pin to B and net label its other pin N001. Check the new netlist (Menu: View: SPICE Netlist). If V1's connections are in the wrong order, flip it.
Step4,5: add remaining components as above, checking the new netlist after each.
Step6: Add the model line for the diode type S2 by placing a SPICE directive:
.model S2 D(Ron=.1 Ilimit=1.2 epsilon=.5)
and again check the new netlist matches the subcircuit model you are reverse engineering.
The result should look something like this:
(https://www.eevblog.com/forum/projects/understanding-ltspice-solarcell-model/?action=dlattach;attach=1227309;image)
and its netlist should be:
* C:\users\<Your_User_Name>\documents\<Your_LTspice_Work_Folder>\revengnetlist\photocell.asc
C1 A B 1n
V1 N001 B PWL(0 0 3u 17.7)
D1 N001 A S2
R1 A N001 75
.model D D
.lib C:\Users\<Your_User_Name>\Documents\LTspiceXVII\lib\cmp\standard.dio
.model S2 D(Ron=.1 Ilimit=1.2 epsilon=.5)
.backanno
.end
Stuff in <> will be specific to your Windows user name. The lines .model D D, .lib C:\...\lib\cmp\standard.dio and .backanno are auto-supplied by LTspice with standard control panel options. Ignore them, they'll vanish when you use the reverse engineered model as a Hierarchical sub-schematic, and the .subckt and .ends lines will be auto-added.
All the steps so far are in the attached zip file. Note that if the subcircuit is complex, you'll need to spend a fair bit of time rearranging the layout to make sense, repeatedly checking that you haven't messed up the new netlist as you do so. For components with more than two pins, flipping them will not fix an incorrect pin order. Its easiest to start by labelling all the pins with a temporary distinct net label as soon as you've placed it, before you make any other connections to the component, then check the new netlist to get the pin order then hook them up one pin at a time, checking the new netlist, and removing the extra temporary net labels as you do so. Also note that any comments will always appear at the end of the new netlist, not in the order you placed them, and the components and directives.
Next we need to make it usable as a Hierarchical sub-schematic (See help LTspice XVII: Schematic Capture: Hierarchy). Save it as PhotoCell.asc and create a symbol of the same name for it. (Hint - Menu: Hierarchy: Open this Sheet's Symbol - will autogenerate a Hierarchical symbol with as many pins as labels with a Port-Type other than 'None' in your schematic, already pre-labelled and in correct netlist order.) Use your artistic talents to re-draw it as required. Check the pin table (Menu: View: Pin Table) is correct, and save it. (I cheated and stole the LED symbol then munged it to suit.)
Finally create a test jig schematic in the same folder and place an instance of 'PhotoCell' on it by selecting the current folder ion the 'Top Directory' dropdown at the top of the dialog then selecting it. Wire it up and run it!
N.B. The symbol attributes Prefix, SpiceModel and ModelFile *MUST* remain blank, the symbol type must be Block and the .asy name must exactly match the .asc name of the Hierarchical sub-schematic, and both + the main schematic must be all in the same folder for LTspice to recognize it as a Hierarchical sub-schematic when you run the main schematic sim.
Lets consider the line:
.model S2 D(Ron=.1 Ilimit=1.2 epsilon=.5)
That's a SPICE model statement that defines S2 as a somewhat peculiar diode (as Jay_Diddy_B explained earlier). Obviously the part 'number' S2 cant conflict with any other .model statement, and LTspice defaults to auto-including the standard libraries for diodes, BJTs, JFETs and MOSFETs, which all use .model statements, so you should avoid any part 'number' in those libraries. (I don't know if the different types of .model are in separate namespaces, so I wouldn't risk reusing e.g. a JFET part no. for a diode.) Otherwise its free choice of part 'number' - you can even use pure numerics which can be useful if you want to .step a sim through a selection of different semiconductors (http://ltwiki.org/index.php?title=Undocumented_LTspice#Stepping_a_Model).
Paralleling individual solar cells is equivalent to simply increasing the cell area, so your approach of fiddling with the parameters to get the correct Isc is acceptable if somewhat awkward. However F1 in your model is a current dependent current source that feeds back the load current into the 'guts' of the model and if you change its value from 1 to 1/{m}, you can then set parameter m to the number of parallel cells (or strings) to scale the feedback without having to fiddle with the parameters of an individual cell.