Skip to content

Commit cefe237

Browse files
committed
Add resync example and docs
1 parent 2a8da4a commit cefe237

File tree

6 files changed

+103
-2
lines changed

6 files changed

+103
-2
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ makedocs(
2323
"Sequence Ramping" => "examples/seqRamping.md",
2424
"Cluster" => "examples/cluster.md",
2525
"Batch" => "examples/batch.md",
26-
"Continous Signal Acquisition" => "examples/producerConsumer.md"],
26+
"Continous Signal Acquisition" => "examples/producerConsumer.md",
27+
"Resync" => "examples/resync.md",],
2728
"FPGA Development" => "fpga.md",
2829
"Development Tips" => "devtips.md",
2930
#"Getting Started" => "overview.md",

docs/src/assets/resync.png

122 KB
Loading

docs/src/examples/resync.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Resync Example
2+
3+
In this example we add a resync signal to a [sequence](sequence.md) to create a signal that resynchronizes phase and frequency of the DACs after every frame. This can be used to change the frequency and phase of a signal during measurement. While the resynchronization is synchronous due to the sequences, the actual new frequency and phase information is asynchronous as they are transmitted via SCPI.
4+
5+
The example constructs a sequence with no offset and the very last step has the resync flag enabled. Note that during the resync-step the DAC outputs zero.
6+
7+
## Julia Client
8+
9+
This and all other examples are located in the ```examples``` [directory](https://github.com/tknopp/RedPitayaDAQServer/tree/master/src/examples/julia)
10+
11+
````@eval
12+
# Adapted from https://github.com/JuliaDocs/Documenter.jl/issues/499
13+
using Markdown
14+
Markdown.parse("""
15+
```julia
16+
$(open(f->read(f, String), "../../../src/examples/julia/resync.jl"))
17+
```
18+
""")
19+
````
20+
21+
![Resync Example Results](../assets/resync.png)

docs/src/generation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ As the LUT used by the FPGA image is small in comparison with the main memory an
2525

2626
Comparable to the sample transmission of the acquisition, this updating of the LUT is also a process with timing uncertainty as it is affected by the scheduling and execution of the RedPitayas CPU. While during the sample transmission samples could be lost because they were overwritten, in the signal generation wrong signals could be output because the server was too slow in updating the values. Here, the server tracks similar performance metrics and also features a status flag `lostSteps` for exactly this case. In its current implementation a safe step rate is at 12 kHz.
2727

28-
Sequences and their steps also have additional features. A step can be marked such that during its duration the signal is set to 0. Furthermore, a step can be marked such that it triggers the ramp down. To make this easier to manage the server actually manages three sequences, that can be set individually: A ramp up, regular and ramp down sequence. The ramp up sequence is moved to the FPGA LUT at the acquisition start, followed by the regular sequence. Afterwards the ramp down sequence is started and during its execution the ramp down flag is set.
28+
Sequences and their steps also have additional features. A step can be marked such that during its duration the signal is set to 0. Furthermore, a step can be marked such that it triggers the ramp down. To make this easier to manage the server actually manages three sequences, that can be set individually: A ramp up, regular and ramp down sequence. The ramp up sequence is moved to the FPGA LUT at the acquisition start, followed by the regular sequence. Afterwards the ramp down sequence is started and during its execution the ramp down flag is set. Steps can also be marked to resync the fast DACs. During a resync, the signals are set to 0 and afterwards start again with their set phase and frequency. This can be used to change frequency and phase during measurements and s.t. the new phase and frequency is synchronous to the steps.
2929

3030
## Calibration
3131
Similar to the signal acquisition, there are also calibration scale ``c_{i, scale}`` and offset ``c_{i, offset}`` values for the signal generation. These are stored in the EEPROM of the RedPitaya and can be updated by a client. The calibration values are always applied, even when the master trigger is off.

docs/src/scpi.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ During an active trigger the buffer is periodically updated by the server. If th
5353
| RP:DAC:SEQ:CHan? | | Return the number of sequence channel | | |
5454
| RP:DAC:SEQ:LUT | steps, repetitions | Instruct the server to receive a LUT over the data socket | C | RP:DAC:SEQ:LUT 10,2 |
5555
| RP:DAC:SEQ:LUT:ENaBle | | Instruct the server to receive an enable LUT over the data socket of the same shape as the regular LUT| C | |
56+
| RP:DAC:SEQ:LUT:ReSYNC | | Instruct the server to receive a resync LUT over the data socket of the same shape as the regular LUT| C | |
5657
| RP:DAC:SEQ:LUT:UP | steps, repetitions | Instruct the server to receive a ramp up LUT over the data socket | C | |
5758
| RP:DAC:SEQ:LUT:DOWN | steps, repetitions | Instruct the server to receive a ramp down LUT over the data socket | C | |
5859
| RP:DAC:SEQ:CLEAR | | Clear the set sequence values from the FPGA buffer | C | |

src/examples/julia/resync.jl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using RedPitayaDAQServer
2+
using CairoMakie
3+
4+
# obtain the URL of the RedPitaya
5+
include("config.jl")
6+
7+
rp = RedPitaya(URLs[1])
8+
serverMode!(rp, CONFIGURATION)
9+
10+
dec = 32
11+
modulus = 124800
12+
base_frequency = 125000000
13+
periods_per_step = 5
14+
samples_per_period = div(modulus, dec)
15+
periods_per_frame = 50
16+
frame_period = dec*samples_per_period*periods_per_frame / base_frequency
17+
steps_per_frame = div(50, periods_per_step)
18+
19+
decimation!(rp, dec)
20+
samplesPerPeriod!(rp, samples_per_period)
21+
periodsPerFrame!(rp, periods_per_frame)
22+
23+
for i in 1:2
24+
frequencyDAC!(rp, i, 1, base_frequency / modulus)
25+
signalTypeDAC!(rp, i, 1, "SINE")
26+
amplitudeDAC!(rp, i, 1, 0.2)
27+
phaseDAC!(rp, i, 1, 0)
28+
end
29+
triggerMode!(rp, INTERNAL)
30+
31+
# Sequence Configuration
32+
clearSequence!(rp)
33+
stepsPerFrame!(rp, steps_per_frame)
34+
seqChan!(rp, 2)
35+
lut = reshape(fill(0.0f0, steps_per_frame), 1, :)
36+
lut = repeat(lut, outer = 2)
37+
enable = collect(fill(true, steps_per_frame))
38+
enable = reshape(enable, 1, :)
39+
enable = repeat(enable, outer = 2)
40+
# In the last step of each frame we resync the DACs
41+
resync = vcat(fill(false, steps_per_frame - 1), [true])
42+
resync = reshape(resync, 1, :)
43+
resync = repeat(resync, outer = 2)
44+
seq = SimpleSequence(lut, 2, enable, resync)
45+
sequence!(rp, seq)
46+
47+
samples_per_frame = samples_per_period * periods_per_frame
48+
target = samples_per_frame * 0.3 # After a third of a frame we want to switch frequency
49+
50+
serverMode!(rp, ACQUISITION)
51+
masterTrigger!(rp, true)
52+
53+
# Wait until we reach the target sample
54+
curr = currentWP(rp)
55+
while curr < target
56+
# NOP
57+
global curr = currentWP(rp)
58+
sleep(0.01)
59+
end
60+
61+
# Update the phase and frequency of the second channel
62+
frequencyDAC!(rp, 2, 1, base_frequency / (2*modulus))
63+
phaseDAC!(rp, 2, 1, pi)
64+
65+
data = readFrames(rp, 0, 2)
66+
67+
masterTrigger!(rp, false)
68+
serverMode!(rp, CONFIGURATION)
69+
70+
71+
fig = Figure()
72+
lines(fig[1, 1], vec(data[:, 2, :, 1]), axis = (ylabel = "First Frame", title = "All Periods"))
73+
lines(fig[1, 2], vec(data[:, 2, 1:5, 1]), axis = (ylabel = "First Frame", title = "First Periods"))
74+
lines(fig[2, 1], vec(data[:, 2, :, 2]), axis = (ylabel = "Second Frame",))
75+
lines(fig[2, 2], vec(data[:, 2, 1:5, 2]), axis = (ylabel = "Second Frame",))
76+
77+
save(joinpath(@__DIR__(), "images", "resync.png"), fig)
78+
fig

0 commit comments

Comments
 (0)