```
In [1]:
```from spirack import SPI_rack, S5k_module
import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook
import ipywidgets as ip

Open SPI rack connection and unlock (necessary after bootup of the controller module).

```
In [2]:
```spi = SPI_rack("COM4", 1000000, 1)
spi.unlock()

```
In [11]:
```s5k = S5k_module(spi, 3)
s5k.set_clock_source('internal')
s5k.set_clock_division(10)

```
In [12]:
```for DAC in range(1,5):
s5k.set_waveform_mode(DAC, 'AWG')
s5k.set_digital_gain(DAC, 0.5)
for DAC in range(9,13):
s5k.set_waveform_mode(DAC, 'sawtooth')
s5k.set_digital_gain(DAC, 0.5)

The sawtooth ramp time length is given by: $$t_{saw} = \frac{2^{14}\cdot n}{f_{ext}}$$

Where $f_{ext}$ is the external clock frequency and $n$ the amount of clock ticks per sawtooth step. For a sawtooth ramp time of ~8ms with an external clock of 10 MHz this gives $n=5$: $$t_{saw} = \frac{2^{14}\cdot 5}{10^6} = 8.192 \text{ ms}$$

So we set the DACs (that are set to sawtooth) to a stepsize of n=5 and a ramp-up sawtooth.

```
In [13]:
```for DAC in range(9,13):
s5k.set_sawtooth_parameters(DAC, 'ramp_up', 5)

```
In [17]:
```wv_len = 640
max_val = 2047
min_val = -2048
waveform_data = ((max_val-min_val)/wv_len) * np.arange(0, wv_len) + min_val
# Need to be integer values, smarter to cast after calculation for rounding errors
waveform_data = waveform_data.astype(int)
plt.figure()
plt.plot(waveform_data)
plt.title("Fast ramp RAM")
plt.xlabel("Samples")
plt.ylabel("RAM values")
plt.show()

```
```

```
In [18]:
```s5k.upload_waveform(1, waveform_data, 0, set_pattern_length=True)
for DAC in range(1,5):
s5k.set_RAM_address(DAC, 0, len(waveform_data)-1)

```
In [19]:
```s5k.run_module(True)

For a demo: knobs for the gain of all the DACs.

```
In [20]:
```def set_gain(DAC, value):
s5k.set_digital_gain(DAC, value)
DACs = [1,2,3,4,9,10,11,12]
sliders = [ip.widgets.FloatSlider(value=0.5, min=-1.0, max=1.0, step=0.01, description='DAC'+str(i)) for i in DACs]
for i in range(0,len(DACs)):
ip.interact(set_gain, DAC=ip.fixed(DACs[i]), value=sliders[i])

```
In [ ]:
```spi.close()