Help with LTSPice - Page 1
Forum section: electronics / projects

author: Bryan
author_rank: Frequent Contributor
timestamp: November 08, 2024, 06:44:50 pm
content: 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

author: iMo
author_rank: Super Contributor
timestamp: November 08, 2024, 07:14:56 pm
content: 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)

author: Bryan
author_rank: Frequent Contributor
timestamp: November 08, 2024, 07:22:18 pm
content: 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?

author: Bryan
author_rank: Frequent Contributor
timestamp: November 08, 2024, 07:23:14 pm
content: I responded before your edit. thanks so much for the info

author: iMo
author_rank: Super Contributor
timestamp: November 08, 2024, 07:32:49 pm
content: ..also I would use an 1N4007 when messing with directly coupled mains voltages..

author: Bryan
author_rank: Frequent Contributor
timestamp: November 08, 2024, 07:38:32 pm
content: Yes, kind of wondered why the author spec'd a 1N4148, seemed a bit dicey

author: iMo
author_rank: Super Contributor
timestamp: November 08, 2024, 07:48:19 pm
content: 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..

author: Bryan
author_rank: Frequent Contributor
timestamp: November 08, 2024, 08:22:22 pm
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: November 08, 2024, 08:43:17 pm
content: 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.

author: iMo
author_rank: Super Contributor
timestamp: November 08, 2024, 08:48:59 pm
content: 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).

author: Bryan
author_rank: Frequent Contributor
timestamp: November 08, 2024, 08:51:42 pm
content: Quote from: Zero999 on November 08, 2024, 08:43:17 pmYes, 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.

author: iMo
author_rank: Super Contributor
timestamp: November 08, 2024, 09:22:46 pm
content: 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).

author: Zero999
author_rank: Super Contributor
timestamp: November 08, 2024, 10:18:26 pm
content: Yes, that will work.Here's what I was suggesting.Zero_Cross.asc(2.81 kB - downloaded 23 times.)A few hints/tips.Rather than adding a shunt resistor, add the following SPICE directive:.options gshunt = 1e-9gshunt connects a conductance between all nodes and 0V. Conductance is the reciprocal of resistance, so the above statement adds 10-9S or1/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  for AC voltages. It puts a nice sinewave symbol on the schematic, which makes it easier to see that it's AC.

author: Bryan
author_rank: Frequent Contributor
timestamp: November 08, 2024, 10:30:02 pm
content: Thank you very much, will update my LtSpice project and play around with it further tonight. Much appreciated

author: iMo
author_rank: Super Contributor
timestamp: November 08, 2024, 10:38:23 pm
content: @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?

author: Bryan
author_rank: Frequent Contributor
timestamp: November 09, 2024, 09:52:08 am
content: Quote from: Zero999 on November 08, 2024, 10:18:26 pmThanks 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 , not sure where that is in LtSPice ? I see it in the symbol in your schematic, but not sure how I can reproduce it?

author: iMo
author_rank: Super Contributor
timestamp: November 09, 2024, 10:01:20 am
content: Signal..

author: iMo
author_rank: Super Contributor
timestamp: November 09, 2024, 10:18:33 am
content: 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..

author: Zero999
author_rank: Super Contributor
timestamp: November 09, 2024, 01:47:20 pm
content: Quote from: iMo on November 09, 2024, 10:18:33 amI've always simply typed it in. Note you have to right click the net to reveal the menu with mark reference.Quote from: iMo on November 08, 2024, 10:38:23 pmWhere 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.

author: iMo
author_rank: Super Contributor
timestamp: November 09, 2024, 02:03:26 pm
content: 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%2C91512989PS: see below - the COM mostly work as a simple net label only, with one exception - when LTspice adds a resistor, imho..

author: Bryan
author_rank: Frequent Contributor
timestamp: November 10, 2024, 01:30:04 am
content: Quote from: iMo on November 09, 2024, 10:18:33 amHmm, for some reason when I right click the net the "Mark Reference" icon is greyed out.

author: Zero999
author_rank: Super Contributor
timestamp: November 10, 2024, 09:56:51 am
content: Quote from: iMo on November 09, 2024, 02:03:26 pmMy guess is LTSpice simply connects COM straight to 0V, if it's not connected to 0V.Quote from: Bryan on November 10, 2024, 01:30:04 amYou need to run the simulation first.

author: Bryan
author_rank: Frequent Contributor
timestamp: November 10, 2024, 10:02:43 am
content: Quote from: iMo on November 09, 2024, 10:18:33 amThat did the trick, thank you very much.

author: Zero999
author_rank: Super Contributor
timestamp: November 11, 2024, 06:34:52 pm
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: December 31, 2024, 07:36:40 pm
content: Quote from: iMo on November 08, 2024, 10:38:23 pmI've recently found this on ltwiki:Quotehttps://ltwiki.org/index.php?title=Undocumented_LTspice#.options_Gfloat.3D.3Cvalue.3EI can't be sure it's true, but it would explain the behaviour demonstrated above.