Author Topic: Help with LTSPice  (Read 1394 times)

0 Members and 1 Guest are viewing this topic.

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Help with LTSPice
« on: November 08, 2024, 06:44:50 pm »
Hello all:

Would appreciate some help with trying to simulate a LTSpice project. It is a zero cross detector and when I run the simulation, I indeed see the pulses from the optocoupler, but when I probe the mains side I am getting high voltages not in line with what the project notes describe. Pretty much get 60v across anywhere on the main side of the optocoupler. I am not that versed in LTSpice so assume it's something wrong in my setup. I have attached the file with the .txt extension, extension needs to be changed to .asc. Appreciate any assistance. Appears the project does work, but just not seeing what I should on the main side.

https://dextrel.net/dextrel-start-page/design-ideas-2/mains-zero-crossing-detector

-=Bryan=-
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #1 on: November 08, 2024, 07:14:56 pm »
For example..
PS: should be named "120Hz.." actually..
120Hz_negative is your virtual ground on the secondary..
There is only one ground in LTspice, so you have to use "differences" with virtual grounds..
LTspice is using "amplitude" in sine generator as Vpeak, thus it is 120V*1.41.. (because 120V in US is "effective" Vrms)
« Last Edit: November 08, 2024, 07:22:27 pm by iMo »
Readers discretion is advised..
 

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #2 on: November 08, 2024, 07:22:18 pm »
Thanks very much for the reply, Aah I see, so I needed to connect the grounds together from the non-isolated to the isolated side but with a somewhat infinite resistance. Interesting, much appreciated.

ps I see you have modified V1 to 170 v is that because it would be 170 RMS, and for future projects when simulating mains voltage that should be the expected settings for power voltages?
-=Bryan=-
 

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #3 on: November 08, 2024, 07:23:14 pm »
I responded before your edit. thanks so much for the info
-=Bryan=-
 
The following users thanked this post: iMo

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #4 on: November 08, 2024, 07:32:49 pm »
..also I would use an 1N4007 when messing with directly coupled mains voltages..
Readers discretion is advised..
 

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #5 on: November 08, 2024, 07:38:32 pm »
Yes, kind of wondered why the author spec'd a 1N4148, seemed a bit dicey
-=Bryan=-
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #6 on: November 08, 2024, 07:48:19 pm »
Yeah, there is a low voltage at the diodes actually (because of the 220k droppers), but shit may happen..
Btw., you have to increase the collector resistor R5 of the transistor at the "secondary" side in order to get a nice 5Vpp sig out of it, it seems..
« Last Edit: November 08, 2024, 07:51:22 pm by iMo »
Readers discretion is advised..
 
The following users thanked this post: Bryan

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #7 on: November 08, 2024, 08:22:22 pm »
The original design spec'd a 4N35 so perhaps that has something to do with it, they do reference adjusting that particular value for a 5v or 3.3v output. Design specd that there will be a fast fall but the rise will be skewed a bit which is confirmed in the Ltspice simulation. Looks like some tweaking is necessary, same with R4 and C1 to adjust the width of the output.
« Last Edit: November 08, 2024, 08:23:54 pm by Bryan »
-=Bryan=-
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20274
  • Country: gb
  • 0999
Re: Help with LTSPice
« Reply #8 on: November 08, 2024, 08:43:17 pm »
LTSpice only has one ground node, but it also has a common node, com, for this purpose.

I managed to get it to simulate without adding a shunt resistor. Another way round this is to ground the output and label the input nets phase and neutral.

With 1k there wasn't enough light from the emitter to saturate the phototransistor. The circuit works perfectly when R5 is increased to 10k.

 
The following users thanked this post: Bryan, tooki

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #9 on: November 08, 2024, 08:48:59 pm »
You may do it in this way as well - the secondary is grounded and the primary is "isolated" via R7.
The max "isolation" value of R7 depends somehow on the models of the other parts there (ie. the simulation does not converge with 1Tohm there).
For a simulation with your schematics the R7 could be any value (or short as well).
Readers discretion is advised..
 

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #10 on: November 08, 2024, 08:51:42 pm »
LTSpice only has one ground node, but it also has a common node, com, for this purpose.

I managed to get it to simulate without adding a shunt resistor. Another way round this is to ground the output and label the input nets phase and neutral.

With 1k there wasn't enough light from the emitter to saturate the phototransistor. The circuit works perfectly when R5 is increased to 10k.

Yes, it does work without the resistor, but LTspice simulate much higher voltages when using the voltage probe, if I recall a probe at C2 and R4 displays 60v, but with the shunt it displays what it should if on a breadboard.
-=Bryan=-
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #11 on: November 08, 2024, 09:22:46 pm »
You have to reference it to the "COM" - see the above sim of Zero999 - "the V(out.COM)". That is the "difference" V(out) against COM.

COM is a symbol only, a name for a net/wire, should be connected to GND "somehow" as well.. Any other net/wire name could be used the same way..

PS: As I wrote above your sim works fine when both sources are grounded to the GND.. (no resistor needed).
« Last Edit: November 08, 2024, 09:39:41 pm by iMo »
Readers discretion is advised..
 
The following users thanked this post: Bryan

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20274
  • Country: gb
  • 0999
Re: Help with LTSPice
« Reply #12 on: November 08, 2024, 10:18:26 pm »
Yes, that will work.

Here's what I was suggesting.

* Zero_Cross.asc (2.81 kB - downloaded 15 times.)

A few hints/tips.
Rather than adding a shunt resistor, add the following SPICE directive:
.options gshunt = 1e-9

gshunt connects a conductance between all nodes and 0V. Conductance is the reciprocal of resistance, so the above statement adds 10-9S or 1/10-9Ω = 109Ω = 1GΩ between everything in the circuit and 0V.

Rather than using V(node_A)-V(node_B) in the plot, use V(node_A,node,B). It saves writing and makes the plot window less cluttered.

Use the signal symbol in [Misc] for AC voltages. It puts a nice sinewave symbol on the schematic, which makes it easier to see that it's AC.
 
The following users thanked this post: Bryan

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #13 on: November 08, 2024, 10:30:02 pm »
Thank you very much, will update my LtSpice project and play around with it further tonight. Much appreciated
-=Bryan=-
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #14 on: November 08, 2024, 10:38:23 pm »
@Zero999 - afaik LTspice adds automatically a "large resistor" between the COM and GND (as there is only one gnd).
I've tried to extract the value, but not successful.. Any idea how to get it?
Readers discretion is advised..
 

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #15 on: November 09, 2024, 09:52:08 am »

A few hints/tips.
Rather than adding a shunt resistor, add the following SPICE directive:
.options gshunt = 1e-9

gshunt connects a conductance between all nodes and 0V. Conductance is the reciprocal of resistance, so the above statement adds 10-9S or 1/10-9Ω = 109Ω = 1GΩ between everything in the circuit and 0V.

Rather than using V(node_A)-V(node_B) in the plot, use V(node_A,node,B). It saves writing and makes the plot window less cluttered.

Use the signal symbol in [Misc] for AC voltages. It puts a nice sinewave symbol on the schematic, which makes it easier to see that it's AC.

Thanks for the tips, how do you get the plot to auto display V(phase,neutral), do you have to do edit it manually every time by right clicking the plot and editing the label (expression editor)

Signal symbol in [Misc], not sure where that is in LtSPice ? I see it in the symbol in  your schematic, but not sure how I can reproduce it?
-=Bryan=-
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #16 on: November 09, 2024, 10:01:20 am »
Signal..
Readers discretion is advised..
 
The following users thanked this post: Bryan

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #17 on: November 09, 2024, 10:05:10 am »
 :-+
-=Bryan=-
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #18 on: November 09, 2024, 10:18:33 am »
Phase Neutral..
Mark the Neutral wire with "Mark Reference" symbol, you will see the symbol of the "reference" there (a small "probe"), and then you simply click on a wire and it shows you the graph with the diff against the reference..
Readers discretion is advised..
 
The following users thanked this post: Bryan

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20274
  • Country: gb
  • 0999
Re: Help with LTSPice
« Reply #19 on: November 09, 2024, 01:47:20 pm »
Phase Neutral..
Mark the Neutral wire with "Mark Reference" symbol, you will see the symbol of the "reference" there (a small "probe"), and then you simply click on a wire and it shows you the graph with the diff against the reference..
I've always simply typed it in. Note you have to right click the net to reveal the menu with mark reference.

@Zero999 - afaik LTspice adds automatically a "large resistor" between the COM and GND (as there is only one gnd).
I've tried to extract the value, but not successful.. Any idea how to get it?
Where did you hear that?

If that were the case, then a current would flow, if a high voltage source were connected between 0V and COM.
 
The following users thanked this post: Bryan

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5485
  • Country: va
Re: Help with LTSPice
« Reply #20 on: November 09, 2024, 02:03:26 pm »
I saw that on ltspice's groups.io forum, somebody wrote it there, as I can remember..
Now, when the COM is the same as GND there should be infinite current in your case.
But with the zero current it is "fully isolated" - that cannot be in ltspice, imho. floating.

https://groups.io/g/LTspice/message/138402?p=%2C%2C%2C20%2C0%2C0%2C0%3A%3Arecentpostdate%2Fsticky%2C%2Ccom+vs+gnd%2C20%2C2%2C0%2C91512989

PS: see below - the COM mostly work as a simple net label only, with one exception - when LTspice adds a resistor, imho..

« Last Edit: November 09, 2024, 03:43:45 pm by iMo »
Readers discretion is advised..
 

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #21 on: November 10, 2024, 01:30:04 am »
Phase Neutral..
Mark the Neutral wire with "Mark Reference" symbol, you will see the symbol of the "reference" there (a small "probe"), and then you simply click on a wire and it shows you the graph with the diff against the reference..

Hmm, for some reason when I right click the net the "Mark Reference" icon is greyed out.
-=Bryan=-
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20274
  • Country: gb
  • 0999
Re: Help with LTSPice
« Reply #22 on: November 10, 2024, 09:56:51 am »
I saw that on ltspice's groups.io forum, somebody wrote it there, as I can remember..
Now, when the COM is the same as GND there should be infinite current in your case.
But with the zero current it is "fully isolated" - that cannot be in ltspice, imho. floating.

https://groups.io/g/LTspice/message/138402?p=%2C%2C%2C20%2C0%2C0%2C0%3A%3Arecentpostdate%2Fsticky%2C%2Ccom+vs+gnd%2C20%2C2%2C0%2C91512989

PS: see below - the COM mostly work as a simple net label only, with one exception - when LTspice adds a resistor, imho..
My guess is LTSpice simply connects COM straight to 0V, if it's not connected to 0V.

Phase Neutral..
Mark the Neutral wire with "Mark Reference" symbol, you will see the symbol of the "reference" there (a small "probe"), and then you simply click on a wire and it shows you the graph with the diff against the reference..

Hmm, for some reason when I right click the net the "Mark Reference" icon is greyed out.
You need to run the simulation first.
« Last Edit: November 10, 2024, 10:08:56 am by Zero999 »
 
The following users thanked this post: Bryan

Offline BryanTopic starter

  • Frequent Contributor
  • **
  • Posts: 633
  • Country: ca
Re: Help with LTSPice
« Reply #23 on: November 10, 2024, 10:02:43 am »
Phase Neutral..
Mark the Neutral wire with "Mark Reference" symbol, you will see the symbol of the "reference" there (a small "probe"), and then you simply click on a wire and it shows you the graph with the diff against the reference..
Quote

Hmm, for some reason when I right click the net the "Mark Reference" icon is greyed out.
You need to run the simulation first.

That did the trick, thank you very much.
-=Bryan=-
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20274
  • Country: gb
  • 0999
Re: Help with LTSPice
« Reply #24 on: November 11, 2024, 06:34:52 pm »
This is interesting, it appears to just tie all unconnected nodes to 0V.


By the way, to the OP: it's possible to draw lines on the schematic, so you can have different symbols for earth, reference or whatever.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf