Author Topic: Micro-Cap simulation  (Read 3172 times)

0 Members and 1 Guest are viewing this topic.

Offline TenderfootTopic starter

  • Contributor
  • Posts: 10
  • Country: gb
Micro-Cap simulation
« on: May 27, 2024, 05:08:45 pm »
I decided to learn how to use Micro-Cap and the first project that came to mind was a linear bench PSU, variable voltage and variable current limiting. Maybe this was a bad choice. What I have found is that at various settings the simulation output is nice and stable, but alter the settings a little, or alter a component value a little and the output goes mad. I'm aware that PSU design is trickier than it might look, so am I asking too much of Micro-Cap (or any simulation for that matter)?
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3570
  • Country: nl
Re: Micro-Cap simulation
« Reply #1 on: May 27, 2024, 07:09:10 pm »
It is common for control loops to be stable in some configurations, and unstable in others. Modifying a single resistor, inductor or capacitor can be the difference between stable or unstable.

There is a lot of math involved, and simulators are a part of the toolbox to figuring out whether the math is applied correctly, or just to experiment with how to get a control loop to be stable.

If you were building the circuit in real life you may experience the same. Change the value of a small capacitor, and suddenly your whole circuit goes bonkers. Because of this, breadboards are not suitable for a lot of circuits. They always add capacitance due to the way they are designed, and this is not always within acceptable limits.
 
The following users thanked this post: Tenderfoot

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 20056
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Micro-Cap simulation
« Reply #2 on: May 27, 2024, 07:32:55 pm »
I decided to learn how to use Micro-Cap and the first project that came to mind was a linear bench PSU, variable voltage and variable current limiting. Maybe this was a bad choice. What I have found is that at various settings the simulation output is nice and stable, but alter the settings a little, or alter a component value a little and the output goes mad. I'm aware that PSU design is trickier than it might look, so am I asking too much of Micro-Cap (or any simulation for that matter)?

That is too vague for diagnosis, however...

The first thing you need to understand is the mathematics of feedback and control theory. Those models will give you a solid framework for understanding the kinds of thing that can happen in general systems.

After that, simulation can be useful doing the arithmetic for specific examples.

It is always worth remembering that all mathematical models are wrong, but some are useful.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: Tenderfoot

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27417
  • Country: nl
    • NCT Developments
Re: Micro-Cap simulation
« Reply #3 on: May 27, 2024, 08:06:59 pm »
I decided to learn how to use Micro-Cap and the first project that came to mind was a linear bench PSU, variable voltage and variable current limiting. Maybe this was a bad choice. What I have found is that at various settings the simulation output is nice and stable, but alter the settings a little, or alter a component value a little and the output goes mad. I'm aware that PSU design is trickier than it might look, so am I asking too much of Micro-Cap (or any simulation for that matter)?
What I don't like about Micro-Cap is that it continues to simulate the circuit even if you alter it to a state it won't work. Maybe that is your problem. I have not looked into configuring Micro-Cap to do a single shot simulation though.

Where it comes to simulation a control loop, you'll need to use techniques to do a frequency sweep over the control loop in order to find the loop's frequency response and phase margin. Especially current limiting can be tricky.
« Last Edit: May 27, 2024, 08:09:19 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 
The following users thanked this post: Tenderfoot

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6741
  • Country: ca
  • Non-expert
Re: Micro-Cap simulation
« Reply #4 on: May 27, 2024, 08:59:39 pm »
Maybe you can post the circuit and files here, so specific advice could be given.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 
The following users thanked this post: Tenderfoot

Offline TenderfootTopic starter

  • Contributor
  • Posts: 10
  • Country: gb
Re: Micro-Cap simulation
« Reply #5 on: May 28, 2024, 11:13:28 am »
Thanks for your replies. I think I didn't make myself clear in my first post. Although I might like to get this PSU built and working, it was more about learning Micro-cap. I've never used a simulation app before, apart from some very basic LT Spice circuits. A couple of replies say I need to do the maths, well that's never going to happen. I wouldn't know where to start, and I'm certain it'd be way beyond me. So my question really is... am I wasting my time trying to get the circuit working in a random 'hit and hope' approach? I can post the circuit if anyone is really interested, though I'd be a little embarrassed, it's just a couple of opamps, sense resistor and pass transistors.
 

Offline Sensorcat

  • Regular Contributor
  • *
  • Posts: 71
  • Country: de
  • Freelance Sensor Consultant
    • Sensorberatung
Re: Micro-Cap simulation
« Reply #6 on: May 28, 2024, 11:49:48 am »
So my question really is... am I wasting my time trying to get the circuit working in a random 'hit and hope' approach?
It depends what you expect. Best is to know the theory, the math, to be able to calculate a circuit before simulation. Without this, you can perhaps take known, proven circuits and adapt them somewhat, using an intuitive understanding of the function. But in general, there are far too many permutations to develop circuits in a random manner.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3570
  • Country: nl
Re: Micro-Cap simulation
« Reply #7 on: May 28, 2024, 12:26:54 pm »
You don't have to know all the math, but you do need a background of how control loops and their stability works. Things like bode plots, phase margin and how to interpret them from simulation results.
With that background you can make guesstimates and tweaks to push your circuit towards stability and something that "works".
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6741
  • Country: ca
  • Non-expert
Re: Micro-Cap simulation
« Reply #8 on: May 28, 2024, 07:55:50 pm »
I can post the circuit if anyone is really interested, though I'd be a little embarrassed, it's just a couple of opamps, sense resistor and pass transistors.

When you go to a forum to ask a question, its best to provide as much relevant information and files as is reasonable.
- Always post a schematic if you have one
- Always post PCB layout if you have one
- etc.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 20056
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Micro-Cap simulation
« Reply #9 on: May 28, 2024, 09:08:19 pm »
A couple of replies say I need to do the maths, well that's never going to happen. I wouldn't know where to start, and I'm certain it'd be way beyond me.

We were all in that position at one time!

Just as you did when learning how basic op-amp circuits work, so you can use a similar level of maths to gain a basic understanding of control systems. If you can understand tutorials that show you why de-compensated op-amps cannot be used as unity-gain amplifiers, then you will be able to understand basic control theory. After all, even simple op-amp circuits like inverting amplifiers are control systems.

Yes, control theory can become very complex and fine-grained, but much of the visible behaviour can be understood intuitively - based on a little maths.

Quote
So my question really is... am I wasting my time trying to get the circuit working in a random 'hit and hope' approach?

Probably, yes. That's true of all circuits.

A simulator will answer the question it is asked, no more. It is up to the engineer's good taste to decide which questions are worth asking. Most questions aren't!

Quote
I can post the circuit if anyone is really interested, though I'd be a little embarrassed, it's just a couple of opamps, sense resistor and pass transistors.

Normally I would say the circuit and simulation should be posted. However in this case I think you are right not to bother posting them. If posted, this thread would start examining individual trees, and fail to see the wood.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Online shapirus

  • Super Contributor
  • ***
  • Posts: 1609
  • Country: ua
Re: Micro-Cap simulation
« Reply #10 on: May 28, 2024, 09:37:58 pm »
it's just a couple of opamps, sense resistor and pass transistors.
Devil is in the details. Post it.
Circuits like what you described are usually simulated just fine. Of course undesired oscillations are sometimes simulated too, and that's a good thing.
 

Offline TenderfootTopic starter

  • Contributor
  • Posts: 10
  • Country: gb
Re: Micro-Cap simulation
« Reply #11 on: May 29, 2024, 03:24:18 pm »
Ok, I'll post the circuit for your amusement. I have several different versions as I played with values etc, so give me time to tidy things up before I post. Obviously it's in Micro-cap so what do you want, a jpeg, Micro-cap files? If you want the MC files, how do I post them?
 

Online shapirus

  • Super Contributor
  • ***
  • Posts: 1609
  • Country: ua
Re: Micro-Cap simulation
« Reply #12 on: May 29, 2024, 03:51:01 pm »
so what do you want, a jpeg, Micro-cap files?
A .png, at least. Well, it will still be converted to jpeg by the forum engine, but that's one less quality loss step than if it's a jpeg originally.

Microcap files might still be of interest to someone, though. If you do attach them, a zip file is a usual way to do it. But a picture of the schematic is a minimum.
 

Offline TenderfootTopic starter

  • Contributor
  • Posts: 10
  • Country: gb
Re: Micro-Cap simulation
« Reply #13 on: May 29, 2024, 05:39:34 pm »
Here's a couple of screenshots of my circuit. The switches on the o/p are to add different loads during simulation, odd resistor values are a result of stepping through different values, capacitors have been added at various places at times, opamp U2B has been configured as differential amp or simple comparator at times too. In the o/p trace the red indicates the circuit is in current limit. As you can see the o/p at 10 volts is unstable during and after the first current limit, if I set the o/p to 25 volts there is way less instability. Perhaps I've set the simulation up incorrectly, remember this is my first attempt at Micro-Cap or any simulation really.
 

Online shapirus

  • Super Contributor
  • ***
  • Posts: 1609
  • Country: ua
Re: Micro-Cap simulation
« Reply #14 on: May 29, 2024, 06:06:57 pm »
What happens if you remove C2?
 

Offline TenderfootTopic starter

  • Contributor
  • Posts: 10
  • Country: gb
Re: Micro-Cap simulation
« Reply #15 on: May 29, 2024, 06:21:49 pm »
What happens if you remove C2?

Slightly better but not 'good', tbh I didn't notice I'd left that in there.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27417
  • Country: nl
    • NCT Developments
Re: Micro-Cap simulation
« Reply #16 on: May 29, 2024, 07:02:36 pm »
I'd check the output of U1B for oscillations.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online shapirus

  • Super Contributor
  • ***
  • Posts: 1609
  • Country: ua
Re: Micro-Cap simulation
« Reply #17 on: May 29, 2024, 07:22:42 pm »
That's also quite a feedback loop you've got there.

I would simplify all those pass transistors to something more basic and see if that would improve things. That's a general way of troubleshooting, especially with simulations: remove unnecessary parts until it starts to work correctly, then start adding them back to analyze what might be causing the issues.

Additionally, try adding a small cap (tens-hundreds of pF as a starting point) in parallel with R60, if I understand your schematic correctly (which is not necessarily true).
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27417
  • Country: nl
    • NCT Developments
Re: Micro-Cap simulation
« Reply #18 on: May 29, 2024, 08:26:50 pm »
Another potential problem could be around U2A. I don't know if the simulation model for U2A is a 100% functional equivalent where it comes to overdriving the opamp, but if it is then U2 may cause havoc when it is overdriven. U2A needs to be a comparotor; definitely not an opamp. When an opamp is overdriven, the impedance of the inputs can get really low and all kinds of other weird effects can happen depending on how an opamp is constructed. Never use an opamp as a comparator!

Edit: this goes for U2A which drives the LED
« Last Edit: May 29, 2024, 09:38:47 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online shapirus

  • Super Contributor
  • ***
  • Posts: 1609
  • Country: ua
Re: Micro-Cap simulation
« Reply #19 on: May 29, 2024, 08:40:10 pm »
U2 needs to be a comparotor; definitely not an opamp.
Are you sure? It's the thing that actually maintains the output voltage, isn't it? I mean U2B specifically. It's wired as a differential amplifier to amplify the difference between the output voltage (the positive terminal of C_out) and the "Set voltage" VDC source.
The bigger the difference, the harder it drives the base of Q1, which in turn pulls the base of Q2 more to ground, which in turn reduces the current flowing through Q3 and Q4, thereby reducing the output voltage and completing the feedback loop.

@Tenderfoot, C1 is also not needed (unless I'm wrong) and can actually cause oscillation as it adds (a lot of) unwanted capacitance inside the feedback loop. Try removing it. Then C3... I'm not sure about it, but it won't hurt to remove it as well while you're troubleshooting the circuit.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27417
  • Country: nl
    • NCT Developments
Re: Micro-Cap simulation
« Reply #20 on: May 29, 2024, 09:39:39 pm »
U2 needs to be a comparotor; definitely not an opamp.
Are you sure? It's the thing that actually maintains the output voltage, isn't it? I mean U2B specifically. It's wired as a differential amplifier to amplify the difference between the output voltage (the positive terminal of C_out) and the "Set voltage" VDC source.
Good catch! I meant U2A which drives the LED. This is a comparator application for which you really shouldn't use an opamp.

Capacitor C1 is likely necessary as this adds a low-pass filter to the feedback loop and thus makes it more stable. It would be nice if the OP can share the original circuit.
« Last Edit: May 29, 2024, 09:44:58 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline TenderfootTopic starter

  • Contributor
  • Posts: 10
  • Country: gb
Re: Micro-Cap simulation
« Reply #21 on: May 29, 2024, 10:20:00 pm »

[/quote]
Good catch! I meant U2A which drives the LED. This is a comparator application for which you really shouldn't use an opamp.
It would be nice if the OP can share the original circuit.
[/quote]

Is using an opamp as a comparator really such a sin? Well It's easy for me to remove it. As for 'the original circuit' this IS my original circuit, though I'm not claiming copyright on it  :)

Frustratingly, following a couple of suggestions, I got the thing working much better, then...  it all went haywire. I have no idea what I did, but I now have a headache and I'm off to bed!
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27417
  • Country: nl
    • NCT Developments
Re: Micro-Cap simulation
« Reply #22 on: May 30, 2024, 12:44:09 pm »
Quote
Good catch! I meant U2A which drives the LED. This is a comparator application for which you really shouldn't use an opamp.
It would be nice if the OP can share the original circuit.

Is using an opamp as a comparator really such a sin?
Yes it is  :) https://www.analog.com/en/resources/analog-dialogue/raqs/raq-issue-11.html
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline TenderfootTopic starter

  • Contributor
  • Posts: 10
  • Country: gb
Re: Micro-Cap simulation
« Reply #23 on: May 31, 2024, 02:27:35 pm »
It's time for me to quit on this, I'm spending too much time playing with trying to get this PSU to work. It's not a failure though. This was never about getting the PSU to work, I never expected it to, I was always aware they can be troublesome. It was about learning how to use Micro-Cap (which is why I posted in the  CAD forum). I've discovered a lot about it's features, though there are still more that I don't understand yet. So, just a thank-you to all who responded with your suggestions, hints and tips. No doubt I'll be back with more questions in the future, but I'll try to make them more specific.
 
The following users thanked this post: nctnico

Online shapirus

  • Super Contributor
  • ***
  • Posts: 1609
  • Country: ua
Re: Micro-Cap simulation
« Reply #24 on: May 31, 2024, 04:08:05 pm »
It's time for me to quit on this, I'm spending too much time playing with trying to get this PSU to work. It's not a failure though. This was never about getting the PSU to work, I never expected it to, I was always aware they can be troublesome. It was about learning how to use Micro-Cap (which is why I posted in the  CAD forum). I've discovered a lot about it's features, though there are still more that I don't understand yet. So, just a thank-you to all who responded with your suggestions, hints and tips. No doubt I'll be back with more questions in the future, but I'll try to make them more specific.
One way or another, you may want to try a different simulation software the next time. For example, Kicad + ngspice (they're not ideal and have some rough corners, but both are actively developed). Microcap is abandoned, so it's probably not the best choice to invest time into.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf