Skip to main content

reda_spice/model/control/
meas.rs

1use reda_unit::{Number, Time};
2
3#[derive(Debug, Clone)]
4pub enum MeasureCommand {
5    Rise(MeasureRise),
6    BasicStat(MeasureBasicStat),
7    FindWhen(MeasureFindWhen),
8}
9
10
11/// .MEAS TRAN rise TRIG V(1) VAL=.2 RISE=1
12///                 TARG V(1) VAL=.8 RISE=1
13#[derive(Debug, Clone)]
14pub struct MeasureRise {
15    pub name: String,
16    pub analysis: AnalysisType,
17    pub trig: TrigTargCondition,
18    pub targ: TrigTargCondition,
19}
20
21/// .MEAS TRAN avgval AVG V(1) FROM=10ns TO=55ns
22#[derive(Debug, Clone)]
23pub struct MeasureBasicStat {
24    pub name: String,
25    pub analysis: AnalysisType,
26    pub stat: MeasureFunction,
27    pub variable: OutputVariable,
28    pub from: Time,
29    pub to: Time,
30}
31
32/// .MEAS TRAN DesiredCurr FIND I(Vmeas) WHEN V(1)=1V
33#[derive(Debug, Clone)]
34pub struct MeasureFindWhen {
35    pub name: String,
36    pub analysis: AnalysisType,
37    pub variable: OutputVariable,
38    pub when: FindWhenCondition,
39}
40
41#[derive(Debug, Clone)]
42pub struct TrigTargCondition {
43    pub variable: OutputVariable,
44    pub value: Number,
45    pub edge: EdgeType, // RISE or FALL
46    pub number: usize,  // 第几个上升沿/下降沿
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub enum EdgeType {
51    Rise,
52    Fall,
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum MeasureFunction {
57    Avg,
58    Rms,
59    Min,
60    Max,
61    Pp,      // Peak to Peak
62    Deriv,
63    Integrate,
64}
65
66#[derive(Debug, Clone)]
67pub struct FindWhenCondition {
68    pub variable: OutputVariable,
69    pub value: Number,
70}
71
72#[derive(Debug, Clone)]
73pub struct ExpressionCondition {
74    pub variable: OutputVariable,
75    pub expression: String, // 如 "0.9*vdd"
76}
77
78#[derive(Debug, Clone, Copy, PartialEq, Eq)]
79pub enum AnalysisType {
80    Dc,
81    Ac,
82    Tran,
83}
84
85#[derive(Debug, Clone)]
86pub enum OutputVariable {
87    Voltage {
88        node1: String,              // 例如 "n1"
89        node2: Option<String>,      // None 表示对地,Some("n2") 表示 V(n1,n2)
90        suffix: Option<OutputSuffix>,
91    },
92    Current {
93        element_name: String,       // 例如 "V1" 表示电压源 V1 中的电流
94        suffix: Option<OutputSuffix>,
95    },
96}
97
98#[derive(Debug, Clone)]
99pub enum OutputSuffix {
100    Magnitude,
101    Decibel,
102    Phase,
103    Real,
104    Imag,
105}