Finetuning ADC performance and bugfix for PID

This commit is contained in:
Elena Arenskötter 2023-11-04 13:51:51 +01:00
parent e596c12a7b
commit 6d10c0d7f5
4 changed files with 24 additions and 14 deletions

View File

@ -464,11 +464,14 @@ class MAX11270:
''' '''
Read ADC value in differential mode Read ADC value in differential mode
''' '''
def read_differential(self): def read_differential(self, rate=0b1001, OSR=8):
#Triggers conversion #Triggers conversion
self._conversionMode() voltage = 0
time.sleep(0.001) for i in range(OSR):
adc_code = self.readDataRegister() self._conversionMode(rate=rate)
return self.value_to_voltage(adc_code) time.sleep(0.01)
adc_code = self.readDataRegister()
voltage = voltage + self.value_to_voltage(adc_code)
return(voltage/OSR)

View File

@ -34,7 +34,7 @@ class PID:
self.dev_num_adc = dev_num_adc self.dev_num_adc = dev_num_adc
self.channel_num_adc = channel_num_adc self.channel_num_adc = channel_num_adc
self.dev_num_dac = dev_num_dac self.dev_num_dac = dev_num_dac
self.channel_dac = channel_num_dac self.channel_num_dac = channel_num_dac
self.pid_num = pid_num self.pid_num = pid_num
self.ITerm = 0 self.ITerm = 0
@ -187,10 +187,10 @@ def run(pid_obj, freq, num):
pid_obj.setKd(msg[1]) pid_obj.setKd(msg[1])
server.send_string('ACK') server.send_string('ACK')
elif msg[0] == 'set_outmax': elif msg[0] == 'set_outmax':
pid_obj.setOutmax(msg[1]) pid_obj.setOutmax(float(msg[1]))
server.send_string('ACK') server.send_string('ACK')
elif msg[0] == 'set_outmin': elif msg[0] == 'set_outmin':
pid_obj.setOutmin(msg[1]) pid_obj.setOutmin(float(msg[1]))
server.send_string('ACK') server.send_string('ACK')
elif msg[0] == 'get_setpoint': elif msg[0] == 'get_setpoint':
#out_queue.put(pid_obj.getSetpoint() ) #out_queue.put(pid_obj.getSetpoint() )

View File

@ -47,15 +47,22 @@ def adc2T(dU):
myADC = MAX11270.MAX11270(21,20,19,17,27,22) myADC = MAX11270.MAX11270(21,20,19,17,27,22)
myDAC = MCP4822.MCP4822(11, 10, 8, 5) myDAC = MCP4822.MCP4822(11, 10, 8, 5)
#myDAC.write(0,1) myDAC.write(1.29,1)
#myDAC.write(0,0) #myDAC.write(0,0)
print('-Status-') print('-Status-')
print(myADC.readStatusRegister(1)) print(bin(myADC.readStatusRegister(1)))
print(bin(myADC.rate))
myADC.setConversion('continous')
#myADC.performCalibration('offsetCalibration') #myADC.performCalibration('offsetCalibration')
#print(myADC.readStatusRegister(1)) #print(myADC.readStatusRegister(1))
print('--------Readout ADC value ---------') print('--------Readout ADC value ---------')
for i in range(0,100): for i in range(0,100):
#print(myADC.read_differential())
print(adc2T(myADC.read_differential())) print(adc2T(myADC.read_differential()))
time.sleep(10)
myADC.readStatusRegister(1)
print(bin(myADC.rate))
time.sleep(1)

View File

@ -3,6 +3,6 @@ import time
myDAC = MCP4822.MCP4822(11, 10, 8, 5) myDAC = MCP4822.MCP4822(11, 10, 8, 5)
myDAC.write(1,0) myDAC.write(1,0)
myDAC.write(0,1) myDAC.write(1,1)
#time.sleep(10) time.sleep(10)