suservo: clean up and beautify example

This commit is contained in:
Robert Jördens 2018-05-14 13:22:34 +00:00 committed by Robert Jordens
parent 4ddb29fa02
commit 0c1caf0744
1 changed files with 29 additions and 13 deletions

View File

@ -16,11 +16,12 @@ class SUServo(EnvExperiment):
mask = 1 << 18 - 1 mask = 1 << 18 - 1
for name, val in zip("ftw1 b1 pow cfg offset a1 ftw0 b0".split(), d): for name, val in zip("ftw1 b1 pow cfg offset a1 ftw0 b0".split(), d):
val = -(val & mask) + (val & ~mask) val = -(val & mask) + (val & ~mask)
print(name, hex(val), val) print("{}: {:x} = {}".format(name, val, val))
@rpc(flags={"async"}) @rpc(flags={"async"})
def p1(self, adc, asf, st): def p1(self, adc, asf, st):
print("{:10s}".format("#"*int(adc*10))) print("ADC: {:10s}, ASF: {:10s}, clipped: {}".format(
"#"*int(adc), "#"*int(asf*10), (st >> 8) & 1), end="\r")
@kernel @kernel
def init(self): def init(self):
@ -40,28 +41,43 @@ class SUServo(EnvExperiment):
# Servo is done and disabled # Servo is done and disabled
assert self.suservo0.get_status() & 0xff == 2 assert self.suservo0.get_status() & 0xff == 2
# set up profile 0 on channel 0 # set up profile 0 on channel 0:
delay(100*us) delay(100*us)
self.suservo0_ch0.set_y(0, 0.) self.suservo0_ch0.set_y(
profile=0,
y=0. # clear integrator
)
self.suservo0_ch0.set_iir( self.suservo0_ch0.set_iir(
profile=0, adc=7, gain=-.1, corner=7000*Hz, limit=0., delay=0.) profile=0,
adc=7, # take data from Sampler channel 7
gain=-.1, # -0.1 P gain
corner=70*Hz, # very low corner frequency
limit=0., # unlimited integrator gain
delay=0. # no IIR update delay after enabling
)
# setpoint 0.5 (5 V with above PGIA gain setting)
# 71 MHz
# 0 phase
self.suservo0_ch0.set_dds( self.suservo0_ch0.set_dds(
profile=0, offset=-.5, frequency=71*MHz, phase=0.) profile=0,
# enable channel offset=-.5, # 5 V with above PGIA settings
frequency=71*MHz,
phase=0.)
# enable RF, IIR updates and profile 0
self.suservo0_ch0.set(en_out=1, en_iir=1, profile=0) self.suservo0_ch0.set(en_out=1, en_iir=1, profile=0)
# enable servo iterations # enable global servo iterations
self.suservo0.set_config(enable=1) self.suservo0.set_config(enable=1)
# check servo enabled
assert self.suservo0.get_status() & 0x01 == 1
delay(10*us)
# read back profile data # read back profile data
data = [0] * 8 data = [0] * 8
self.suservo0_ch0.get_profile_mu(0, data) self.suservo0_ch0.get_profile_mu(0, data)
self.p(data) self.p(data)
delay(10*ms) delay(10*ms)
# check servo enabled
assert self.suservo0.get_status() & 0x01 == 1
delay(10*us)
while True: while True:
self.suservo0.set_config(0) self.suservo0.set_config(0)
delay(10*us) delay(10*us)
@ -73,7 +89,7 @@ class SUServo(EnvExperiment):
delay(10*us) delay(10*us)
self.suservo0.set_config(1) self.suservo0.set_config(1)
self.p1(v, w, x) self.p1(v, w, x)
delay(200*ms) delay(20*ms)
@kernel @kernel
def led(self): def led(self):