-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adv custom spice #3988
base: main
Are you sure you want to change the base?
Adv custom spice #3988
Conversation
…capacitor.cpp (if the property is not numeric, we should able to edit freely)
One issue with just having a unique moduleID for all the custom spice parts is that the only thing that you can change is the source model. |
There is already an something similar: "Editable pin labels". But I am not sure if this would help or is needed. Lets look at the use cases:
Once the spice model is an editable property, case 1 and 2 should already be covered. For 3. we already have the possibilty to publish parts with spice models, no changes needed. |
"But I am not sure if this would help or is needed." Not sure if you are talking about the editable pins, the modifiable spice fields or the special spice parts. I really think that there should be a way to modify the spice field of, at least some, parts. I am not sure if all of them should be modifiable or just a few special ones. Regarding the necessity of modifying spice fields, this come from the fact that some times you want to use a specific model (for example, a model of a specific diode). Then, you need to add the spice model to the part. This is very common as most of the licenses of the models do not allow redistribution. Right now, the only solution is to create a new part, which is time consuming. And if there is an error or you want to modify something, back to edit the part and regenerate the database... If we allow that all parts can modify their spice fields, there are a few issues. First, a specific part that has a specific model for that part could be changed to something to doors not model that part. E.g., you have a model for the 1N4001 diode and the user changes it to be another kind of diode. It's the user mistake, but a person who recovers that sketch will guys that the model still represents an 1N4001 diode af the part of called 1N4001. If the model cannot be modified, this error disappears. Second, another source of error could come if, as you said, the spice model is not correct. Then, the simulator will not work and an error message will be shown, I do not think that it will crash Fritzing. But users could complain about things not being able to simulate. A parser for the spice model is a possibility, but I do not think it is very useful and it will take some effort to program. As most models are copies from a library/internet, most of the time it is just copy and paste a line of text. Most persons do not change the different parameters of the model. Third, the readability of the spice file (the spice circuit) decreases. If each instance of a part had its own spice model, the models cannot be reused. A circuit with 3 transistors (all the same kind) will get three different spice models, even if the models are the same. We could clean up this, but it will need some code. The above reasons put me to think in only some special spice parts, where the source field is a property. The drawback is the multiple moduleIDs necessary. Also, if the user wants a special part with a different BB or PCB layout, it will need to generate a new part. Maybe an intermediate solution would be to have to do something to enable the modifiable spice field, like check an enable or double click on the spice field. But this would require more changes in the code. More complex spice models would also require a text box rather than just a line of text. For example, you may want to create spice models which are made with subcircuits and need several lines of text. |
Sorry I was unclear. I am not sure that we would need a switch to make the spice field editable. |
The main issue I think comes from not being allowed to redistribute SPICE models. Does this apply for each individual model, or does it apply for the collection of spice models (similar as with collection of CAD files for electronic parts) ? Of course we should allow users to enter their spice models. But we should not encourage people to copy and redistribute those protected models. |
Ok. So basically you are ok with the current pull request: Normal parts do not have editable spice fields and there are special parts for that. Then, the only issue is that I would like to create several new module IDs: DiodeCustomSpiceModuleID, TransistorCustomSpiceModuleID, etc. If there is only a generic CustomSpiceModuleID, the parts cannot edit other properties (like max. current or max. power). Or can you imagine another option where we indicate somehow that the part has an editable spice field. Maybe "editable=yes" in the spice tag of the fpz file? |
This is one of the reasons why I want to make this parts with editable spice fields. We cannot redistribute the spice models, but if the users can find them, we can allow then to just copy and paste that model into the part. More models that I have seen come with a copyright notice. You can find them sometimes in the datasheet of the component or at the manufacturer website. I have seen collections of spice models, but they usually come with copyright. We should not encourage them to redistribute the models, but if they do it it's not our fault. In any case, we should be careful when committing spice models to the repository. |
How about a table
A diode would use the default model, but you can select a different one. I think the UX problem (adding an own spice model) could be solved easily, e.g by just having <add> included as one of the options. This would avoid the confusion about having multiplte identical looking diodes, but one has a fixed spice model, and only the other can be edited. This would be similar to existing property.xml presets e.g. for capacitors. |
Mmm, I'm a bit confused. The table seems that you are proposing to make this for all parts and not have parts with editable field and others without them. Have you changed your opinion (or maybe I understood you wrong before)? I am not sure if a table is a good idea. It seems less intuitive to have to modify a table. And if an user needs several different diodes, he would need to use several different parts to get all of them (I'm guessing that one part ID will only have a spice field). I think it is easier to understand that the spice model is defined in the fpz file and bit in a table somewhere else. If we add an for the spice model, we should explain if the new spice model affects all the parts or just that instance. Regarding the issue of having multiple diodes and some with editable spice fields and others not, we could add "custom spice" label or a small symbol next to the part to differentiate those custom spice parts from the normal ones. |
That is true, but we could add some "SPICE" symbol over the schematic or the part in the BB view. I am not sure if we need to duplicate a lot of the parts. The editable spice parts would be generic and we would only need a part for each type of spice instance: resistors, capacitors, diodes, different kinds of transistors, power supplies, etc., and maybe a generic IC part for spice subcircuits. I agree that making all of the spice fields editable is maybe neater from a UI point of view, but it is much more work to implement:
Right now, the spice model of a part is applied to all the instances of that part and each instance generates a spice device. But if we allow being editable, the modified model needs to be applied to only that instance. To do that, in this PR I modified the name of the model to be "MODEL_{instanceTitle}". The {instanceTitle} label gets replaced by the actual instance title of the component when generating the netlist: e.g.: MODEL_D3 for diode 3. Thus, we avoid having several models with the same name (but being actually different models).
My bigguest concern is that what it could work for some kind of devices, it could not work for others. For example, transistor and diodes use models, there are subcircuits and there are other devices that do not need models like resistors, voltage sources, etc. A part could require one line (a resistor or a transistor) and other several lines (e.g., potentiometers are two resistors, a 4x nand gate component needs four nand gate devices). Making something homogenous that works for all parts needs to be well thought. Others: The table is nice to give several spice models (e.g., a model for the 1n4001 diode, another for a Schottky diode, etc.), but as most models are proprietary we will not have a lot of them. There are some spice models available here (some of them are public domain, but not a lot of them): https://ngspice.sourceforge.io/modelparams.html Making graphs for the diodes is nice, but too complex for being scalable (there are several parts to simulate). Displaying the spice field could make sense, but it is probably too long. Maybe we should only show an alias of the model. In my opinion, having all parts with modifible spice fields seems a big change that requires a lot of code. Thus, I am not sure if it is worth the effor as only a few people will use this functionality. But maybe you have a nice way of implementing these changes. |
This code is just an initial implementation for feedback.
This commit (with the respective commit in the parts repository) implements parts where users can adjusts their spice models without creating new parts. This can be useful in debugging simulations. Each part defines its own property "spice model" which thus can be different from other parts. For now, two of the parts are implemented: diodes and NPN transistors, but there are several more if this is proposal is accepted (see ngSpice manual).