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