File indexing completed on 2024-04-28 05:43:15
0001 /*************************************************************************** 0002 * Copyright (C) 2003-2004 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 DIODE_H 0012 #define DIODE_H 0013 0014 #include "nonlinear.h" 0015 0016 class DiodeSettings 0017 { 0018 public: 0019 DiodeSettings(); 0020 void reset(); 0021 0022 double I_S; ///< Diode saturation current 0023 double N; ///< Emission coefficient 0024 double V_B; ///< Reverse breakdown 0025 // double R; ///< Series resistance 0026 }; 0027 0028 /** 0029 This simulates a diode. The simulated diode characteristics are: 0030 0031 @li I_s: Diode saturation current 0032 @li V_T: Thermal voltage = kT/4 = 25mV at 20 C 0033 @li n: Emission coefficient, typically between 1 and 2 0034 @li V_RB: Reverse breakdown (large negative voltage) 0035 @li G_RB: Reverse breakdown conductance 0036 @li R_D: Base resistance of diode 0037 0038 @short Simulates the electrical property of diode-ness 0039 @author David Saxton 0040 */ 0041 class Diode : public NonLinear 0042 { 0043 public: 0044 Diode(); 0045 ~Diode() override; 0046 0047 void update_dc() override; 0048 void add_initial_dc() override; 0049 Element::Type type() const override 0050 { 0051 return Element_Diode; 0052 } 0053 DiodeSettings settings() const 0054 { 0055 return m_diodeSettings; 0056 } 0057 void setDiodeSettings(const DiodeSettings &settings); 0058 /** 0059 * Returns the current flowing through the diode 0060 */ 0061 double current() const; 0062 0063 protected: 0064 void updateCurrents() override; 0065 void calc_eq(); 0066 void calcIg(double V, double *I, double *g) const; 0067 void updateLim(); 0068 0069 double g_new, g_old; 0070 double I_new, I_old; 0071 double V_prev; 0072 double V_lim; 0073 0074 DiodeSettings m_diodeSettings; 0075 }; 0076 0077 #endif