Micro-Cap SPICE simulator bug or user problem - Page 1
Forum section: electronics / projects

author: joeqsmith
author_rank: Super Contributor
timestamp: September 24, 2025, 07:21:32 pm
content: I was attempting to run an AC analysis today and got side tracked by what appears to be a bug. For this example, I have a voltage ratio or Vout/Vin = 0.1. I want to convert that to dB..define VGAIN (V(OUT)/V(IN)) - Results in 0.1 as expected.define TEST1 20*LOG10(0.1) - Results in -20 as expected.define TEST2 20*LOG10(VGAIN) - Results in +20?.define TEST3 20*LOG10(V(OUT)/V(IN)) - Results in +20?.define TEST4 dB(VGAIN) - Results in -20 as expectedThis is some pretty basic Bob stuff. Problem between the keyboard and chair, or is this a bug? Doing an internet search, I came up with nothing.

author: Whales
author_rank: Super Contributor
timestamp: September 24, 2025, 10:28:56 pm
content: (Not a micro-cap person) Could V(out) or V(in) be vectors? Vector division might be doing something interesting.

author: joeqsmith
author_rank: Super Contributor
timestamp: September 24, 2025, 11:25:16 pm
content: Thanks. "V" is the voltage across a node, "I" is the current through it. V(1) for example is the voltage of node 1 relative to ground.Why dB(x) is not the same as 20*LOG10(x), is really strange. It's not a problem with 20*LOG10(x) as that works with a constant value of x. This problem stopped me dead in my tracks.

author: Whales
author_rank: Super Contributor
timestamp: September 25, 2025, 07:29:15 am
content: I think we're talking about different things. In the software I'm used to V(1) could be a vector.Was your AC analysis done at a single frequency (so each node has a single voltage), or a sweep across a range of frequencies (so each node is a list of voltages)?

author: joeqsmith
author_rank: Super Contributor
timestamp: September 25, 2025, 01:13:55 pm
content: During AC analysis, the frequency is swept.Page 206 Chapter 7: AC AnalysisQuoteYou may find the manual here:https://www.iee.et.tu-dresden.de/~jmueller/simulation/soft/microcap/MC12.RefManual.pdf

author: Terry Bites
author_rank: Super Contributor
timestamp: September 26, 2025, 11:38:51 am
content: Why are you using .definetest blah blah blah?You can do all the db stuff in the AC analysis dialog box.

author: RoGeorge
author_rank: Super Contributor
timestamp: September 26, 2025, 12:39:24 pm
content: I don't know about MicroCap, it is not maintained any more, but I guess it might be related with the voltage represented as complex numbers in AC analysis.I would try the same math expressions, but with mag(Vout)/mag(Vin), or whatever the name is in MicroCap to denote the magnitude of a complex number.

author: joeqsmith
author_rank: Super Contributor
timestamp: September 26, 2025, 01:56:38 pm
content: Quote from: Terry Bites on September 26, 2025, 11:38:51 amYou still have to enter the data into the AC analysis dialog box, but I keep the equations on the schematic for documentation purposes. I'll try moving the equations and see if it has any effect.***Moving the equations onto the AC menu makes no difference in the sign reversal.

author: thm_w
author_rank: Super Contributor
timestamp: September 26, 2025, 09:53:19 pm
content: These all give me the same number of -20 for a resistor divider- dB(0.1)- dB(V(VOUT)/V(VIN))- 20*LOG(0.1)- 20*LOG10(0.1)- 20*LOG10(V(VOUT)/V(VIN))But when I added a cap the last line did not match up at all. So its treating something differently.The V(VOUT)/V(VIN) part works fine. But the LOG function is the issue.

author: joeqsmith
author_rank: Super Contributor
timestamp: September 27, 2025, 12:32:45 pm
content: Thanks for verifying this effect. Let me know if you have any ideas as to why this happens. It seems totally unexpected.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 27, 2025, 02:00:27 pm
content: I still suspect Whales could be right. Node voltages in transient sim are vectors, not single values. Otherwise, you should strictly use ONLY a OP (operating point) analysis, if you want a single value.I don't know much about MicroCap, but in general, for this kind of calculation over transient simulations, you'd use either a FIND statement to locate a specific voltage at a specific time or condition, or use an average or RMS function.Likewise for AC analysis, you get vectors and need to specify the frequency at which you want the values to be computed, or use averaging functions first.This would explain why this works with pure resistive circuits, but fails once you introduce elements that will get a non-static transient simulation, or for AC, a non-constant value. Just a thought.

author: joeqsmith
author_rank: Super Contributor
timestamp: September 27, 2025, 03:59:45 pm
content: Quote from: SiliconWizard on September 27, 2025, 02:00:27 pmI doubt many users are using purely resistive components. Per my OP, this is an AC analysis not transient. Yes, you specify the frequency range to run it. dB, log and log10 all use Z.

author: joeqsmith
author_rank: Super Contributor
timestamp: September 27, 2025, 04:04:28 pm
content: Trying a different SPICE tool, both dB and LOG10 get the sign correct.AC analysis, 1M to 500M sweep. With small cap to make people happy.

author: joeqsmith
author_rank: Super Contributor
timestamp: September 27, 2025, 05:11:43 pm
content: Another flavor of SPICE and the sign is correct.

author: joeqsmith
author_rank: Super Contributor
timestamp: September 27, 2025, 05:33:03 pm
content: And yet another SPICE tool with the correct sign.

author: joeqsmith
author_rank: Super Contributor
timestamp: September 27, 2025, 05:57:33 pm
content: I'm not a fan of LTSPICE because it is so different. If you plot VOUT/VIN on the log scale, it shows the correct sign. However, it you use a linear scale then plot 20LOG10, the sign is incorrect..

author: Ian.M
author_rank: Super Contributor
timestamp: September 27, 2025, 10:05:23 pm
content: Try:Code:20*LOG10(MAG(V(out)/V(in)))

author: joeqsmith
author_rank: Super Contributor
timestamp: September 28, 2025, 01:09:08 am
content: Quote from: Ian.M on September 27, 2025, 10:05:23 pmI tried it with LTSPICE and saw no difference.

author: Ian.M
author_rank: Super Contributor
timestamp: September 28, 2025, 02:22:04 am
content: It seems to be a quirk of .ac analysis mode that it displays negative values as their magnitude with 180° phase. This is somewhat logical considering the nature of Log and dB scales.Code:.meas n PARAM log10(0.01).meas m PARAM log10(100)logs:Code:n: log10(0.01)=(6.0206dB,180°)m: log10(100)=(6.0206dB,0°)Try adding traces 25 and -25.1 to your linear plot and TURN ON phase display!

author: joeqsmith
author_rank: Super Contributor
timestamp: September 28, 2025, 03:19:55 am
content: 20log10 should be the same as dB without the sign change. Three programs have it right, two do not. I would have thought it was pretty basic and was surprised there would have been any discrepancy.I doubt I will do any more with it.