Using LTSpice to study electronics? What if there's no model for a component I want to use?

Thread Starter

JamesAguilar

Joined Nov 11, 2024
17
Friends,

I'm a beginner maker. I'm mostly interested in using microcontrollers to build and control small devices. I program professionally, so the big weakness in my education is the electronics and mechanical engineering side of things.

Particularly in the space of electronics, I know a lot of the fundamentals only at a high level. I am working my way through a beginning electronics text, and concurrently working on some design projects I'm interested in, practicing reading datasheets, etc.

One thing I thought might be useful is to use a program like LTSpice to simulate my designs and see if they "actually work" before ordering parts. As an exercise, I'm trying to design a decoder for DCC model train signals.

I've attached the model I came up with so far, with a screenshot in case anyone doesn't want to download my file.

1731341278173.png

(Note that this model is not complete yet -- there are a few other components I want to include on it. But it demonstrates the issue I was having.)

Originally, when I was designing this circuit, I thought the DCC signal pulses were about 1us in duration. I've since realized that the pulses are more like 50us long, which means my question is sort of obsolete. But, for the sake of "learning to learn," I'd like to ask this question anyway.

A problem I noticed in the simulation was that the railsig net voltage rose and fell too slowly, I assume due to capacitance in the 4N25. I read the datasheet for the 4N25 photocoupler and learned that the rise and fall time were about 2us, too slow for a signal 1us in duration. There are other photocouplers with sufficiently high bandwidth for this application, however, all the ones included in LTSpice are too slow.

My question: when you want to test the behavior of a component that is not included in LTSpice, what are your options? Do you have to build your own model for the device? Are you supposed to use some kind of shortcut? Is testing behavior using LTSpice even a proper use of this program or proper avenue for learning, or should I be testing on the bench?

More generally: my main goal right now is gaining an intuitive understanding of how circuits and circuit components work, with an aim to become proficient and board design and component selection in the space of mostly-digital low-power electronics. I seem to learn best by experimenting and doing, and I think my overall question is whether you think LTSpice or some other simulator is a good approach to this, or if this is not productive and there is another avenue I should be following.

Thank you so much for any help.
 

Attachments

crutschow

Joined Mar 14, 2008
38,314
You can add models to LTspice, but it can require a little work.
Look for a model file for the device you want and download that to the LTspice library in the Lib directory as a .sub or .lib file.
Then you may have to edit a symbol model of a similar device to connect to the model file you have and save it as a new symbol (.asy) file.

Attached is an example of a faster opto coupler I have downloaded.
 

Attachments

Alec_t

Joined Sep 17, 2013
15,101
Welcome to AAC!
My question: when you want to test the behavior of a component that is not included in LTSpice, what are your options?
Third party models of many components are available for free download from the LTspice user group at the groups.io site.
LTS-compatible models for microcontrollers don't appear to be available though.
The LTS Help explains how to add third party models.
 

Thread Starter

JamesAguilar

Joined Nov 11, 2024
17
Y'all are too kind. Thank you for answering my question about other models. I did find a few optos whose datasheets indicated they would work for my use case, but I couldn't find ltspice models for those. Maybe I just needed to keep looking for a device for which a model was available.

I would still welcome any feedback about whether using LTSpice as a learning platform is efficient.
 

crutschow

Joined Mar 14, 2008
38,314
I would still welcome any feedback about whether using LTSpice as a learning platform is efficient.
Depends upon you definition of "efficient".
I find it very useful to determine if a circuit is likely to work before I build it.
I've found a lot of problems in my designs doing that.

And it's very useful to help understand how basic circuits work.
It allows you to probe voltages and currents anywhere in the circuit without disturbing the circuit, which is not generally possible in a real circuit.

Of course simulations are only as good as the model of the devices, but I have found that if the simulation works, then there's a good chance it will work as a real circuit, but if the sim doesn't work, then the real circuit likely won't either.
 

eetech00

Joined Jun 8, 2013
4,704
Friends,

I'm a beginner maker. I'm mostly interested in using microcontrollers to build and control small devices. I program professionally, so the big weakness in my education is the electronics and mechanical engineering side of things.

Particularly in the space of electronics, I know a lot of the fundamentals only at a high level. I am working my way through a beginning electronics text, and concurrently working on some design projects I'm interested in, practicing reading datasheets, etc.

One thing I thought might be useful is to use a program like LTSpice to simulate my designs and see if they "actually work" before ordering parts. As an exercise, I'm trying to design a decoder for DCC model train signals.

I've attached the model I came up with so far, with a screenshot in case anyone doesn't want to download my file.

View attachment 335549

(Note that this model is not complete yet -- there are a few other components I want to include on it. But it demonstrates the issue I was having.)

Originally, when I was designing this circuit, I thought the DCC signal pulses were about 1us in duration. I've since realized that the pulses are more like 50us long, which means my question is sort of obsolete. But, for the sake of "learning to learn," I'd like to ask this question anyway.
The DCC signal generator should produce a bi-polar square wave with a period of either 100us, or 200us, at 50% duty.

A problem I noticed in the simulation was that the railsig net voltage rose and fell too slowly, I assume due to capacitance in the 4N25. I read the datasheet for the 4N25 photocoupler and learned that the rise and fall time were about 2us, too slow for a signal 1us in duration. There are other photocouplers with sufficiently high bandwidth for this application, however, all the ones included in LTSpice are too slow.
Attached below is 6N137 optocoupler model.

My question: when you want to test the behavior of a component that is not included in LTSpice, what are your options? Do you have to build your own model for the device? Are you supposed to use some kind of shortcut? Is testing behavior using LTSpice even a proper use of this program or proper avenue for learning, or should I be testing on the bench?

More generally: my main goal right now is gaining an intuitive understanding of how circuits and circuit components work, with an aim to become proficient and board design and component selection in the space of mostly-digital low-power electronics. I seem to learn best by experimenting and doing, and I think my overall question is whether you think LTSpice or some other simulator is a good approach to this, or if this is not productive and there is another avenue I should be following.

Thank you so much for any help.
Your circuit need some modifications. I think the opto is supposed to detect the presence of the DCC signal. It could do that by connecting it to the "railsum" output. It not clear to me what the switch mode controller is for.

Anyway, LTspice is an accurate simulator, and free, but has a steep learning curve. Models are available from various sources, here on AAC, manufacture web sites, as well as the internet. If you can't find a model, you can try asking the manufacturer or someone familiar with spice modeling.

1731430426104.png
 

Attachments

Thread Starter

JamesAguilar

Joined Nov 11, 2024
17
Your circuit need some modifications. I think the opto is supposed to detect the presence of the DCC signal. It could do that by connecting it to the "railsum" output. It not clear to me what the switch mode controller is for.
Thank you! Regarding the opto, after adjusting the voltage generator to match the actual behavior of the DCC signal (c.a. +12v or -12v on a 100 or 200us period, AIUI), it seems to work fine in the present configuration. I.e. I see the desired signal on the output. I am going to study your diagram, though.

The purpose of the switch mode controller is that the decoder will have a microcontroller on it as well. That needs to be fed with 3.3v, and in my limited understanding 12v->3.3v probably should use a switching regulator rather than a linear one. (Is that correct?) Eventually there will also be a motor driver and a motor in my schematic.

I put the regulator into the simulation because I wanted to get a sense of whether I had correctly understood the datasheet's instructions on how to hook it up. I.e. did the voltage converge at 3.3v.

That being said, your questions make me think there may be something I'm missing about the purpose of LTSpice in the design of circuits. Should I not be putting all my components into the sim?
 

crutschow

Joined Mar 14, 2008
38,314
Should I not be putting all my components into the sim?
For components that have no available model, you may just have to approximate them using the LTspice functional sources and gain blocks (get familiar with them) and passive devices.

Also, for a complex circuit, it may be easier to simulate the circuit in smaller functional blocks.
That way if something is not working, it's easier to isolate the problem.
 

Thread Starter

JamesAguilar

Joined Nov 11, 2024
17
Thanks, that makes sense. If the whole circuit is not in one piece in LTSpice, it seems like importing it into another program e.g. for manufacturing might be a little troublesome. Any advice on avoiding errors when transferring the circuit? Besides "be careful and don't screw it up" of course. :)
 

crutschow

Joined Mar 14, 2008
38,314
If the whole circuit is not in one piece in LTSpice, it seems like importing it into another program e.g. for manufacturing might be a little troublesome.
Generally that has to be done manually anyway with LTspice, so whether its in one piece or not does not make much difference.

There are some for-pay programs, such as Multisim, that I believe do allow direct transfer from the simulation schematic to the PC layout.
 

eetech00

Joined Jun 8, 2013
4,704
Thank you! Regarding the opto, after adjusting the voltage generator to match the actual behavior of the DCC signal (c.a. +12v or -12v on a 100 or 200us period, AIUI), it seems to work fine in the present configuration. I.e. I see the desired signal on the output. I am going to study your diagram, though.
Actually, the DCC signal is +/- 14VDC to +/-16VDC, depending on gauge.

The purpose of the switch mode controller is that the decoder will have a microcontroller on it as well. That needs to be fed with 3.3v, and in my limited understanding 12v->3.3v probably should use a switching regulator rather than a linear one. (Is that correct?) Eventually there will also be a motor driver and a motor in my schematic.
That's one reason (input voltage is much higher than output) to use a switching supply (SMPS) because they are more efficient, but there are other considerations. SMPS's are noisy and have a large initial input current draw when they startup.

I put the regulator into the simulation because I wanted to get a sense of whether I had correctly understood the datasheet's instructions on how to hook it up. I.e. did the voltage converge at 3.3v.

That being said, your questions make me think there may be something I'm missing about the purpose of LTSpice in the design of circuits. Should I not be putting all my components into the sim?
As implied in #11, not all components need to be fully modeled. Just like you did with the DCC generator, you didn't design a whole DCC generator, you simply used a primitive spice Voltage element to behave as one. Its usually not necessary to model each and every component, but you can if you wish. You need to decide what you intend to get out of the simulation, then go forward with modeling devices only if necessary.
 
Last edited:

eetech00

Joined Jun 8, 2013
4,704
Thanks, that makes sense. If the whole circuit is not in one piece in LTSpice, it seems like importing it into another program e.g. for manufacturing might be a little troublesome. Any advice on avoiding errors when transferring the circuit? Besides "be careful and don't screw it up" of course. :)
This is something to consider when choosing software for schematic capture, simulation and PCB design.
There are a few programs that will let you "draw" the schematic in their software, but use LTspice to simulate.
The schematic can then be forwarded to the PCB program for design, and output of manufacturing files. It takes a bit of user effort, however, to use this integration effectively. I suggest for LTspice beginners to draw and simulate the schematic in LTspice, and when simulation is complete, redraw the schematic and design the PCB in a tool that has those programs integrated.
 
Top