record(motor,"BOO-RF-TUNER:Cell1Motor")
{
	field(DESC,"B00-RF Cell 1")
	field(OUT, "@asyn(M0,0)")	
	field(DTYP,"asynMotor")
	field(DIR, "Pos")
	field(VMAX,"12.7")	
	field(VELO,"6.35")
	field(VBAS,"1.27")
	field(ACCL,"0.5")
	field(BDST,"0")
	field(BVEL,"1.27")
	field(BACC,"0.1")
	field(MRES,"9.921875e-05")
	field(PREC,"4")
	field(EGU, "mm")
	field(DHLM,"35")
	field(DLLM,"-25")
	field(INIT,"")
	field(RLV, "0")	
	field(TWV, "1")
	field(FOFF,"Frozen")		
	field(FRAC,"1")
	field(JVEL,"6.35")	
	field(JAR, "12.7")
	field(ERES,"1")
	field(RRES,"0.001")
	field(RDBD,"1")
	field(RTRY,"10")
	field(UEIP,"No")
	field(URIP,"No")
	field(DLY, "0")
	field(OMSL,"supervisory")
	field(CNEN,"Enable")
	field(SET, "Use")
	field(OFF, "0")
	field(PCOF,"0")
	field(ICOF,"0")
	field(DCOF,"0")
	field(RDBL,"")
	field(PREM,"")
	field(POST,"")
	field(FLNK,"")					
}

record(motor,"BOO-RF-TUNER:Cell5Motor")
{
	field(DESC,"B00-RF Cell 5")
	field(OUT, "@asyn(M1,0)")	
	field(DTYP,"asynMotor")
	field(DIR, "Pos")
	field(VMAX,"12.7")	
	field(VELO,"6.35")
	field(VBAS,"1.27")
	field(ACCL,"0.5")
	field(BDST,"0")
	field(BVEL,"1.27")
	field(BACC,"0.1")
	field(MRES,"9.921875e-05")
	field(PREC,"4")
	field(EGU, "mm")
	field(DHLM,"16")
	field(DLLM,"-44")
	field(INIT,"")
	field(RLV, "0")	
	field(TWV, "1")
	field(FOFF,"Frozen")		
	field(FRAC,"1")
	field(JVEL,"6.35")	
	field(JAR, "12.7")
	field(ERES,"1")
	field(RRES,"0.001")
	field(RDBD,"1")
	field(RTRY,"10")
	field(UEIP,"No")
	field(URIP,"No")
	field(DLY, "0")
	field(OMSL,"supervisory")
	field(CNEN,"Enable")
	field(SET, "Use")
	field(OFF, "0")
	field(PCOF,"0")
	field(ICOF,"0")
	field(DCOF,"0")
	field(RDBL,"")
	field(PREM,"")
	field(POST,"")
	field(FLNK,"")					
}

#===============================================================
#
# Abs:  Booster RF Tuner Tuner Potentiometer database
#
# File:tuner_pot.template
#
# Desc:  Booster RF has two tuner motors - 
#			one for moving tuner in Cell1 of the Booster RF cavity
#			and one for moving the tuner in Cell5 of the same cavity 
#        The motors are controlled via two EtherCAT Beckhoff modules EL7041.
#		 The motor position is readback via potentiometers via EtherCAT Beckhoff module EL3702 AI module.
#		 This database reads the raw counts from the potentiometer via an ADC and converts it first to Volts and then to mm.
#		 The full-scale of the ADC is 0-65535 an corresponds to a range of 20V.
#		 ai record:
#		 	ADC Raw counts range of -32767 to +31767 correspond to -10V to +10V
#				with 0V producing 0 counts at the center of the motor stage. The count->V map is linear.
#		 calc record:
#		 	The Volts are converted to mm based on the actual calibration that was done 
#				where 1 Volt potentiometer change resulted due to approximately 5.254 mm motor displacement.
#			Scale and Offset for the linear conversion can be changed but they will be hard-coded 
#				in the soft-ioctuner-boo-rf.substitutions file.
#
# Facility: SPEAR3 Booster RF Tuner Controls
#
# Auth: 28-Oct-2016, S. Condamoor    (SCONDAM)
# Rev:  dd-mmm-yyyy, First Lastname  (USERNAME)
#--------------------------------------------------------------
# % macro, P, record name prefix
# % macro, R, record name 
# % macro, PORT, asyn port for device
# % macro, CH, ADC channel (1 or 2)
# % macro, EGUF, Engineering Units Full
# % macro, EGUL, Engineering Units Low

record(ai, "BOO-RF-TUNER:Cell1PosnVolt")
{
  field("DESC", "B00-RF Cell1 posn in V")
  field("DTYP", "asynInt32")
  field("INP",  "@asyn(AIN0)Ch1Sample.Ch1Value")
  field("SCAN", "I/O Intr")
  field("LINR", "LINEAR")
  field("EGUF", "10")
  field("EGUL", "-10")
  field("EGU",  "V")
  field("FLNK", "BOO-RF-TUNER:Cell1Posn") 
  info(autosaveFields, "EGUF EGUL")	   
}

#
# Convert to a 32-bit integer and convert to floating point.
#	A and B and Alarm Limits will be saved and restored by RDB upon ioc reboot.
#
# % macro, Offset, Offset for V->mm linear conversion
# % macro, Scale,  Slope for V->mm linear conversion
# % macro, high, HIGH Alarm Limit
# % macro, hihi, HIHI Alarm Limit
# % macro, high, HIGH Alarm Limit
# % macro, lolo, LOLO Alarm Limit
# % macro, low,  LOW Alarm Limit

record(calc,"BOO-RF-TUNER:Cell1Posn") {
  	field(DESC, "B00-RF Cell1 posn in mm")
#   field(ASG, "$(security,undefined)ADMIN")	
	field(PREC, "2")
	field(EGU,  "mm")
    field(PINI, "YES")	
	field(HIHI, "35.0")
	field(HIGH, "33.0")
	field(LOLO, "-25.0")
	field(LOW,  "-23.0")
#	field(HYST, "0.1")
	field(HHSV, "MAJOR")
	field(HSV,  "MINOR")
	field(LLSV, "MAJOR")
	field(LSV,  "MINOR")
	field(INPA, "BOO-RF-TUNER:Cell1PosnVolt MS")	
	field(B, 	"-0.02614")
	field(C, 	"5.26936")
	field(CALC, "B+(C*A)")
    field("FLNK", "BOO-RF-TUNER:Cell1PosnCalib")  
    info(autosaveFields, "LOW LOLO HIGH HIHI B C")		
}

#
#   Calculate polynomial: x is raw counts from adc and a-h are polynomial coefficients
#   f = a*x^0 + b*x^1 + c*x^2 + d*x^3 + e*x^4 + f*x^5 + g*x^6 + h*x^7
#
 
record(calc, "BOO-RF-TUNER:Cell1PosnCalib") {
  field(DESC, "B00-RF Cell1 posn in mm")
#  field(ASG, "$(security,undefined)ADMIN")
  field(SCAN, "Passive")
  field(A, "0")
  field(B, "0")
  field(C, "0")
  field(D, "0")
  field(E, "0")
  field(F, "0")
  field(G, "0")
  field(H, "0")
  field(INPL, "BOO-RF-TUNER:Cell1PosnVolt.RVAL")
  field(PREC, "2")
  field(EGU,  "mm")
  field(PINI, "YES")
  field(HHSV, "MAJOR")
  field(LLSV, "MAJOR")
  field(HSV,  "MINOR")
  field(LSV,  "MINOR")
  field(CALC, "A*L^0+B*L^1+C*L^2+D*L^3+E*L^4+F*L^5+G*L^6+H*L^7")  
  info(autosaveFields, "LOW LOLO HIGH HIHI A B C D E F G H")
}

#===============================================================
#
# Abs:  Booster RF Tuner Tuner Potentiometer database
#
# File:tuner_pot.template
#
# Desc:  Booster RF has two tuner motors - 
#			one for moving tuner in Cell1 of the Booster RF cavity
#			and one for moving the tuner in Cell5 of the same cavity 
#        The motors are controlled via two EtherCAT Beckhoff modules EL7041.
#		 The motor position is readback via potentiometers via EtherCAT Beckhoff module EL3702 AI module.
#		 This database reads the raw counts from the potentiometer via an ADC and converts it first to Volts and then to mm.
#		 The full-scale of the ADC is 0-65535 an corresponds to a range of 20V.
#		 ai record:
#		 	ADC Raw counts range of -32767 to +31767 correspond to -10V to +10V
#				with 0V producing 0 counts at the center of the motor stage. The count->V map is linear.
#		 calc record:
#		 	The Volts are converted to mm based on the actual calibration that was done 
#				where 1 Volt potentiometer change resulted due to approximately 5.254 mm motor displacement.
#			Scale and Offset for the linear conversion can be changed but they will be hard-coded 
#				in the soft-ioctuner-boo-rf.substitutions file.
#
# Facility: SPEAR3 Booster RF Tuner Controls
#
# Auth: 28-Oct-2016, S. Condamoor    (SCONDAM)
# Rev:  dd-mmm-yyyy, First Lastname  (USERNAME)
#--------------------------------------------------------------
# % macro, P, record name prefix
# % macro, R, record name 
# % macro, PORT, asyn port for device
# % macro, CH, ADC channel (1 or 2)
# % macro, EGUF, Engineering Units Full
# % macro, EGUL, Engineering Units Low

record(ai, "BOO-RF-TUNER:Cell5PosnVolt")
{
  field("DESC", "B00-RF Cell2 posn in V")
  field("DTYP", "asynInt32")
  field("INP",  "@asyn(AIN0)Ch2Sample.Ch2Value")
  field("SCAN", "I/O Intr")
  field("LINR", "LINEAR")
  field("EGUF", "10")
  field("EGUL", "-10")
  field("EGU",  "V")
  field("FLNK", "BOO-RF-TUNER:Cell5Posn") 
  info(autosaveFields, "EGUF EGUL")	   
}

#
# Convert to a 32-bit integer and convert to floating point.
#	A and B and Alarm Limits will be saved and restored by RDB upon ioc reboot.
#
# % macro, Offset, Offset for V->mm linear conversion
# % macro, Scale,  Slope for V->mm linear conversion
# % macro, high, HIGH Alarm Limit
# % macro, hihi, HIHI Alarm Limit
# % macro, high, HIGH Alarm Limit
# % macro, lolo, LOLO Alarm Limit
# % macro, low,  LOW Alarm Limit

record(calc,"BOO-RF-TUNER:Cell5Posn") {
  	field(DESC, "B00-RF Cell2 posn in mm")
#   field(ASG, "$(security,undefined)ADMIN")	
	field(PREC, "2")
	field(EGU,  "mm")
    field(PINI, "YES")	
	field(HIHI, "16.0")
	field(HIGH, "14.0")
	field(LOLO, "-44.0")
	field(LOW,  "-42.0")
#	field(HYST, "0.1")
	field(HHSV, "MAJOR")
	field(HSV,  "MINOR")
	field(LLSV, "MAJOR")
	field(LSV,  "MINOR")
	field(INPA, "BOO-RF-TUNER:Cell5PosnVolt MS")	
	field(B, 	"-0.02614")
	field(C, 	"5.26936")
	field(CALC, "B+(C*A)")
    field("FLNK", "BOO-RF-TUNER:Cell5PosnCalib")  
    info(autosaveFields, "LOW LOLO HIGH HIHI B C")		
}

#
#   Calculate polynomial: x is raw counts from adc and a-h are polynomial coefficients
#   f = a*x^0 + b*x^1 + c*x^2 + d*x^3 + e*x^4 + f*x^5 + g*x^6 + h*x^7
#
 
record(calc, "BOO-RF-TUNER:Cell5PosnCalib") {
  field(DESC, "B00-RF Cell2 posn in mm")
#  field(ASG, "$(security,undefined)ADMIN")
  field(SCAN, "Passive")
  field(A, "0")
  field(B, "0")
  field(C, "0")
  field(D, "0")
  field(E, "0")
  field(F, "0")
  field(G, "0")
  field(H, "0")
  field(INPL, "BOO-RF-TUNER:Cell5PosnVolt.RVAL")
  field(PREC, "2")
  field(EGU,  "mm")
  field(PINI, "YES")
  field(HHSV, "MAJOR")
  field(LLSV, "MAJOR")
  field(HSV,  "MINOR")
  field(LSV,  "MINOR")
  field(CALC, "A*L^0+B*L^1+C*L^2+D*L^3+E*L^4+F*L^5+G*L^6+H*L^7")  
  info(autosaveFields, "LOW LOLO HIGH HIHI A B C D E F G H")
}

