Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gain error #86

Merged
merged 7 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/julia/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RedPitayaDAQServer"
uuid = "c544963a-496b-56d4-a5fe-f99a3f174c8f"
authors = ["Tobias Knopp <[email protected]>"]
version = "0.8.1"
version = "0.8.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
4 changes: 4 additions & 0 deletions src/client/julia/src/ADC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ julia> decimation(rp)
```
"""
function decimation!(rp::RedPitaya, dec)
if dec < 8 || dec > 8192 || mod(dec, 2) != 0
error("Decimation must be an even value between 8 and 8192. Supplied value is $dec.")
end

rp.decimation = Int64(dec)
return query(rp, scpiCommand(decimation!, rp.decimation), scpiReturn(decimation!))
end
Expand Down
16 changes: 12 additions & 4 deletions src/client/julia/src/Acquisition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function readSamplesHeartbeat(rpu::Union{RedPitaya,RedPitayaCluster, RedPitayaCl
# Current WP query as a heartbeat to avoid timeouts with "distant" wpStarts
timeDifference = time() - heartBeatStartTime
if timeDifference / (heartbeatTimeout*1000.0) >= timeOutCounter
@warn "Still waiting for write pointer (currently it is $(currentWP(rpu)). Are you sure there is no error and this loop is running infinitely?"
@warn "Still waiting for write pointer (currently it is $(currentWP(rpu))). Are you sure there is no error and this loop is running infinitely?"
timeOutCounter += 1
end
end
Expand All @@ -53,6 +53,11 @@ function correctFilterDelay(wpStart::Int64, dec::Int64)
return correctedWp
end

# See https://support.xilinx.com/s/question/0D52E00006hpfy6SAA/cic-filter-gain?language=en_US
gain_cic(rp::RedPitaya) = gain_cic(round(Int, rp.decimation / 2), 1, 6) # M and N are fixed due to the FPGA image settings
gain_cic(rpc::RedPitayaCluster) = gain_cic(round(Int, master(rpc).decimation / 2), 1, 6) # M and N are fixed due to the FPGA image settings
gain_cic(rpcv::RedPitayaClusterView) = gain_cic(rpcv.rpc)
gain_cic(R::Int64, M::Int64, N::Int64) = ((R * M)^N) / 2^(ceil(N * log2(R * M)))

"""
readSamples(rpu::Union{RedPitaya,RedPitayaCluster, RedPitayaClusterView}, wpStart::Int64, numOfRequestedSamples::Int64; chunkSize::Int64 = 25000, rpInfo=nothing)
Expand Down Expand Up @@ -220,8 +225,9 @@ function convertSamplesToFrames(rpu::Union{RedPitaya, RedPitayaCluster, RedPitay
frames = convertSamplesToFrames(samples, numChan, numSampPerPeriod, numPeriods, numFrames, numBlockAverages, numPeriodsPerPatch)
calibs = [x.calib for x in rpu]
calib = hcat(calibs...)
gainCorr_ = 1 / gain_cic(rpu)
for d = 1:size(frames, 2)
frames[:, d, :, :] .*= calib[1, d]
frames[:, d, :, :] .*= calib[1, d] * gainCorr_
frames[:, d, :, :] .+= calib[2, d]
end
return frames
Expand Down Expand Up @@ -255,8 +261,9 @@ function convertSamplesToFrames!(rpu::Union{RedPitaya, RedPitayaCluster, RedPita
convertSamplesToFrames!(samples, frames, numChan, numSampPerPeriod, numPeriods, numFrames, numTrueSampPerPeriod, numBlockAverages, numPeriodsPerPatch)
calibs = [x.calib for x in rpu]
calib = hcat(calibs...)
gainCorr_ = 1 / gain_cic(rpu)
for d = 1:size(frames, 2)
frames[:, d, :, :] .*= calib[1, d]
frames[:, d, :, :] .*= calib[1, d] * gainCorr_
frames[:, d, :, :] .+= calib[2, d]
end
end
Expand Down Expand Up @@ -331,8 +338,9 @@ function convertSamplesToPeriods!(rpu::Union{RedPitaya, RedPitayaCluster, RedPit
convertSamplesToPeriods!(samples, periods, numChan, numSampPerPeriod, numPeriods, numBlockAverages)
calibs = [x.calib for x in rpu]
calib = hcat(calibs...)
gainCorr_ = 1 / gain_cic(rpu)
for d = 1:size(periods, 2)
periods[:, d, :] .*= calib[1, d]
periods[:, d, :] .*= calib[1, d] * gainCorr_
periods[:, d, :] .+= calib[2, d]
end
return periods
Expand Down
7 changes: 4 additions & 3 deletions src/client/julia/src/Cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ function RedPitayaCluster(hosts::Vector{String}, port::Int64=5025, dataPort::Int
modes = fill(INTERNAL, length(rps))
modes[1] = EXTERNAL
end
@sync for (i, rp) in enumerate(rps)
@async begin

@sync for (i, rp) ∈ enumerate(rps)
@async begin
triggerMode!(rp, modes[i])
triggerPropagation!(rp, true)
end
end

triggerPropagation!(rps[end], false)

return RedPitayaCluster(rps)
end

Expand Down
2 changes: 1 addition & 1 deletion src/fpga/bd/bd.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ proc create_hier_cell_system_1 { parentCell nameHier } {
# Create instance: image_version, and set properties
set image_version [ create_bd_cell -type ip -vlnv xilinx.com:ip:xlconstant:1.1 image_version ]
set_property -dict [ list \
CONFIG.CONST_VAL {7} \
CONFIG.CONST_VAL {8} \
CONFIG.CONST_WIDTH {32} \
] $image_version

Expand Down
4 changes: 4 additions & 0 deletions src/lib/rp-daq-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ int setArbitraryWaveform(float* values, int channel) {
// Fast ADC

int setDecimation(uint16_t decimation) {
if(!(decimation % 2 == 0)) {
return -1;
}

if(decimation < 8 || decimation > 8192) {
return -1;
}
Expand Down
Loading