Chapter 13: Modeling Best Practices

AMS LSF and ELN

Modeling continuous-time differential equations and electrical circuits with SystemC AMS LSF and ELN.

AMS LSF and ELN

While Timed Data Flow (TDF) handles discrete-time sampled signals, sometimes you need to model pure continuous-time physical systems. The SystemC AMS LRM provides Linear Signal Flow (LSF) and Electrical Linear Networks (ELN).

Linear Signal Flow (LSF)

LSF models continuous-time behavior by building block diagrams of mathematical operations (Adders, Multipliers, Integrators). The AMS solver compiles these blocks into a system of linear differential equations and solves them continuously.

LSF Example: First-Order Low-Pass Filter

#include <systemc>
#include <systemc-ams.h>
 
SC_MODULE(LSF_Filter) {
    sca_lsf::sca_in in;
    sca_lsf::sca_out out;
 
    // Internal LSF signals and blocks
    sca_lsf::sca_signal sig_sub, sig_gain, sig_int;
    
    sca_lsf::sca_sub sub;
    sca_lsf::sca_gain gain;
    sca_lsf::sca_integ integ;
 
    SC_CTOR(LSF_Filter) 
        : in("in"), out("out"), sig_sub("sig_sub"), sig_gain("sig_gain"), sig_int("sig_int"),
          sub("sub"), gain("gain", 1000.0), integ("integ") 
    {
        // 1. subtract: sig_sub = in - out (Feedback loop)
        sub.x1(in);
        sub.x2(out);
        sub.y(sig_sub);
 
        // 2. gain: sig_gain = sig_sub * 1000.0
        gain.x(sig_sub);
        gain.y(sig_gain);
 
        // 3. integrator: out = integral(sig_gain)
        integ.x(sig_gain);
        integ.y(out);
    }
};
 
int sc_main(int argc, char* argv[]) {
    // Boilerplate for wrapping LSF inside TDF or DE omitted for brevity.
    // LSF systems are mathematically resolved by the AMS solver seamlessly.
    return 0;
}

Electrical Linear Networks (ELN)

ELN allows you to model physical circuits using standard electrical components. This is similar to SPICE, but restricted to linear components for massive speed improvements. The solver uses Modified Nodal Analysis (MNA).

ELN Example: RC Circuit

#include <systemc>
#include <systemc-ams.h>
 
SC_MODULE(ELN_Circuit) {
    // Electrical nodes
    sca_eln::sca_node n1, n2;
    sca_eln::sca_node_ref gnd; // Ground reference (0V)
 
    // Components
    sca_eln::sca_vsource src; // Voltage source
    sca_eln::sca_r r1;        // Resistor
    sca_eln::sca_c c1;        // Capacitor
 
    SC_CTOR(ELN_Circuit) 
        : n1("n1"), n2("n2"), gnd("gnd"),
          src("src", 0.0, 5.0, 1000.0), // 5V sine wave at 1kHz
          r1("r1", 1000.0),             // 1k Ohm
          c1("c1", 1.0e-6)              // 1 Microfarad
    {
        // Connect voltage source between ground and node 1
        src.p(n1);
        src.n(gnd);
 
        // Connect resistor between node 1 and node 2
        r1.p(n1);
        r1.n(n2);
 
        // Connect capacitor between node 2 and ground
        c1.p(n2);
        c1.n(gnd);
    }
};
 
int sc_main(int argc, char* argv[]) {
    ELN_Circuit rc("rc");
    sc_core::sc_start(2, sc_core::SC_MS);
    return 0;
}

SystemC AMS automatically converts ELN circuits into matrix equations. While not replacing full SPICE simulation for non-linear transistor analysis, ELN is perfect for modeling PCB traces, simple power grids, and analog filters at a system level.

Comments and Corrections