Skip to content

Commit addef85

Browse files
authored
Merge pull request #93 from tknopp/tk/hbridge
HBridge Branch
2 parents 9a48579 + 34a932c commit addef85

File tree

23 files changed

+1266
-116
lines changed

23 files changed

+1266
-116
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/client/julia/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RedPitayaDAQServer"
22
uuid = "c544963a-496b-56d4-a5fe-f99a3f174c8f"
33
authors = ["Tobias Knopp <tobias@knoppweb.de>"]
4-
version = "0.8.2"
4+
version = "0.10.0"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/client/julia/src/Sequence.jl

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ Struct representing a sequence in which the server directly takes the values fro
103103
"""
104104
struct SimpleSequence <: AbstractSequence
105105
lut::SequenceLUT
106-
enable::Union{Array{Bool}, Nothing}
106+
enable::Union{Matrix{Bool}, Nothing}
107+
resync::Union{Matrix{Bool}, Nothing}
107108
"""
108109
SimpleSequence(lut, repetitions, enable=nothing)
109110
@@ -114,17 +115,18 @@ struct SimpleSequence <: AbstractSequence
114115
- `repetitions::Int32`: the number of times the sequence should be repeated
115116
- `emable::Union{Array{Bool}, Nothing}`: matrix containing enable flags
116117
"""
117-
function SimpleSequence(lut::Array{Float32}, repetitions::Integer, enable::Union{Array{Bool}, Nothing}=nothing)
118+
function SimpleSequence(lut::Matrix{Float32}, repetitions::Integer, enable::Union{Matrix{Bool}, Nothing}=nothing, resync::Union{Matrix{Bool}, Nothing} = nothing)
118119
if !isnothing(enable) && size(lut) != size(enable)
119120
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
120121
end
121-
return new(SequenceLUT(lut, repetitions), enable)
122+
return new(SequenceLUT(lut, repetitions), enable, resync)
122123
end
123124
end
124-
SimpleSequence(lut::Array{T}, repetitions::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = SimpleSequence(map(Float32, lut), repetitions, enable)
125-
SimpleSequence(lut::Vector{T}, repetitions::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = SimpleSequence(reshape(lut, 1, :), repetitions, enable)
125+
SimpleSequence(lut::Array{T}, repetitions::Integer, args...) where T <: Real = SimpleSequence(map(Float32, lut), repetitions, args...)
126+
SimpleSequence(lut::Vector{T}, repetitions::Integer, args...) where T <: Real = SimpleSequence(reshape(lut, 1, :), repetitions, args...)
126127

127128
enableLUT(seq::SimpleSequence) = seq.enable
129+
resyncLUT(seq::SimpleSequence) = seq.resync
128130
valueLUT(seq::SimpleSequence) = seq.lut
129131
rampUpLUT(seq::SimpleSequence) = nothing
130132
rampDownLUT(seq::SimpleSequence) = nothing
@@ -134,17 +136,19 @@ abstract type RampingSequence <: AbstractSequence end
134136
struct SimpleRampingSequence <: AbstractSequence
135137
lut::SequenceLUT
136138
enable::Union{Array{Bool}, Nothing}
139+
resync::Union{Array{Bool}, Nothing}
137140
rampUp::SequenceLUT
138141
rampDown::SequenceLUT
139-
function SimpleRampingSequencee(lut::SequenceLUT, up::SequenceLUT, down::SequenceLUT, enable::Union{Array{Bool}, Nothing}=nothing)
142+
function SimpleRampingSequencee(lut::SequenceLUT, up::SequenceLUT, down::SequenceLUT, enable::Union{Array{Bool}, Nothing}=nothing, resync::Union{Array{Bool}, Nothing}=nothing)
140143
if !isnothing(enable) && size(values(lut)) != size(enable)
141144
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
142145
end
143-
return new(SequenceLUT(lut, repetitions), enable, up, down)
146+
return new(SequenceLUT(lut, repetitions), enable, resync, up, down)
144147
end
145148
end
146149

147150
enableLUT(seq::SimpleRampingSequence) = seq.enable
151+
resyncLUT(seq::SimpleRampingSequence) = seq.resync
148152
valueLUT(seq::SimpleRampingSequence) = seq.lut
149153
rampUpLUT(seq::SimpleRampingSequence) = nothing
150154
rampDownLUT(seq::SimpleRampingSequence) = nothing
@@ -158,6 +162,7 @@ end
158162
struct HoldBorderRampingSequence <: RampingSequence
159163
lut::SequenceLUT
160164
enable::Union{Array{Bool}, Nothing}
165+
resync::Union{Array{Bool}, Nothing}
161166
rampUp::SequenceLUT
162167
rampDown::SequenceLUT
163168

@@ -170,13 +175,13 @@ struct HoldBorderRampingSequence <: RampingSequence
170175
- `lut`,`repetitions`,`enable` are used the same as for a `SimpleSequence`
171176
- `rampingSteps` is the number of steps the first and last value of the given sequence are repeated before the sequence is started
172177
"""
173-
function HoldBorderRampingSequence(lut::Array{Float32}, repetitions::Integer, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing)
178+
function HoldBorderRampingSequence(lut::Array{Float32}, repetitions::Integer, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing, resync::Union{Array{Bool}, Nothing}=nothing)
174179
if !isnothing(enable) && size(lut) != size(enable)
175180
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
176181
end
177182
up = SequenceLUT(lut[:, 1], rampingSteps)
178183
down = SequenceLUT(lut[:, end], rampingSteps)
179-
return new(SequenceLUT(lut, repetitions), enable, up, down)
184+
return new(SequenceLUT(lut, repetitions), enable, resync, up, down)
180185
end
181186
end
182187

@@ -190,38 +195,42 @@ function HoldBorderRampingSequence(rp::RedPitaya, lut, repetitions, enable=nothi
190195
end
191196

192197
enableLUT(seq::HoldBorderRampingSequence) = seq.enable
198+
resyncLUT(seq::HoldBorderRampingSequence) = seq.resync
193199
valueLUT(seq::HoldBorderRampingSequence) = seq.lut
194200
rampUpLUT(seq::HoldBorderRampingSequence) = seq.rampUp
195201
rampDownLUT(seq::HoldBorderRampingSequence) = seq.rampDown
196202

197203
struct ConstantRampingSequence <: RampingSequence
198204
lut::SequenceLUT
199205
enable::Union{Array{Bool}, Nothing}
206+
resync::Union{Array{Bool}, Nothing}
200207
ramping::SequenceLUT
201208

202-
function ConstantRampingSequence(lut::Array{Float32}, repetitions::Integer, rampingValue::Float32, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing)
209+
function ConstantRampingSequence(lut::Array{Float32}, repetitions::Integer, rampingValue::Float32, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing, resync::Union{Array{Bool}, Nothing}=nothing)
203210
if !isnothing(enable) && size(lut) != size(enable)
204211
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
205212
end
206213
rampingLut = SequenceLUT([rampingValue for i = 1:size(lut, 1)], rampingSteps)
207-
return new(SequenceLUT(lut, repetitions), enable, rampingLut)
214+
return new(SequenceLUT(lut, repetitions), enable, resync, rampingLut)
208215
end
209216
end
210217
ConstantRampingSequence(lut::Array{T}, repetitions::Integer, rampingValue::Real, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = ConstantRampingSequence(map(Float32, lut), repetitions, Float32(rampingValue), rampingSteps, enable)
211218
ConstantRampingSequence(lut::Vector{Float32}, repetitions::Integer, rampingValue::Float32, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) = ConstantRampingSequence(reshape(lut, 1, :), repetitions, rampingValue, rampingSteps, enable)
212219
ConstantRampingSequence(lut::Vector{T}, repetitions::Integer, rampingValue::Real, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = ConstantRampingSequence(reshape(lut, 1, :), repetitions, rampingValue, rampingSteps, enable)
213220

214221
enableLUT(seq::ConstantRampingSequence) = seq.enable
222+
resyncLUT(seq::ConstantRampingSequence) = seq.resync
215223
valueLUT(seq::ConstantRampingSequence) = seq.lut
216224
rampUpLUT(seq::ConstantRampingSequence) = seq.ramping
217225
rampDownLUT(seq::ConstantRampingSequence) = seq.ramping
218226

219227
struct StartUpSequence <: RampingSequence
220228
lut::SequenceLUT
221229
enable::Union{Array{Bool}, Nothing}
230+
resync::Union{Array{Bool}, Nothing}
222231
rampUp::SequenceLUT
223232
rampDown::SequenceLUT
224-
function StartUpSequence(lut::Array{Float32}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing)
233+
function StartUpSequence(lut::Array{Float32}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing, resync::Union{Array{Bool}, Nothing}=nothing)
225234
if !isnothing(enable) && size(lut) != size(enable)
226235
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
227236
end
@@ -239,14 +248,15 @@ struct StartUpSequence <: RampingSequence
239248
end
240249
up = SequenceLUT(upLut, 1)
241250
down = SequenceLUT(lut[:, end], rampingSteps)
242-
return new(SequenceLUT(lut, repetitions), enable, up, down)
251+
return new(SequenceLUT(lut, repetitions), enable, resync, up, down)
243252
end
244253
end
245254
StartUpSequence(lut::Array{T}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = StartUpSequence(map(Float32, lut), repetitions, rampingSteps, startUpSteps, enable)
246255
#StartUpSequence(lut::Vector{Float32}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) = StartUpSequence(reshape(lut, 1, :), repetitions, rampingSteps, startUpSteps, enable)
247256
StartUpSequence(lut::Vector{T}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = StartUpSequence(reshape(lut, 1, :), repetitions, rampingSteps, startUpSteps, enable)
248257

249258
enableLUT(seq::StartUpSequence) = seq.enable
259+
resyncLUT(seq::StartUpSequence) = seq.resync
250260
valueLUT(seq::StartUpSequence) = seq.lut
251261
rampUpLUT(seq::StartUpSequence) = seq.rampUp
252262
rampDownLUT(seq::StartUpSequence) = seq.rampDown
@@ -269,10 +279,11 @@ Transmit the client-side representation `seq` to the server and append it to the
269279
"""
270280
function sequence!(rp::RedPitaya, seq::AbstractSequence)
271281
result = true
272-
result &= valueLUT!(rp, valueLUT(seq))
273-
result &= enableLUT!(rp, enableLUT(seq))
274-
result &= rampUpLUT!(rp, rampUpLUT(seq))
275-
result &= rampDownLUT!(rp, rampDownLUT(seq))
282+
result &= valueLUT!(rp, seq)
283+
result &= enableLUT!(rp, seq)
284+
result &= resyncLUT!(rp, seq)
285+
result &= rampUpLUT!(rp, seq)
286+
result &= rampDownLUT!(rp, seq)
276287
result &= setSequence!(rp)
277288
return result
278289
end
@@ -283,11 +294,13 @@ function transmitLUT!(rp::RedPitaya, lut::Array{Float32}, cmd::String, repetitio
283294
return parse(Bool, receive(rp))
284295
end
285296

297+
valueLUT!(rp::RedPitaya, lut::AbstractSequence) = valueLUT!(rp, valueLUT(lut))
286298
function valueLUT!(rp::RedPitaya, lut::SequenceLUT)
287299
lutFloat32 = map(Float32, values(lut))
288300
return transmitLUT!(rp, lutFloat32, "RP:DAC:SEQ:LUT", repetitions(lut))
289301
end
290302

303+
rampUpLUT!(rp::RedPitaya, lut::AbstractSequence) = rampUpLUT!(rp, rampUpLUT(lut))
291304
function rampUpLUT!(rp::RedPitaya, lut::SequenceLUT)
292305
lutFloat32 = map(Float32, values(lut))
293306
return transmitLUT!(rp, lutFloat32, "RP:DAC:SEQ:LUT:UP", repetitions(lut))
@@ -298,6 +311,7 @@ function rampUpLUT!(rp::RedPitaya, lut::Nothing)
298311
return true
299312
end
300313

314+
rampDownLUT!(rp::RedPitaya, lut::AbstractSequence) = rampDownLUT!(rp, rampDownLUT(lut))
301315
function rampDownLUT!(rp::RedPitaya, lut::SequenceLUT)
302316
lutFloat32 = map(Float32, values(lut))
303317
return transmitLUT!(rp, lutFloat32, "RP:DAC:SEQ:LUT:DOWN", repetitions(lut))
@@ -308,6 +322,7 @@ function rampDownLUT!(rp::RedPitaya, lut::Nothing)
308322
return true
309323
end
310324

325+
enableLUT!(rp::RedPitaya, lut::AbstractSequence) = enableLUT!(rp, enableLUT(lut))
311326
function enableLUT!(rp::RedPitaya, lut::Array)
312327
lutBool = map(Bool, lut)
313328
send(rp, string("RP:DAC:SEQ:LUT:ENaBle"))
@@ -322,6 +337,21 @@ function enableLUT!(rp::RedPitaya, lut::Nothing)
322337
return true
323338
end
324339

340+
resyncLUT!(rp::RedPitaya, lut::AbstractSequence) = resyncLUT!(rp, resyncLUT(lut))
341+
function resyncLUT!(rp::RedPitaya, lut::Array)
342+
lutBool = map(Bool, lut)
343+
send(rp, string("RP:DAC:SEQ:LUT:ReSYNC"))
344+
@debug "Writing resync DAC LUT"
345+
write(rp.dataSocket, lutBool)
346+
reply = receive(rp)
347+
return parse(Bool, reply)
348+
end
349+
350+
function resyncLUT!(rp::RedPitaya, lut::Nothing)
351+
# NOP
352+
return true
353+
end
354+
325355
function seqTiming(seq::AbstractSequence)
326356
up = 0
327357
if !isnothing(rampUpLUT(seq))

src/client/julia/src/SlowIO.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,43 @@ end
182182
scpiCommand(::typeof(DIO), pin) = string("RP:DIO:", DIOPinToCommand(pin), "?")
183183
scpiReturn(::typeof(DIO)) = String
184184
parseReturn(::typeof(DIO), ret) = occursin("ON", ret)
185+
186+
187+
188+
189+
190+
191+
export DIOHBridge!
192+
"""
193+
DIOHBridge!(rp::RedPitaya, pin::DIOPins, val::Bool)
194+
195+
Set the value of DIOHBridge pin `pin` to the value `val`.
196+
# Example
197+
```julia
198+
julia> DIOHBridge!(rp, DIO7_P, true)
199+
true
200+
```
201+
"""
202+
function DIOHBridge!(rp::RedPitaya, pin, val)
203+
return query(rp, scpiCommand(DIOHBridge!, pin, val), scpiReturn(DIOHBridge!))
204+
end
205+
scpiCommand(::typeof(DIOHBridge!), pin::DIOPins, val::Bool) = string("RP:DIO:", DIOPinToCommand(pin), ":HBRIDGE ", (val ? "ON" : "OFF"))
206+
scpiReturn(::typeof(DIOHBridge!)) = Bool
207+
208+
export DIOHBridge
209+
"""
210+
DIOHBridge(rp::RedPitaya, pin::DIOPins)
211+
212+
Get the value of DIOHBridge pin `pin`.
213+
# Example
214+
```julia
215+
julia>DIOHBridge(rp, DIO7_P)
216+
true
217+
```
218+
"""
219+
function DIOHBridge(rp::RedPitaya, pin)
220+
return parseReturn(DIOHBridge, query(rp, scpiCommand(DIOHBridge, pin), scpiReturn(DIOHBridge)))
221+
end
222+
scpiCommand(::typeof(DIOHBridge), pin) = string("RP:DIO:", DIOPinToCommand(pin), ":HBRIDGE?")
223+
scpiReturn(::typeof(DIOHBridge)) = String
224+
parseReturn(::typeof(DIOHBridge), ret) = occursin("ON", ret)

src/examples/julia/config.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# URLs= ["rp-f08ccb.local", "rp-f08caa.local"]
22
URLs= ["192.168.1.100"]#, "192.168.2.17"]
3+
# URLs= ["192.168.178.65"]#, "192.168.178.95"]
34
mkpath("images")

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)