Skip to content

Commit a0ddf04

Browse files
Update SMU support for source limits (#46)
Also update the over range current for PSU
1 parent 4b04fd7 commit a0ddf04

File tree

3 files changed

+106
-48
lines changed

3 files changed

+106
-48
lines changed

script-gen-manager/src/instr_metadata/mpsu50_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Mpsu50Metadata {
2323
//TODO: verify for Trebuchet PSU (model: MPSU50-2ST)
2424
// Add ranges
2525
let max_supported_voltage = 50.1;
26-
let max_supported_current = 5.0;
26+
let max_supported_current = 5.1;
2727
base.add_range(
2828
"source.levelv".to_string(),
2929
-max_supported_voltage,

script-gen-manager/src/instr_metadata/msmu60_metadata.rs

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,51 @@ use crate::model::{
44

55
use super::base_metadata::{BaseMetadata, Metadata};
66

7+
// Epsilon for floating-point comparisons
8+
const EPSILON: f64 = 1e-15;
9+
10+
// Voltage range constants for MSMU60
11+
const VOLTAGE_AUTO: &str = "AUTO";
12+
const VOLTAGE_200_MV: &str = "200 mV";
13+
const VOLTAGE_2_V: &str = "2 V";
14+
const VOLTAGE_6_V: &str = "6 V";
15+
const VOLTAGE_20_V: &str = "20 V";
16+
const VOLTAGE_60_V: &str = "60 V";
17+
18+
// Current range constants for MSMU60
19+
const CURRENT_AUTO: &str = "AUTO";
20+
const CURRENT_100_NA: &str = "100 nA";
21+
const CURRENT_1_UA: &str = "1 \u{00B5}A"; // Unicode character for micro (µ)
22+
const CURRENT_10_UA: &str = "10 \u{00B5}A";
23+
const CURRENT_100_UA: &str = "100 \u{00B5}A";
24+
const CURRENT_1_MA: &str = "1 mA";
25+
const CURRENT_10_MA: &str = "10 mA";
26+
const CURRENT_100_MA: &str = "100 mA";
27+
const CURRENT_1_A: &str = "1 A";
28+
const CURRENT_1_5_A: &str = "1.5 A";
29+
30+
// Range arrays built from constants
31+
const VOLTAGE_RANGES: &[&str] = &[
32+
VOLTAGE_AUTO,
33+
VOLTAGE_200_MV,
34+
VOLTAGE_2_V,
35+
VOLTAGE_6_V,
36+
VOLTAGE_20_V,
37+
VOLTAGE_60_V,
38+
];
39+
const CURRENT_RANGES: &[&str] = &[
40+
CURRENT_AUTO,
41+
CURRENT_100_NA,
42+
CURRENT_1_UA,
43+
CURRENT_10_UA,
44+
CURRENT_100_UA,
45+
CURRENT_1_MA,
46+
CURRENT_10_MA,
47+
CURRENT_100_MA,
48+
CURRENT_1_A,
49+
CURRENT_1_5_A,
50+
];
51+
752
#[derive(Debug, Clone)]
853
pub struct Msmu60Metadata {
954
base: BaseMetadata,
@@ -14,26 +59,8 @@ impl Msmu60Metadata {
1459
pub fn new() -> Self {
1560
let mut base = BaseMetadata::new();
1661
// Add additional key-value pairs for MSmu60Metadata
17-
base.add_option(
18-
"source_meas.rangev",
19-
vec!["AUTO", "200 mV", "2 V", "6 V", "20 V", "60 V"],
20-
);
21-
// "\u{00B5}"" - Unicode character for micro (µ)
22-
base.add_option(
23-
"source_meas.rangei",
24-
vec![
25-
"AUTO",
26-
"100 nA",
27-
"1 \u{00B5}A",
28-
"10 \u{00B5}A",
29-
"100 \u{00B5}A",
30-
"1 mA",
31-
"10 mA",
32-
"100 mA",
33-
"1 A",
34-
"1.5 A",
35-
],
36-
);
62+
base.add_option("source_meas.rangev", VOLTAGE_RANGES.to_vec());
63+
base.add_option("source_meas.rangei", CURRENT_RANGES.to_vec());
3764

3865
base.add_default("source_meas.range.defaultv", "AUTO");
3966
base.add_default("source_meas.range.defaulti", "AUTO");
@@ -42,19 +69,47 @@ impl Msmu60Metadata {
4269
base.add_range("source.levelv".to_string(), -60.6, 60.6);
4370
base.add_range("source.leveli".to_string(), -1.515, 1.515);
4471

45-
base.add_range("source.limiti".to_string(), -1e-8, 1.515);
46-
base.add_range("source.limitv".to_string(), -0.02, 60.6);
72+
base.add_range("source.limiti".to_string(), -1.515, 1.515);
73+
base.add_range("source.limitv".to_string(), -60.6, 60.6);
4774

4875
base.add_range("source.step_to_sweep_delay".to_string(), 0.0, 100.0);
4976

5077
// Add region maps
5178
// when pulse mode is off
5279
let exclude_v = Some(NumberLimit::new(-0.01, 0.01, false, None));
5380
let exclude_i = NumberLimit::new(-10.0e-9, 10.0e-9, false, None);
54-
let mut region_map_metadata = RegionMapMetadata::new(exclude_v, exclude_i);
55-
region_map_metadata.add_region(1, -60.0, -0.1, 60.0, 0.1);
56-
region_map_metadata.add_region(1, -20.0, -1.5, 20.0, 1.5);
57-
base.add_region_map("smu.region", region_map_metadata);
81+
82+
let mut inner_region = RegionMapMetadata::new(exclude_v.clone(), exclude_i.clone());
83+
inner_region.add_region(
84+
1,
85+
-60.6 - EPSILON,
86+
-0.1 - EPSILON,
87+
60.6 + EPSILON,
88+
0.1 + EPSILON,
89+
);
90+
base.add_region_map(VOLTAGE_60_V, inner_region.clone());
91+
base.add_region_map(CURRENT_100_NA, inner_region.clone());
92+
base.add_region_map(CURRENT_1_UA, inner_region.clone());
93+
base.add_region_map(CURRENT_10_UA, inner_region.clone());
94+
base.add_region_map(CURRENT_100_UA, inner_region.clone());
95+
base.add_region_map(CURRENT_1_MA, inner_region.clone());
96+
97+
let mut outer_region = RegionMapMetadata::new(exclude_v.clone(), exclude_i.clone());
98+
outer_region.add_region(
99+
1,
100+
-20.0 - EPSILON,
101+
-1.515 - EPSILON,
102+
20.0 + EPSILON,
103+
1.515 + EPSILON,
104+
);
105+
base.add_region_map(VOLTAGE_200_MV, outer_region.clone());
106+
base.add_region_map(VOLTAGE_2_V, outer_region.clone());
107+
base.add_region_map(VOLTAGE_6_V, outer_region.clone());
108+
base.add_region_map(VOLTAGE_20_V, outer_region.clone());
109+
base.add_region_map(CURRENT_10_MA, outer_region.clone());
110+
base.add_region_map(CURRENT_100_MA, outer_region.clone());
111+
base.add_region_map(CURRENT_1_A, outer_region.clone());
112+
base.add_region_map(CURRENT_1_5_A, outer_region.clone());
58113

59114
base.add_overrange_scale(1.01);
60115

script-gen-manager/src/model/chan_data/default_channel.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ impl CommonChanAttributes {
267267
}
268268

269269
pub fn validate_source_limits(&mut self, metadata: &MetadataEnum) {
270+
//This is the fixed min/max range
270271
if let Some((min, max)) = self.get_range_limits(metadata, "source.limiti") {
271272
if let Some(ref mut limiti) = self.source_limiti {
272273
limiti.value = Self::limit(limiti.value, min, max);
@@ -284,36 +285,38 @@ impl CommonChanAttributes {
284285
start_value: &ParameterFloat,
285286
stop_value: &ParameterFloat,
286287
) {
287-
if let Some((min, max)) = self.get_range_limits(&self.device.metadata, ":MODE") {
288-
if let Some(ref mut limiti) = self.source_limiti {
289-
limiti.value = Self::limit(limiti.value, min, max);
290-
}
291-
}
292-
288+
//Use region map to further limit the source limits based on the source function and range
289+
let mut limit_value = start_value.value;
293290
if let Some(region_map) =
294291
self.get_region_map(&self.device.metadata, &self.source_range.value)
295292
{
296-
//Do this only to the PSU for now
297-
let mut limit_value = start_value.value;
298293
if stop_value.value.abs() > limit_value.abs() {
299294
//Use the largest absolute value
300295
limit_value = stop_value.value;
301296
}
302-
if let Some(ref mut limiti) = self.source_limiti {
303-
let curr_limit = region_map.get_current_limit(limit_value);
304-
limiti.value =
305-
Self::limit(limiti.value, curr_limit.get_min(), curr_limit.get_max());
306-
println!("Evaluated current limit value is {:?}", limiti.value);
307-
}
308-
}
309-
310-
if let Some((min, max)) = self.get_range_limits(&self.device.metadata, "source.limitv") {
311-
if let Some(ref mut limitv) = self.source_limitv {
312-
limitv.value = Self::limit(limitv.value, min, max);
297+
match &self.source_function.value[..] {
298+
s if s == BaseMetadata::FUNCTION_VOLTAGE => {
299+
// Source is Voltage. Hence, limit current
300+
if let Some(ref mut limiti) = self.source_limiti {
301+
let curr_limit = region_map.get_current_limit(limit_value);
302+
limiti.value =
303+
Self::limit(limiti.value, curr_limit.get_min(), curr_limit.get_max());
304+
}
305+
}
306+
s if s == BaseMetadata::FUNCTION_CURRENT => {
307+
//Source is Current. Hence, limit voltage
308+
if let Some(ref mut limitv) = self.source_limitv {
309+
let voltage_limit = region_map.get_voltage_limit(limit_value);
310+
limitv.value = Self::limit(
311+
limitv.value,
312+
voltage_limit.get_min(),
313+
voltage_limit.get_max(),
314+
);
315+
}
316+
}
317+
_ => {} //If neither voltage nor current, do nothing, for now. Existing limits apply.
313318
}
314319
}
315-
316-
println!("Source range value is {:?}", self.source_range.value);
317320
}
318321

319322
fn limit(mut value: f64, min: f64, max: f64) -> f64 {

0 commit comments

Comments
 (0)