Example for the D5a 16 channel, 18-bit DAC module. To use this, we need a D5a module and a controller module. This can be either the C1b/C2 combination or the C1.
To use the D5a module, we also need to import the SPI rack class. All communication with the SPI Rack will go through this object. For each SPI Rack connected to the PC, only one connection can be open at a time. So before running another script, the connection in this one should be closed. You can connect and run multiple SPI Racks in parallel.
# Import SPI rack and D5a module
from spirack import SPI_rack, D5a_module
Open the SPI rack connection and unlock the controller. This is necessary after bootup of the controller module. If not unlocked, no communication with the modules can take place. The virtual COM port baud rate is irrelevant as it doesn’t change the actual speed. Timeout can be changed, but 1 second is a good value.
COM_speed = 1e6 # Baud rate, doesn't matter much
timeout = 1 # In seconds
spi_rack = SPI_rack('COM4', COM_speed, timeout)
spi_rack.unlock() # Unlock the controller to be able to send data
Create a new D5a module object at the correct (set) module address using the SPI object. By default the module resets the output voltages to 0 Volt. Before it does this, it will read back the current value. If this value is non-zero it will slowly ramp it to zero. If reset_voltages = False
then the output will not be changed.
D5a = D5a_module(spi_rack, module=2, reset_voltages=True)
The output span of the DAC can be set in software to the following ranges:
By default it is set to 4V bipolar. Changing the span, determines the smallest step size possible. The DACs used are 18-bit, which gives a smallest step size of:
$$\text{LSB} = \frac{\text{Span}}{2^{18}}$$
In the case of a $\pm$2V span this gives a LSB of: ~15 μV. You can get the current stepsize of a certain DAC with the get_stepsize
function.
D5a.change_span_update(1, D5a.range_2V_bi)
stepsize = D5a.get_stepsize(1) # Get the stepsize of DAC 1
print("Stepsize: " + str(stepsize) + " V")
The voltage can be set using the set_voltage
function. If you want the output to be precisely equal to the set value, the voltage should be an integer multiple of the stepsize. Especially if sweeps are performed this is recommended. Otherwise the steps might nog be equidistant. Here we set the voltage of output 1 to 1.9 Volt. In the software the DAC count starts at 0, while on the front it starts at 1.
# Changing the output by voltage
D5a.set_voltage(0, 1.9)
Optionally the output voltage might also be changed by setting a digital bit value ranging from $0$ to $2^{18}-1$ using change_value_update
.
# Changing the output by ditigal values
D5a.change_value_update(1, 165535)
When done with the measurement, it is recommended to close the SPI Rack connection. This will allow other measurement scripts to acces the device.
spi_rack.close()