Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cryvisil/run_coarse_approach_down.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
149 lines (114 sloc)
3.59 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from epics import caput, caget | |
import numpy as np | |
from scipy import signal | |
import time | |
amplitude = caget('CRYVISIL:AWG0:Amp0:Amplitude') # peak-peak / amplification factor | |
array_length = caget('CRYVISIL:AWG0:Channel0:SetWfSize') | |
source = 1 | |
steps = caget('CRYVISIL:AWG0:Channel0:SetBurstCount') | |
direction = -1 # up: 1, down:-1 | |
burst_control = 32768 | |
repetitions = 1 | |
# stop synthesizer | |
caput("CRYVISIL:AWG0:HoldDDS", 15) | |
# set limits for amplitude (peak-to-peak) | |
for i in [ | |
'CRYVISIL:AWG0:Amp0:Amplitude.DRVH', | |
'CRYVISIL:AWG0:Amp1:Amplitude.DRVH', | |
'CRYVISIL:AWG0:Amp2:Amplitude.DRVH', | |
'CRYVISIL:AWG0:Amp3:Amplitude.DRVH' | |
]: | |
caput(i, 10) | |
# set amplitude | |
for i in [ | |
'CRYVISIL:AWG0:Amp0:Amplitude', | |
'CRYVISIL:AWG0:Amp1:Amplitude', | |
'CRYVISIL:AWG0:Amp2:Amplitude', | |
'CRYVISIL:AWG0:Amp3:Amplitude' | |
]: | |
caput(i, amplitude) | |
# set wform length | |
for i in [ | |
'CRYVISIL:AWG0:Channel0:SetWfSize', | |
'CRYVISIL:AWG0:Channel1:SetWfSize', | |
'CRYVISIL:AWG0:Channel2:SetWfSize', | |
'CRYVISIL:AWG0:Channel3:SetWfSize' | |
]: | |
caput(i, array_length) | |
# set source (all derived from DDS 1(B)) | |
for i in [ | |
'CRYVISIL:AWG0:Channel0:SetSource', | |
'CRYVISIL:AWG0:Channel1:SetSource', | |
'CRYVISIL:AWG0:Channel2:SetSource', | |
'CRYVISIL:AWG0:Channel3:SetSource' | |
]: | |
caput(i, source) | |
############################################################################### | |
# Define waveforms | |
fraction = 0.3 | |
t = np.linspace(0, 1, int(round(array_length * fraction))) | |
saw = signal.sawtooth(2 * np.pi * t) | |
cos = -np.cos(np.pi * t) | |
shift = int(round(array_length * fraction)) | |
# start at min/max | |
tbasic = np.zeros(array_length)+1 | |
tbasic[0:shift - 1] = saw[:-1] | |
# tbasic[0:int(round(array_length * fraction)) - 1] = cos[:-1] | |
t0 = np.copy(tbasic) | |
t0[shift:] = -1 | |
t0 = (t0 * 32767 * direction).astype(int) | |
t1 = np.copy(tbasic) | |
t1[int(round(2*shift + shift/10)) - 1:] = -1 | |
t1 = (t1 * 32767 * direction).astype(int) | |
t2 = np.copy(tbasic) | |
t2[int(round(3*shift + 2*shift/10)) - 1:] = -1 | |
t2 = (t2 * 32767 * direction).astype(int) | |
# start at 0 | |
exp = 1 # must be odd! 1 is linear increase | |
cbasic = np.zeros(array_length) | |
ind_saw = int(len(saw)/2) | |
saw1 = saw[ind_saw:-1] | |
saw2 = saw[0:ind_saw] | |
start = int((1-fraction*3)/2*array_length) | |
cbasic = np.insert(cbasic, start, saw1**exp) | |
cbasic = np.insert(cbasic, start+len(saw1)+2*shift, saw2**exp) | |
c0 = cbasic.copy() | |
c0[start+len(saw1):start+len(saw1)+2*shift] = -1 | |
c1 = cbasic.copy() | |
c1[start+len(saw1):start+len(saw1)+shift] = 1 | |
c1[start+len(saw1)+shift:start+len(saw1)+2*shift] = -1 | |
c2 = cbasic.copy() | |
c2[start+len(saw1):start+len(saw1)+2*shift] = 1 | |
# only in one direction (+/-) | |
# square root | |
sbasic = np.zeros(array_length)+0 | |
sbasic = np.insert(sbasic, start, np.sqrt(saw1)) | |
s0 = sbasic.copy() | |
s1 = sbasic.copy() | |
s1[start+len(saw1):start+len(saw1)+shift] = 1 | |
s2 = sbasic.copy() | |
s2[start+len(saw1):start+len(saw1)+2*shift] = 1 | |
############################################################################### | |
caput("CRYVISIL:AWG0:Channel0:wform", t0) | |
caput("CRYVISIL:AWG0:Channel1:wform", t1) | |
caput("CRYVISIL:AWG0:Channel2:wform", t2) | |
# set Burst count | |
for i in [ | |
'CRYVISIL:AWG0:Channel0:SetBurstCount', | |
'CRYVISIL:AWG0:Channel1:SetBurstCount', | |
'CRYVISIL:AWG0:Channel2:SetBurstCount', | |
'CRYVISIL:AWG0:Channel3:SetBurstCount' | |
]: | |
caput(i, steps) | |
# prepare burst mode | |
for i in [ | |
'CRYVISIL:AWG0:Channel0:SetBurstControl', | |
'CRYVISIL:AWG0:Channel1:SetBurstControl', | |
'CRYVISIL:AWG0:Channel2:SetBurstControl', | |
'CRYVISIL:AWG0:Channel3:SetBurstControl' | |
]: | |
caput(i, burst_control) | |
caput("CRYVISIL:AWG0:HoldDDS", 13) | |
for i in range(repetitions): | |
caput("CRYVISIL:AWG0:Channel0:ArmAllBursts", 33024) | |
time.sleep(1) |