# Setup script for the ISEG VHS-Cxxxx (12 channel) high voltage module.

# In addition to simple 16-bit write commands this script uses the
# 'write_float_word' command which takes a float value and an index (one of
# 'upper' or 'lower') to specify which 16-bit word of the floats binary
# representation to write to the register.
# The VHS-Cxxxx internally uses big-endian byte order so it expects the two
# high bytes of a float at the first register address, the two low bytes at the
# register offset by 2 (upper first, lower second).

# The speed of the voltage ramp in percent of the nominal voltage of the
# channel. The upper limit is 20%. The lower limit is equivalent to 1mV/s.
set VoltageRampSpeedPercent 1.0

# ChannelControl values. Bit 3 (value 0x0008) is the 'SetON' bit to enable the
# channel.
set ChannelControl0  0x0008
set ChannelControl1  0x0008
set ChannelControl2  0x0008
set ChannelControl3  0x0008
set ChannelControl4  0x0008
set ChannelControl5  0x0008
set ChannelControl6  0x0008
set ChannelControl7  0x0008
set ChannelControl8  0x0008
set ChannelControl9  0x0008
set ChannelControl10 0x0008
set ChannelControl11 0x0008

set VoltageSet0  0.0
set VoltageSet1  0.0
set VoltageSet2  0.0
set VoltageSet3  0.0
set VoltageSet4  0.0
set VoltageSet5  0.0
set VoltageSet6  0.0
set VoltageSet7  0.0
set VoltageSet8  0.0
set VoltageSet9  0.0
set VoltageSet10 0.0
set VoltageSet11 0.0

# VHS default module base address. The write commands in this script will
# add this value to their address arguments.
setbase 0x00004000

write a16 d16 0x0002 0x0040 # ModuleControl: doClear

# VoltageRampSpeed
write_float_word a16 0x0014 upper ${RampSpeedPercent}
write_float_word a16 0x0016 lower ${RampSpeedPercent}

# Channel Offsets:
# Channel 0: 0x0060
# Channel 1: 0x0090
# Channel 2: 0x00C0
# Channel 3: 0x00F0
# Channel 4: 0x0120
# Channel 5: 0x0150
# Channel 6: 0x0180
# Channel 7: 0x01B0
# Channel 8: 0x01E0
# Channel 9: 0x0210
# Channel10: 0x0240
# Channel11: 0x0270

# Channel0
write a16 d16 0x0062 ${ChannelControl0}                     # Ch0 ChannelControl: setON
write_float_word a16 0x0068 upper ${VoltageSet0}            # Ch0 VoltageSet upper 16 bits
write_float_word a16 0x006A lower ${VoltageSet0}            # Ch0 VoltageSet lower 16 bits

# Channel1
write a16 d16 0x0092 ${ChannelControl1}                     # Ch1 ChannelControl: setON
write_float_word a16 0x0098 upper ${VoltageSet1}            # Ch1 VoltageSet upper 16 bits
write_float_word a16 0x009A lower ${VoltageSet1}            # Ch1 VoltageSet lower 16 bits

# Channel2
write a16 d16 0x00C2 ${ChannelControl2}                     # Ch2 ChannelControl: setON
write_float_word a16 0x00C8 upper ${VoltageSet2}            # Ch2 VoltageSet upper 16 bits
write_float_word a16 0x00CA lower ${VoltageSet2}            # Ch2 VoltageSet lower 16 bits

# Channel3
write a16 d16 0x00F2 ${ChannelControl3}                     # Ch3 ChannelControl: setON
write_float_word a16 0x00F8 upper ${VoltageSet3}            # Ch3 VoltageSet upper 16 bits
write_float_word a16 0x00FA lower ${VoltageSet3}            # Ch3 VoltageSet lower 16 bits

# Channel4
write a16 d16 0x0122 ${ChannelControl4}                     # Ch4 ChannelControl: setON
write_float_word a16 0x0128 upper ${VoltageSet4}            # Ch4 VoltageSet upper 16 bits
write_float_word a16 0x012A lower ${VoltageSet4}            # Ch4 VoltageSet lower 16 bits

# Channel5
write a16 d16 0x0152 ${ChannelControl5}                     # Ch5 ChannelControl: setON
write_float_word a16 0x0158 upper ${VoltageSet5}            # Ch5 VoltageSet upper 16 bits
write_float_word a16 0x015A lower ${VoltageSet5}            # Ch5 VoltageSet lower 16 bits

# Channel6
write a16 d16 0x0182 ${ChannelControl6}                     # Ch6 ChannelControl: setON
write_float_word a16 0x0188 upper ${VoltageSet6}            # Ch6 VoltageSet upper 16 bits
write_float_word a16 0x018A lower ${VoltageSet6}            # Ch6 VoltageSet lower 16 bits

# Channel7
write a16 d16 0x01B2 ${ChannelControl7}                     # Ch7 ChannelControl: setON
write_float_word a16 0x01B8 upper ${VoltageSet7}            # Ch7 VoltageSet upper 16 bits
write_float_word a16 0x01BA lower ${VoltageSet7}            # Ch7 VoltageSet lower 16 bits

# Channel8
write a16 d16 0x01E2 ${ChannelControl8}                     # Ch8 ChannelControl: setON
write_float_word a16 0x01E8 upper ${VoltageSet8}            # Ch8 VoltageSet upper 16 bits
write_float_word a16 0x01EA lower ${VoltageSet8}            # Ch8 VoltageSet lower 16 bits

# Channel9
write a16 d16 0x0212 ${ChannelControl9}                     # Ch9 ChannelControl: setON
write_float_word a16 0x0218 upper ${VoltageSet9}            # Ch9 VoltageSet upper 16 bits
write_float_word a16 0x021A lower ${VoltageSet9}            # Ch9 VoltageSet lower 16 bits

# Channel10
write a16 d16 0x0242 ${ChannelControl10}                    # Ch10 ChannelControl: setON
write_float_word a16 0x0248 upper ${VoltageSet10}           # Ch10 VoltageSet upper 16 bits
write_float_word a16 0x024A lower ${VoltageSet10}           # Ch10 VoltageSet lower 16 bits

# Channel11
write a16 d16 0x0272 ${ChannelControl11}                    # Ch11 ChannelControl: setON
write_float_word a16 0x0278 upper ${VoltageSet11}           # Ch11 VoltageSet upper 16 bits
write_float_word a16 0x027A lower ${VoltageSet11}           # Ch11 VoltageSet lower 16 bits

