File indexing completed on 2024-05-05 05:46:11

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2006 by David Saxton                               *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef JFET_H
0012 #define JFET_H
0013 
0014 #include "nonlinear.h"
0015 
0016 class JFETState
0017 {
0018 public:
0019     JFETState();
0020     void reset();
0021 
0022     JFETState operator-(const JFETState &s) const;
0023 
0024     double A[3][3];
0025     double I[3];
0026 };
0027 
0028 class JFETSettings
0029 {
0030 public:
0031     JFETSettings();
0032 
0033     double V_Th; ///< zero-bias threshold voltage
0034     double beta; ///< transconductance parameter
0035     double I_S;  ///< gate-junction saturation current
0036     double N;    ///< gate pn emission coeffecient
0037     double N_R;  ///< Isr emission coefficient
0038 };
0039 
0040 /**
0041 @author David Saxton
0042  */
0043 class JFET : public NonLinear
0044 {
0045 public:
0046     enum JFET_type { nJFET, pJFET };
0047 
0048     JFET(JFET_type type);
0049     ~JFET() override;
0050 
0051     Type type() const override
0052     {
0053         return Element_JFET;
0054     }
0055     void update_dc() override;
0056     void add_initial_dc() override;
0057     JFETSettings settings() const
0058     {
0059         return m_jfetSettings;
0060     }
0061     void setJFETSettings(const JFETSettings &settings);
0062 
0063 protected:
0064     void updateCurrents() override;
0065     /**
0066      * Calculates the new JFETState from the voltages on the nodes.
0067      */
0068     void calc_eq();
0069 
0070     void calcIg(double V_GS, double V_GD, double V_DS, double *I_GS, double *I_GD, double *I_DS, double *g_GS, double *g_GD, double *g_DS, double *g_m) const;
0071 
0072     enum OpRegion { NormalCutoff, NormalSaturation, NormalLinear, InverseCutoff, InverseSaturation, InverseLinear };
0073     OpRegion getOpRegion(double V_DS, double V_GST, double V_GDT) const;
0074 
0075     void updateLim();
0076 
0077     JFETState m_os;
0078     JFETState m_ns;
0079     int m_pol;
0080     double V_GS_prev, V_GD_prev;
0081     double V_lim;
0082     JFETSettings m_jfetSettings;
0083 
0084     static const uint PinD, PinG, PinS;
0085 };
0086 
0087 #endif