Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progressive precision loss #63

Open
Erhannis opened this issue Oct 21, 2021 · 0 comments
Open

Progressive precision loss #63

Erhannis opened this issue Oct 21, 2021 · 0 comments

Comments

@Erhannis
Copy link

I think that if you have a voltage -> inductor -> capacitor -> ground, and the voltage toggles from 0V to 1V, the voltage between the inductor and capacitor should become a sine wave...right? Like, once the voltage goes to 1V, the inductor spins up until it sorta bounces off the capacitor and the current starts flowing the other way, until the opposite happens and the current starts flowing back in the first direction. With ideal components, without resistance, this cycle should continue indefinitely, I think; right? (I'm using this program in part to learn about circuits.) However, what I find with JSpice is that the cycle tapers off pretty quick - but LESS quickly if I increase the sample rate. This suggests to me that numerical error is affecting the results. To get the cycle-drain to a vaguely manageable level, I'm having to increase the sample rate by a factor of like 400, which seems like a lot. Is there anything that can be done about that, or is it sortof just an imperfection we have to live with?

Here's some example code:

    private static final int SPS = 32000;
    public static void main(String[] args) {
        Netlist netlist = new Netlist();
        netlist.addNetListComponent(new NetlistDCVoltage("V1", 0.0, "1", "0"));
        netlist.addNetListComponent(new NetlistInductor("L1", 10E-4, "1", "2"));
        netlist.addNetListComponent(new NetlistCapacitor("C1", 10E-6, "2", "0"));
        int factor = 10;
        TransientConfig transientConfig = new TransientConfig("0.01s", (1.0/factor)/SPS+"s", new Square("V1", 0.25, "-0.001", 0.25, "2.0"));
        netlist.setSimulationConfig(transientConfig);
        SimulationResult simulationResult = JSpice.simulate(netlist);
        SimulationPlotter.plot(simulationResult, new String[]{"V(1)", "V(2)", "I(L1)"});
    }

which gives:
factor10

Increasing factor from 10 to 100 gives:
factor100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant