Skip to main content

sciforge_core/electronics/
devices.rs

1use crate::moleculars::Material;
2use sciforge_hub::prelude::physics::electronics::amplifiers as sf_amp;
3use sciforge_hub::prelude::physics::electronics::semiconductor_devices as sf_semi;
4
5#[derive(Debug, Clone, Copy)]
6pub struct Bjt {
7    pub material: Material,
8    pub beta: f64,
9    pub early_voltage_v: f64,
10}
11
12impl Bjt {
13    pub fn new(material: Material, beta: f64, early_voltage_v: f64) -> Self {
14        Self { material, beta, early_voltage_v }
15    }
16
17    pub fn collector_current_a(&self, base_current_a: f64) -> f64 {
18        sf_semi::bjt_ic_active(self.beta, base_current_a)
19    }
20
21    pub fn emitter_current_a(&self, base_current_a: f64) -> f64 {
22        let ic = self.collector_current_a(base_current_a);
23        sf_semi::bjt_ie(ic, base_current_a)
24    }
25
26    pub fn alpha(&self) -> f64 {
27        sf_semi::bjt_alpha(self.beta)
28    }
29
30    pub fn early_effect_a(&self, ic0: f64, vce: f64) -> f64 {
31        sf_semi::early_effect(ic0, vce, self.early_voltage_v)
32    }
33
34    pub fn transconductance_s(&self, collector_current_a: f64, temperature_k: f64) -> f64 {
35        sf_amp::transconductance(collector_current_a, sf_amp::thermal_voltage(temperature_k))
36    }
37
38    pub fn common_emitter_gain(&self, collector_current_a: f64, load_ohm: f64, temperature_k: f64) -> f64 {
39        let gm = self.transconductance_s(collector_current_a, temperature_k);
40        sf_amp::common_emitter_voltage_gain(gm, load_ohm)
41    }
42}
43
44#[derive(Debug, Clone, Copy)]
45pub struct Mosfet {
46    pub material: Material,
47    pub kn: f64,
48    pub vth_v: f64,
49}
50
51impl Mosfet {
52    pub fn new(material: Material, kn: f64, vth_v: f64) -> Self {
53        Self { material, kn, vth_v }
54    }
55
56    pub fn drain_current_saturation_a(&self, vgs_v: f64) -> f64 {
57        sf_semi::mosfet_drain_current_saturation(self.kn, vgs_v, self.vth_v)
58    }
59
60    pub fn drain_current_linear_a(&self, vgs_v: f64, vds_v: f64) -> f64 {
61        sf_semi::mosfet_drain_current_linear(self.kn, vgs_v, self.vth_v, vds_v)
62    }
63
64    pub fn threshold_with_body_effect_v(&self, gamma: f64, vsb_v: f64, phi_v: f64) -> f64 {
65        sf_semi::mosfet_threshold_body_effect(self.vth_v, gamma, vsb_v, phi_v)
66    }
67
68    pub fn dibl_threshold_v(&self, sigma: f64, vds_v: f64) -> f64 {
69        sf_semi::drain_induced_barrier_lowering(self.vth_v, sigma, vds_v)
70    }
71}
72
73#[derive(Debug, Clone, Copy)]
74pub struct OpAmp {
75    pub gain_bandwidth_hz: f64,
76}
77
78impl OpAmp {
79    pub fn new(gain_bandwidth_hz: f64) -> Self {
80        Self { gain_bandwidth_hz }
81    }
82
83    pub fn inverting_gain(&self, feedback_ohm: f64, input_ohm: f64) -> f64 {
84        sf_amp::inverting_gain(feedback_ohm, input_ohm)
85    }
86
87    pub fn non_inverting_gain(&self, feedback_ohm: f64, input_ohm: f64) -> f64 {
88        sf_amp::non_inverting_gain(feedback_ohm, input_ohm)
89    }
90
91    pub fn differential_gain(&self, feedback_ohm: f64, input_ohm: f64) -> f64 {
92        sf_amp::differential_gain(feedback_ohm, input_ohm)
93    }
94
95    pub fn summing_output_v(&self, inputs_v: &[f64], input_resistors_ohm: &[f64], feedback_ohm: f64) -> f64 {
96        sf_amp::summing_amplifier(inputs_v, input_resistors_ohm, feedback_ohm)
97    }
98
99    pub fn integrator_output_v(&self, input_v: f64, resistance_ohm: f64, capacitance_f: f64, time_s: f64) -> f64 {
100        sf_amp::integrator_output(input_v, resistance_ohm, capacitance_f, time_s)
101    }
102
103    pub fn differentiator_output_v(&self, dv_dt: f64, resistance_ohm: f64, capacitance_f: f64) -> f64 {
104        sf_amp::differentiator_output(dv_dt, resistance_ohm, capacitance_f)
105    }
106
107    pub fn bandwidth_hz(&self, gain: f64) -> f64 {
108        self.gain_bandwidth_hz / gain
109    }
110
111    pub fn gain_at_bandwidth(&self, bandwidth_hz: f64) -> f64 {
112        sf_amp::gain_bandwidth_product(self.gain_bandwidth_hz / bandwidth_hz, bandwidth_hz)
113            / bandwidth_hz
114    }
115}
116
117pub fn decibel_voltage(v_out: f64, v_in: f64) -> f64 {
118    sf_amp::decibel_voltage(v_out, v_in)
119}
120
121pub fn decibel_power(p_out: f64, p_in: f64) -> f64 {
122    sf_amp::decibel_power(p_out, p_in)
123}
124
125pub fn cascaded_gain_db(gains_db: &[f64]) -> f64 {
126    sf_amp::cascaded_gain(gains_db)
127}
128
129pub fn noise_figure_db(snr_in: f64, snr_out: f64) -> f64 {
130    sf_amp::noise_figure(snr_in, snr_out)
131}
132
133pub fn friis_noise_factor(factors: &[f64], gains: &[f64]) -> f64 {
134    sf_amp::friis_noise_factor(factors, gains)
135}