File Coverage

blib/lib/Lab/XPRESS/Sweep/Voltage.pm
Criterion Covered Total %
statement 47 77 61.0
branch 6 16 37.5
condition 2 6 33.3
subroutine 11 13 84.6
pod 1 7 14.2
total 67 119 56.3


line stmt bran cond sub pod time code
1             package Lab::XPRESS::Sweep::Voltage;
2             $Lab::XPRESS::Sweep::Voltage::VERSION = '3.880';
3             #ABSTRACT: Voltage sweep
4              
5 2     2   1760 use v5.20;
  2         8  
6              
7 2     2   15 use Lab::XPRESS::Sweep;
  2         4  
  2         75  
8 2     2   11 use Time::HiRes qw/usleep/, qw/time/;
  2         13  
  2         14  
9 2     2   219 use warnings;
  2         4  
  2         50  
10 2     2   21 use strict;
  2         14  
  2         46  
11 2     2   10 use Carp;
  2         4  
  2         2087  
12             our @ISA = ('Lab::XPRESS::Sweep');
13              
14             sub new {
15 1     1 0 3 my $proto = shift;
16 1         4 my @args = @_;
17 1   33     7 my $class = ref($proto) || $proto;
18             my $self->{default_config} = {
19 1         14 id => 'Voltage_sweep',
20             filename_extension => 'V=',
21             interval => 1,
22             points => [],
23             duration => [],
24             mode => 'continuous',
25             jump => 0,
26             allowed_instruments => [
27             qw/
28             Lab::Instrument::Yokogawa7651 Lab::Instrument::Keithley2400
29             Lab::Moose::Instrument::KeysightE3633E
30             Lab::Instrument::YokogawaGS200 Lab::Instrument::DummySource
31             Lab::Instrument::SR830::AuxOut Lab::Moose::Instrument::DummySource
32             Lab::Moose::Instrument::YokogawaGS200 Lab::Moose::Instrument::ZI_MFLI Lab::Moose::Instrument::ZI_MFIA/
33             ],
34             allowed_sweep_modes => [ 'continuous', 'list', 'step' ],
35             number_of_points => [undef]
36             };
37              
38 1         9 $self = $class->SUPER::new( $self->{default_config}, @args );
39 1         2 bless( $self, $class );
40              
41 1         9 return $self;
42             }
43              
44             sub go_to_sweep_start {
45 1     1 0 2 my $self = shift;
46              
47             # go to start:
48 1         61 print "Setting voltage to start value ... ";
49 1 50 33     28 if ( $self->{config}->{mode} =~ /step|list/
50             && $self->{config}->{jump} ) {
51 1         4 my $target = $self->{config}{points}[ $self->{iterator} ];
52 1         3 my $rate = $self->{config}{rate}[ $self->{iterator} ];
53 1         4 my $current = $self->{config}{instrument}->get_level();
54 1         5 my $stepwidth = $self->{config}{stepwidth}[ $self->{iterator} ];
55 1 50       3 if ( not defined $stepwidth ) {
56 0         0 croak "no 'stepwidth' defined for sweep with mode 'step'";
57             }
58 1         4 my $time = abs( ( $target - $current ) / $rate );
59             $self->{config}{instrument}
60 1         8 ->sweep_to_level( $target, $time, $stepwidth );
61             }
62             else {
63             $self->{config}->{instrument}->config_sweep(
64             {
65             'points' =>
66 0         0 @{ $self->{config}->{points} }[ $self->{iterator} ],
67 0         0 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} ]
  0         0  
68             }
69             );
70 0         0 $self->{config}->{instrument}->trg();
71 0         0 $self->{config}->{instrument}->wait();
72             }
73 1         106 print "Done \n";
74              
75             }
76              
77             sub start_continuous_sweep {
78 0     0 0 0 my $self = shift;
79              
80             $self->{config}->{instrument}->config_sweep(
81             {
82             'points' =>
83 0         0 @{ $self->{config}->{points} }[ $self->{iterator} + 1 ],
84 0         0 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} + 1 ]
  0         0  
85             }
86             );
87 0         0 $self->{config}->{instrument}->trg();
88             }
89              
90             sub go_to_next_step {
91 11     11 0 19 my $self = shift;
92              
93 11 50       29 if ( $self->{config}->{jump} == 1 ) {
94             $self->{config}->{instrument}->set_voltage(
95 11         22 ${ $self->{config}->{points} }[ $self->{iterator} ] );
  11         45  
96             }
97             else {
98             $self->{config}->{instrument}->config_sweep(
99             {
100             'points' =>
101 0         0 @{ $self->{config}->{points} }[ $self->{iterator} ],
102 0         0 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} ]
  0         0  
103             }
104             );
105 0         0 $self->{config}->{instrument}->trg();
106 0         0 $self->{config}->{instrument}->wait();
107             }
108             }
109              
110             sub exit_loop {
111 11     11 0 21 my $self = shift;
112              
113             # if ( not $self->{config}->{instrument}->active() ) {
114 11 50       81 if ( $self->{config}->{mode} =~ /step|list/ ) {
115 11 100       22 if (
116             not
117 11         34 defined @{ $self->{config}->{points} }[ $self->{iterator} + 1 ] )
118             {
119 1         15 return 1;
120             }
121 10         73 return 0;
122             }
123 0 0       0 if ( not $self->{config}->{instrument}->active() ) {
124 0 0       0 if ( $self->{config}->{mode} eq "continuous" ) {
125 0 0       0 if (
126 0         0 not defined @{ $self->{config}->{points} }
127             [ $self->{sequence} + 2 ] ) {
128 0         0 return 1;
129             }
130 0         0 $self->{sequence}++;
131             $self->{config}->{instrument}->config_sweep(
132             {
133 0         0 'points' => @{ $self->{config}->{points} }
134             [ $self->{sequence} + 1 ],
135             'rate' =>
136 0         0 @{ $self->{config}->{rate} }[ $self->{sequence} + 1 ]
  0         0  
137             }
138             );
139 0         0 $self->{config}->{instrument}->trg();
140             }
141 0         0 return 0;
142             }
143             else {
144 0         0 return 0;
145             }
146             }
147              
148             sub get_value {
149 12     12 1 58 my $self = shift;
150 12         44 return $self->{config}->{instrument}->get_level();
151             }
152              
153             sub exit {
154 0     0 0   my $self = shift;
155 0           $self->{config}->{instrument}->abort();
156             }
157              
158             1;
159              
160             __END__
161              
162             =pod
163              
164             =encoding UTF-8
165              
166             =head1 NAME
167              
168             Lab::XPRESS::Sweep::Voltage - Voltage sweep
169              
170             =head1 VERSION
171              
172             version 3.880
173              
174             =head1 SYNOPSIS
175              
176             use Lab::XPRESS::hub;
177             my $hub = new Lab::XPRESS::hub();
178            
179            
180             my $Yoki = $hub->Instrument('Yokogawa7651',
181             {
182             connection_type => 'VISA_GPIB',
183             gpib_address => 2
184             });
185            
186             my $sweep_voltage = $hub->Sweep('Voltage',
187             {
188             instrument => $Yoki,
189             points => [-1,1],
190             rate => [0.1,0.001],
191             mode => 'continuous',
192             interval => 1,
193             backsweep => 1
194             });
195              
196             =head1 DESCRIPTION
197              
198             Parent: Lab::XPRESS::Sweep
199              
200             The Lab::XPRESS::Sweep::Voltage class implements a module for voltage Sweeps in the Lab::XPRESS::Sweep framework.
201              
202             =head1 CONSTRUCTOR
203              
204             my $sweep_voltage = $hub->Sweep('Voltage',
205             {
206             instrument => $Yoki,
207             points => [-1,1],
208             rate => [0.1,0.001],
209             mode => 'continuous',
210             interval => 1,
211             backsweep => 1
212             });
213              
214             Instantiates a new voltage-sweep.
215              
216             =head1 PARAMETERS
217              
218             =head2 instrument [Lab::Instrument] (mandatory)
219              
220             Instrument, conducting the sweep. Must be of type Lab:Instrument.
221             Allowed instruments: Lab::Instrument::Yokogawa7651
222              
223             =head2 mode [string] (default = 'continuous' | 'step' | 'list')
224              
225             continuous: perform a continuous voltage sweep. Measurements will be performed constantly at the time-interval defined in interval.
226              
227             step: measurements will be performed at discrete values of the applied voltage between start and end points defined in parameter points, seperated by voltage steps defined in parameter stepwidth
228              
229             list: measurements will be performed at a list voltage values defined in parameter points
230              
231             =head2 points [float array] (mandatory)
232              
233             array of voltage values (in volts) that defines the characteristic points of the sweep.
234             First value is appraoched before measurement begins.
235              
236             Case mode => 'continuous' :
237             List of at least 2 values, that define start and end point of the sweep or a sequence of consecutive sweep-sections (e.g. if changing the sweep-rate for different sections or reversing the sweep direction).
238             points => [-5, 5] # Start: -5 / Stop: 5
239              
240             points => [-5, -1, 1, 5]
241              
242             points => [0, -5, 5]
243              
244             Case mode => 'step' :
245             Same as in 'continuous' but voltage will be swept in stop and go mode. I.e. voltage source approaches values between start and stop at the interval defined in 'stepwidth'. A measurement is performed, when voltage source is idle.
246              
247             Case mode => 'list' :
248             Array of voltages, with minimum length 1, that are approached in sequence to perform a measurment.
249              
250             =head2 rate [float array] (mandatory if not defined duration)
251              
252             array of rates, at which the voltage is swept (V / sec).
253             Has to be of length 1 or greater (Maximum length: length of points-array).
254             The first value defines the rate to approach the starting point.
255             The following values define the rates to approach the voltages defined by the points-array.
256             If the number of values in the rates-array is less than the length of the points-array, the last defined rate will be used for the remaining sweep sections.
257              
258             points => [-5, -1, 1, 5],
259             rates => [1, 0.005, 0.02]
260            
261             rate to approach -5 V (the starting point): 1 V/sec
262             rate to approach -1 V : 0.005 V/sec
263             rate to approach 1 V : 0.02 V/sec
264             rate to approach 5 V : 0.02 V/sec (last defined rate)
265              
266             =head2 duration [float array] (mandatory if not defined rate)
267              
268             can be used instead of 'rate'. Attention: Use only the 'duration' or the 'rate' parameter. Using both will cause an Error!
269              
270             The first value defines the duration to approach the starting point.
271             The second value defines the duration to approach the voltage value defined by the second value of the points-array.
272             ...
273             If the number of values in the duration-array is less than the length of the points-array, last defined duration will be used for the remaining sweep sections.
274              
275             =head2 stepwidth [float array]
276              
277             This parameter is relevant only if mode = 'step' has been selected.
278             Stepwidth has to be an array of length '1' or greater. The values define the width for each step within the corresponding sweep sequence.
279             If the length of the defined sweep sequence devided by the stepwidth is not an integer number, the last step will be smaller in order to reach the defined points-value.
280              
281             points = [0, 0.5, 3]
282             stepwidth = [0.2, 0.5]
283            
284             ==> steps: 0, 0.2, 0.4, 0.5, 1.0, 1.5, 2.0, 2.5, 3
285              
286             =head2 number_of_points [int array]
287              
288             can be used instead of 'stepwidth'. Attention: Use only the 'number_of_points' or the 'stepwidth' parameter. Using both will cause an Error!
289             This parameter is relevant only if mode = 'step' has been selected.
290             Number_of_points has to be an array of length '1' or greater. The values defines the number of steps within the corresponding sweep sequence.
291              
292             points = [0, 0.5, 3]
293             number_of_points = [5, 2]
294            
295             ==> steps: 0, 0.1, 0.2, 0.3, 0.4, 0.5, 1.75, 3
296              
297             =head2 interval [float] (default = 1)
298              
299             interval in seconds for taking measurement points. Only relevant in mode 'continuous'.
300              
301             =head2 backsweep [int] (default = 0 | 1 | 2)
302              
303             0 : no backsweep (default)
304             1 : a backsweep will be performed
305             2 : no backsweep performed automatically, but sweep sequence will be reverted every second time the sweep is started (relevant eg. if sweep operates as a slave. This way the sweep sequence is reverted at every second step of the master)
306              
307             =head2 jump [int] (default = 0 | 1 )
308              
309             can be used to switch off the sweeping between adjacent points in step or list mode.
310              
311             0 : a sweep is performed between adjacent steps (default)
312             1 : the voltage is set without sweeping, given that gateprotect does not trigger a sweep.
313              
314             =head2 id [string] (default = 'Voltage_sweep')
315              
316             Just an ID.
317              
318             =head2 filename_extention [string] (default = 'V=')
319              
320             Defines a postfix, that will be appended to the filenames if necessary.
321              
322             =head2 delay_before_loop [int] (default = 0)
323              
324             defines the time in seconds to wait after the starting point has been reached.
325              
326             =head2 delay_in_loop [int] (default = 0)
327              
328             This parameter is relevant only if mode = 'step' or 'list' has been selected.
329             Defines the time in seconds to wait after the value for the next step has been reached.
330              
331             =head2 delay_after_loop [int] (default = 0)
332              
333             Defines the time in seconds to wait after the sweep has been finished. This delay will be executed before an optional backsweep or optional repetitions of the sweep.
334              
335             =head1 CAVEATS/BUGS
336              
337             probably none
338              
339             =head1 SEE ALSO
340              
341             =over 4
342              
343             =item L<Lab::XPRESS::Sweep>
344              
345             =back
346              
347             =head1 COPYRIGHT AND LICENSE
348              
349             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
350              
351             Copyright 2012 Stefan Geissler
352             2013 Alois Dirnaichner, Andreas K. Huettel, Christian Butschkow, Stefan Geissler
353             2014 Alois Dirnaichner, Andreas K. Huettel
354             2015 Alois Dirnaichner
355             2016 Simon Reinhardt
356             2017 Andreas K. Huettel, Simon Reinhardt
357             2019 Simon Reinhardt
358             2020 Andreas K. Huettel
359              
360              
361             This is free software; you can redistribute it and/or modify it under
362             the same terms as the Perl 5 programming language system itself.
363              
364             =cut