---+ Getting Started with Crython
The "crython" library provides an easy scripting interface to the cryoelectronics board. Python scripts using crython may be run on a PC (communicating with the board over the network), or on the board itself (interacting directly with hardware.)
Checking out the repository
You can quickly check out a read-only version of the crython code as follows:
-
$ git clone git://kingspeak.physics.mcgill.ca/git/crython
If you want write access, you'll need to create a set of credentials Git can use to authenticate you. We use the "gitosis" system; instructions are available
here.
A Quick Introduction
- The ipython front-end to Python is highly recommended. It comes with some serious goodies:
- Tab-completion of crython methods (try typing 'cb.' followed by the tab key), and
- On-line help (try typing '? cb.set_heater_switch')
Presented here is a quick description and example of many of the crython.py functions you may wish to use.
Instantiate cryoboard object
This is required to send commands to the board, or to get board parameters, such as bias current amplitude.
>>> from crython.cryoboard import CryoBoard
>>> cb = crython.CryoBoard('192.168.1.138')
The cryoboard object functions typically apply to the drive or sense circuit. They are organized in the code that deals with the sensor_dac or sensor_adc functions that you can set or get.
sense_dac functions
- Set the carrier waveform (is it a DC carrier, or sine wave). cb.set_sensor_dac_waveform(channel number, waveform type). Eg. cb.set_sensor_dac_waveform(1,crython.DC)
- Set the carrier amplitude. cb.set_sensor_dac_amplitude(channel number, amplitude, units). Eg. cb.set_sensor_dac_amplitude(5,10e-6,crython.AMPS)
sense_adc_functions
- Set the demodulation waveform (is it demodulated with a sine wave, or no demodultaion(DC)). cb.set_sensor_adc_waveform(channel number, waveform type). Eg. cb.set_sensor_dac_waveform(1,crython.SINE)
- Set the adc offset (careful). cb.set_sensor_adc_offset(channel number, offset value, units). Eg. cb.set_sensor_adc_offset(1,-2090000,crython.RAW)
general functions
- Set the bias frequency for a sine wave. cb.set_frequency( frequency, units). Eg. cb.set_frequency(17,crython.HZ)
- Set the drive circuit feedback gain resistor. cb.set_drive_resistance(channel number, resistance (ohms)). Eg. cb.set_drive_resistance(1,100)
- Set the sense circuit feedback gain resistor. cb.set_sense_resistance(channel number, resistance (ohms)). Eg. cb.set_sense_resistance(1,100)
Instantiate Streamer object This is required to stream data from the board to a pc.
>>> from crython.cryoboard import CryoStreamer
>>> cs = CryoStreamer(cb,'192.168.1.5','12121')
- Check the status of a streamer. cs.status(). True indicates that the streamer has been launched. False indicates the opposite.
- Launch a streamer. cs.launch()
- Kill a streamer. cs.kill()
- Get samples. x = cs.get_samples(number of samples)
Read samples Once you have some streamed data you can use the cryoboard object to convert from raw units to physical units. The streamer contains the sensor voltage i, q, and magnitude components, and the drive current i, q, and magnitude componets for each channel.
- Get sensor voltage. v = cb.convert_sensor_adc_voltage(channel number, streamed value, units its in, units to convert to). Eg. voltage = cb.convert_sensor_adc_voltage(1,x[0].v(1),crython.ADC_COUNTS,crython.VOLTS)
- Get sensor current. i = cb.convert_sensor_adc_current(channel number, streamed value, units its in, units to convert to). Eg. current = cb.convert_sensor_adc_current(1,x[0].i(1),crython.ADC_COUNTS,crython.AMPS)
- Get Temperature from the resistance. r = v/i. Temperature = cb.convert_sensor_adc_resistance(channel number, resistance, units in (ohms), units to convert to (Kelvin)). Eg. temperature = cb.convert_sensor_adc_resistance(1,r,crython.OHMS,crython.KELVIN)
Putting it all together Below is some code that will instantiate a board, bias channels 1 & 2 with a 37 Hz 15nA sine wave, bias channel 3 with a 10uA DC current, stream the data to a pc and find the resistances.
>> from crython.cryoboard import CryoBoard, CryoStreamer
>> import pylab
>> cb = CryoBoard('192.168.1.138')
>> cs = CryoStreamer(cb,'192.168.1.121','12121')
>> cb.set_frequency(37,cb.HZ)
>> for i in range(1,3):
>> cb.set_sensor_dac_waveform(i,cb.SINE)
>> cb.set_sensor_adc_waveform(i,cb.SINE)
>> cb.set_sensor_dac_amplitude(i,15e-9,cb.AMPS)
>> cb.set_sensor_dac_waveform(3,cb.DC)
>> cb.set_sensor_adc_waveform(3,cb.DC)
>> cb.set_sensor_dac_amplitude(3,10e-6,cb.AMPS)
>> cs.launch()
>> x = cs.get_samples(1)
>> for chan in range(1,3):
>> v = cb.convert_sensor_adc_voltage(chan,pylab.sqrt(x['vi'][chan-1][0]**2 + x['vq'][chan-1][0]**2),cb.ADC_COUNTS,cb.VOLTS)
>> i = cb.convert_sensor_adc_current(chan,pylab.sqrt(x['ii'][chan-1][0]**2 + x['iq'][chan-1][0]**2),cb.ADC_COUNTS,cb.AMPS)
>> r = v/i
>> t = cb.convert_sensor_adc_resistance(chan,r,cb.OHMS,cb.KELVIN)
>> print_str = 'The resistance for channel #'+str(chan)+' is ' +str(r) + ' Ohms'
>> print(print_str)
>> print_str = 'The temperature of channel #'+str(chan)+' is '+str(t) + ' Kelvin'
>> print(print_str)
>> v = cb.convert_sensor_adc_voltage(3-1,pylab.sqrt(x['vi'][3-1][0]**2 + x['vq'][3-1][0]**2),cb.ADC_COUNTS,cb.VOLTS)
>> i = cb.convert_sensor_adc_current(3-1,pylab.sqrt(x['ii'][3-1][0]**2 + x['iq'][3-1'][0]**2),cb.ADC_COUNTS,cb.AMPS)
>> r = v/i
>> print_str = 'The resistance for channel #3 is ' +str(r) + ' Ohms'
>> print(print_str)
>> print_str = 'The temperature of channel #3 is '+str(t) + ' Kelvin'
>> print(print_str)
This topic: CryoElectronics
> WebHome > GettingStartedWithCrython
Topic revision: r15 - 2012-11-08 - JamesKennedy