Skip to content

Testing SR830

William Wood edited this page Dec 3, 2018 · 2 revisions

Example: Testing SR830

Here's some example code for a short experiment that I ran to test how accurately my lock-in amplifier could lock on to different frequencies.

The lock-in was set up so that the output of its internal oscillator was connected to the lock-in input and the lock-in was told to be in internal referencing mode (ie use the internal oscillator as reference). In effect, this meant the lock-in would be locking on to itself.

The code, just the code

import ...;
public class Main extends GUI {

  public static void run() throws Exception {

    LockIn lock = new SR830(new GPIBAddress(0,30));  
    lock.setRefMode(LockIn.RefMode.INTERNAL);
    lock.setOscAmplitude(50e-3);
                                                 
    ResultList list = new ResultList("Frequency","Amplitude","Measured Amplitude","Error");
    list.setUnits("Hz","V","V","%");

    Plot plot = new Plot("Results", list, 0, 3); 
    plot.show();   
                                                 
    for (double f = 0.2; f <= 10; f += 0.2) {        
                                                 
      lock.setTimeConstant(3.0/f);
      lock.setOscFrequency(f);                      
                                                 
      lock.waitForStableLock();                     
                                               
      double ref = lock.getRefAmplitude();          
      double mes = lock.getLockedAmplitude();
      double frq = lock.getFrequency();       
                                                  
      list.addData(                              
        frq,                         
        ref,                                         
        mes,                                         
        100 * (Math.abs(ref - mes) / Math.max(ref,mes)) 
      );                                             
                                                 
    }                                                
                                                 
    list.output("SR830Errors.csv");

  }

  public static void main(String[] args) {
    try { run(); } catch (Exception e) { Util.exceptionHandler(e); }
  }

}

The code with commentary

LockIn lock = new SR830(new GPIBAddress(0,30)); // The lock-in was connected via GPIB
lock.setRefMode(LockIn.RefMode.INTERNAL);       // Use internal reference mode
lock.setOscAmplitude(50e-3);                    // Set oscillator amplitude to 50 mV
                                                //
ResultList list= new ResultList(                // Create result list to store results
  "Frequency",                                  // Column 0 is for frequency
  "Amplitude",                                  // Column 1 is for oscillator amplitude
  "Measured Amplitude",                         // Column 2 is for locked-on amplitude
  "Error"                                       // Column 3 is for percentage error
);                                              //
                                                //
list.setUnits(                                  // Set the units of each column
  "Hz",                                         //
  "V",                                          //
  "V",                                          //
  "%"                                           //
);                                              //
                                                //
Plot plot = new Plot("Results", list, 0, 3);    // Create the plot window, we want it
                                                // to plot column 3 on the y-axis vs
                                                // column 0 on the x-axis
                                                //
plot.show();                                    // Show the plot window
                                                //
for (double f = 0.1; f <= 10; f += 0.2) {       // Loop f from 0.1 to 10 in steps of 0.1
                                                //
  lock.setTimeConstant(3.0/f);                  // Make sure TC is ~ 3x period
  lock.setOscFrequency(f);                      // Sets frequency of internal oscillator
                                                //
  lock.waitForStableLock();                     // Makes program wait until lock is stable
                                                //
  double ref = lock.getRefAmplitude();          // Get the amplitude of reference signal
  double mes = lock.getLockedAmplitude();       // Get the amplitude of locked-on signal
  double frq = lock.getFreuqency();             // Get the frequency
                                                //
  list.addData(                                 // Add the data to the result list
    frq,                                        // 
    ref,                                        //
    mes,                                        //
    100*(Math.abs(ref - mes)/Math.max(ref,mes)) // Calculating percentage error
  );                                            //
                                                //
}                                               //
                                                //
list.output("SR830Errors.csv");                 // Outputs the results as a CSV file

The Code, in Python

import sys
sys.path.append("JISA.jar")
from JISA ... import ...

def run():
  
  GUI.startGUI()
  
  lock = SR830(GPIBAddress(0,30)); 
  lock.setRefMode(LockIn.RefMode.INTERNAL)
  lock.setOscAmplitude(50e-3)
  
  lst = ResultList(["Frequency","Amplitude","Measured Amplitude","Error"])
  lst.setUnits(["Hz","V","V","%"])
  
  plot = Plot("Results", lst, 0, 3)
  plot.show()
  
  f = 0.1
  
  while f <= 10.0:        
    lock.setTimeConstant(3.0/f)
    lock.setOscFrequency(f)                    
    
    lock.waitForStableLock()                    
    
    ref = lock.getRefAmplitude()         
    mes = lock.getLockedAmplitude()
    frq = lock.getFrequency()     
    
    lst.addData([
      frq, 
      ref, 
      mes, 
      100.0 * (abs(ref - mes) / max(ref,mes))
    ])
    
    f += 0.2
  
  lst.output("SR830Errors.csv");

try:
  run();
except:
  print("Exception Occurred");

Output

When run the output is added in real-time to the plot window which ends up looking like this:

The CSV file looks like

Frequency [Hz],Amplitude [V],Measured Amplitude [V],Error [%]
0.100000,0.050000,0.048419,3.162278
0.300000,0.050000,0.049087,1.825742
0.500000,0.050000,0.049293,1.414214
0.700000,0.050000,0.049402,1.195229
0.900000,0.050000,0.049473,1.054093
1.100000,0.050000,0.049523,0.953463
1.300000,0.050000,0.049561,0.877058
1.500000,0.050000,0.049592,0.816497
1.700000,0.050000,0.049617,0.766965
1.900000,0.050000,0.049637,0.725476
2.100000,0.050000,0.049655,0.690066
2.300000,0.050000,0.049670,0.659380
2.500000,0.050000,0.049684,0.632456
2.700000,0.050000,0.049696,0.608581
2.900000,0.050000,0.049706,0.587220
3.100000,0.050000,0.049716,0.567962
3.300000,0.050000,0.049725,0.550482
3.500000,0.050000,0.049733,0.534522
3.700000,0.050000,0.049740,0.519875
3.900000,0.050000,0.049747,0.506370
4.100000,0.050000,0.049753,0.493865
4.300000,0.050000,0.049759,0.482243
4.500000,0.050000,0.049764,0.471405
4.700000,0.050000,0.049769,0.461266
4.900000,0.050000,0.049774,0.451754
5.100000,0.050000,0.049779,0.442807
5.300000,0.050000,0.049783,0.434372
5.500000,0.050000,0.049787,0.426401
5.700000,0.050000,0.049791,0.418854
5.900000,0.050000,0.049794,0.411693
6.100000,0.050000,0.049798,0.404888
6.300000,0.050000,0.049801,0.398410
6.500000,0.050000,0.049804,0.392232
6.700000,0.050000,0.049807,0.386334
6.900000,0.050000,0.049810,0.380693
7.100000,0.050000,0.049812,0.375293
7.300000,0.050000,0.049815,0.370117
7.500000,0.050000,0.049817,0.365148
7.700000,0.050000,0.049820,0.360375
7.900000,0.050000,0.049822,0.355784
8.100000,0.050000,0.049824,0.351364
8.300000,0.050000,0.049826,0.347105
8.500000,0.050000,0.049829,0.342997
8.700000,0.050000,0.049830,0.339032
8.900000,0.050000,0.049832,0.335201
9.100000,0.050000,0.049834,0.331497
9.300000,0.050000,0.049836,0.327913
9.500000,0.050000,0.049838,0.324443
9.700000,0.050000,0.049839,0.321081
9.900000,0.050000,0.049841,0.317821
Clone this wiki locally