Jump to content

Operational amplifier with finite power rails


Recommended Posts

I'm trying to model an operational with finite power rails of +5V and -5V.

The starting point of my approach is a non-inverting amplifier based on a sca_nullor and resistances R1 and R2 (see code below). At the output of this circuit, I put a TDF module for comparison of the output voltage with the levels of 5V and -5V. I used sca_tdf_vsink and sca_tdf_vsource to access to the input and output of this comparator.

#include <systemc-ams>

#include "comparator.h"

int sc_main(int argc, char* argv[])
{

  sc_core::sc_set_time_resolution(1.0, sc_core::SC_FS);

  ////////////////////////////////////////////////////////////////////////////
  // signal declarations                                                    //
  ////////////////////////////////////////////////////////////////////////////

  // input node for voltage source
  sca_eln::sca_node in("in");
  // output node
  sca_eln::sca_node vout_src_node("vout_src_node");
  // nodes for ideal op-amp
  sca_eln::sca_node aop_minus("aop_minus");
  sca_eln::sca_node aop_out("aop_out");
  // resistors for non-inverting op-amp
  // amplification is -r2/r1 -> in this case 200
  sca_eln::sca_r r1("r1",1e+3);
  sca_eln::sca_r r2("r2",200e+3);
  // output resistance load
  sca_eln::sca_r r("r",10e+3);
  // ideal op-amp
  sca_eln::sca_nullor i_aop("i_aop");

  // input & output voltage visualisation
  sca_eln::sca_tdf_vsink vin("vin");
  sca_eln::sca_tdf_vsink vout("vout");

  sca_eln::sca_tdf_vsource vout_src("vout_src");

  // value of the output voltage
  sca_tdf::sca_signal<double> vout_volt("vout_volt");
  // value of the clipped output voltage
  sca_tdf::sca_signal<double> vout_clipped("vout_clipped");
  // value of the input voltage source (for visualization purposes)
  sca_tdf::sca_signal<double> vin_volt("vin_volt");

  // parameters for input voltage source
  double init_value = 0.0;
  double offset = 0.0;
  double amplitude = 0.1;  
  double frequency = 50; 
  double phase = 0.0; 
  sc_core::sc_time delay(0.0, sc_core::SC_NS); 
  double ac_amplitude = 0.0;
  double ac_phase = 0.0;
  double ac_noise_amplitude = 0.0;

  sca_eln::sca_node_ref gnd("gnd");
  
  // comparator for ideal op-amp clipping
  comparator comp("comparator");
  comp.inp(vout_volt);
  comp.out(vout_clipped);

  // voltage source controlled by the comparator's voltage
  vout_src.n(gnd);
  vout_src.p(vout_src_node);
  vout_src.inp(vout_clipped);


  // input voltage source (50Hz sinus signal of 100mV amplitude)
  sca_eln::sca_vsource v_in("v_in", init_value, offset, amplitude, frequency, phase, delay, ac_amplitude, ac_phase, ac_noise_amplitude);
  v_in.p(in);
  v_in.n(gnd);
  v_in.set_timestep(.5,sc_core::SC_US);

  r.p(aop_out);
  //r.p(vout_src_node);
  r.n(gnd);


  r1.p(in);
  r1.n(aop_minus);

  vin.p(in);
  vin.n(gnd);
  vin.outp(vin_volt);

  vout.p(aop_out);
  vout.n(gnd);
  vout.outp(vout_volt);


  i_aop.nip(gnd);
  i_aop.nin(aop_minus);
  i_aop.nop(aop_out);
  i_aop.non(gnd);

  r2.p(aop_minus);
  r2.n(aop_out);
  //r2.n(vout_src_node);

  // trace signals                                                          //

  sca_util::sca_trace_file *tf = sca_util::sca_create_tabular_trace_file(
      "op_amp_trace.dat");
  sca_util::sca_trace(tf, vin_volt, "vin_volt");
  sca_util::sca_trace(tf, vout_volt, "vout_volt");
  sca_util::sca_trace(tf, vout_clipped, "vout_clipped");

  ////////////////////////////////////////////////////////////////////////////
  // time domain simulation                                                 //
  ////////////////////////////////////////////////////////////////////////////

  std::cout << "Simulation started..." << std::endl;

  //run s
  sc_core::sc_start(100, sc_core::SC_MS);

  sc_core::sc_stop();

  std::cout << "Simulation finished." << std::endl;

  return 0;
}

Code of comparator:

#ifndef _COMPARATOR_H
#define _COMPARATOR_H

SCA_TDF_MODULE(comparator){

	sca_tdf::sca_in <double> inp; // comparator input
	sca_tdf::sca_out <double> out; //comparator output

	SCA_CTOR(comparator)
		: inp("inp"),out("out")
	{}
    void set_attributes()
    {
        out.set_delay(1);

    }

	void processing(){
	
		if (inp.read()>5.0)
			out.write(5.0);
        else if (inp.read()<-5.0)
            out.write(-5.0);
		else
			out.write(inp.read());
	}

};

#endif

This work in this initial configuration. There are also attached plots illustrating the correct functioning of this circuit.

 

When I try to connect the resistance R2 (only by commenting the line r2.p(aop_out) and uncommenting the line r2.p(vout_src_node)) at the output of the comparator, I got the following error:

Error: SystemC-AMS: Initialization equation system failed in sca_linear_solver_0: 4
  The error is in the following net (max. 50): 
	r1
	vin
	v_in
	r2
	i_aop
	r
	vout
	vout_src

The error is may  be near: 
		vout_src  and 
		aop_out

I have a delay in my comparator, but apparently it is not sufficient to get working the simulation. The main goal is to simulate the resistance connected at the output of the comparator because this comparator will be integrated in the new component with sca_nullor.

Any ideas about this error?

I looked at the previous posts, and did not find the situations that were described in 

 

vout_clipped.png

vout.png

vin.png

Link to comment
Share on other sites

The nullor is not suitable for modelling a clamped operational amplifier, as it forces the voltage and current at the input terminals (i.e., its nullator side) to zero, but leaves the voltage and current at its output terminals (i.e., the norator side) completely undefined. This only works when a feedback path exists from the outpu to the negative input terminal. The voltage sink attached to the nullor output does not contribute an equation to the equation system. I suggest you replace the nullor with a voltage controlled voltage source with a sufficiently high gain. You may also need to add an artificial load resistance to its output in case the SystemC AMS PoC implementation should still have a problem to establish the equation system.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...