| 1 | package Lab::XPRESS::Sweep::Voltage; | ||
| 2 | $Lab::XPRESS::Sweep::Voltage::VERSION = '3.899'; | ||
| 3 | #ABSTRACT: Voltage sweep | ||
| 4 | |||
| 5 | use v5.20; | ||
| 6 | |||
| 7 | use Lab::XPRESS::Sweep; | ||
| 8 | use Time::HiRes qw/usleep/, qw/time/; | ||
| 9 | use warnings; | ||
| 10 | use strict; | ||
| 11 | use Carp; | ||
| 12 | our @ISA = ('Lab::XPRESS::Sweep'); | ||
| 13 | |||
| 14 | sub new { | ||
| 15 | my $proto = shift; | ||
| 16 | my @args = @_; | ||
| 17 | my $class = ref($proto) || $proto; | ||
| 18 | my $self->{default_config} = { | ||
| 19 | 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 | $self = $class->SUPER::new( $self->{default_config}, @args ); | ||
| 39 | bless( $self, $class ); | ||
| 40 | |||
| 41 | return $self; | ||
| 42 | } | ||
| 43 | |||
| 44 | sub go_to_sweep_start { | ||
| 45 | my $self = shift; | ||
| 46 | |||
| 47 | # go to start: | ||
| 48 | print "Setting voltage to start value ... "; | ||
| 49 | if ( $self->{config}->{mode} =~ /step|list/ | ||
| 50 | && $self->{config}->{jump} ) { | ||
| 51 | my $target = $self->{config}{points}[ $self->{iterator} ]; | ||
| 52 | my $rate = $self->{config}{rate}[ $self->{iterator} ]; | ||
| 53 | my $current = $self->{config}{instrument}->get_level(); | ||
| 54 | my $stepwidth = $self->{config}{stepwidth}[ $self->{iterator} ]; | ||
| 55 | if ( not defined $stepwidth ) { | ||
| 56 | croak "no 'stepwidth' defined for sweep with mode 'step'"; | ||
| 57 | } | ||
| 58 | my $time = abs( ( $target - $current ) / $rate ); | ||
| 59 | $self->{config}{instrument} | ||
| 60 | ->sweep_to_level( $target, $time, $stepwidth ); | ||
| 61 | } | ||
| 62 | else { | ||
| 63 | $self->{config}->{instrument}->config_sweep( | ||
| 64 | { | ||
| 65 | 'points' => | ||
| 66 | @{ $self->{config}->{points} }[ $self->{iterator} ], | ||
| 67 | 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} ] | ||
| 68 | } | ||
| 69 | ); | ||
| 70 | $self->{config}->{instrument}->trg(); | ||
| 71 | $self->{config}->{instrument}->wait(); | ||
| 72 | } | ||
| 73 | print "Done \n"; | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | sub start_continuous_sweep { | ||
| 78 | my $self = shift; | ||
| 79 | |||
| 80 | $self->{config}->{instrument}->config_sweep( | ||
| 81 | { | ||
| 82 | 'points' => | ||
| 83 | @{ $self->{config}->{points} }[ $self->{iterator} + 1 ], | ||
| 84 | 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} + 1 ] | ||
| 85 | } | ||
| 86 | ); | ||
| 87 | $self->{config}->{instrument}->trg(); | ||
| 88 | } | ||
| 89 | |||
| 90 | sub go_to_next_step { | ||
| 91 | my $self = shift; | ||
| 92 | |||
| 93 | if ( $self->{config}->{jump} == 1 ) { | ||
| 94 | $self->{config}->{instrument}->set_voltage( | ||
| 95 | ${ $self->{config}->{points} }[ $self->{iterator} ] ); | ||
| 96 | } | ||
| 97 | else { | ||
| 98 | $self->{config}->{instrument}->config_sweep( | ||
| 99 | { | ||
| 100 | 'points' => | ||
| 101 | @{ $self->{config}->{points} }[ $self->{iterator} ], | ||
| 102 | 'rate' => @{ $self->{config}->{rate} }[ $self->{iterator} ] | ||
| 103 | } | ||
| 104 | ); | ||
| 105 | $self->{config}->{instrument}->trg(); | ||
| 106 | $self->{config}->{instrument}->wait(); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | sub exit_loop { | ||
| 111 | my $self = shift; | ||
| 112 | |||
| 113 | # if ( not $self->{config}->{instrument}->active() ) { | ||
| 114 | if ( $self->{config}->{mode} =~ /step|list/ ) { | ||
| 115 | if ( | ||
| 116 | not | ||
| 117 | defined @{ $self->{config}->{points} }[ $self->{iterator} + 1 ] ) | ||
| 118 | { | ||
| 119 | return 1; | ||
| 120 | } | ||
| 121 | return 0; | ||
| 122 | } | ||
| 123 | if ( not $self->{config}->{instrument}->active() ) { | ||
| 124 | if ( $self->{config}->{mode} eq "continuous" ) { | ||
| 125 | if ( | ||
| 126 | not defined @{ $self->{config}->{points} } | ||
| 127 | [ $self->{sequence} + 2 ] ) { | ||
| 128 | return 1; | ||
| 129 | } | ||
| 130 | $self->{sequence}++; | ||
| 131 | $self->{config}->{instrument}->config_sweep( | ||
| 132 | { | ||
| 133 | 'points' => @{ $self->{config}->{points} } | ||
| 134 | [ $self->{sequence} + 1 ], | ||
| 135 | 'rate' => | ||
| 136 | @{ $self->{config}->{rate} }[ $self->{sequence} + 1 ] | ||
| 137 | } | ||
| 138 | ); | ||
| 139 | $self->{config}->{instrument}->trg(); | ||
| 140 | } | ||
| 141 | return 0; | ||
| 142 | } | ||
| 143 | else { | ||
| 144 | return 0; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | sub get_value { | ||
| 149 | my $self = shift; | ||
| 150 | return $self->{config}->{instrument}->get_level(); | ||
| 151 | } | ||
| 152 | |||
| 153 | sub exit { | ||
| 154 | my $self = shift; | ||
| 155 | $self->{config}->{instrument}->abort(); | ||
| 156 | } | ||
| 157 | |||
| 158 | 1; | ||
| 159 | |||
| 160 | __END__ |