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
'''
def read_differential(self):
def read_differential(self, rate=0b1001, OSR=8):
#Triggers conversion
self._conversionMode()
time.sleep(0.001)
adc_code = self.readDataRegister()
return self.value_to_voltage(adc_code)
voltage = 0
for i in range(OSR):
self._conversionMode(rate=rate)
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.channel_num_adc = channel_num_adc
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.ITerm = 0
@ -187,10 +187,10 @@ def run(pid_obj, freq, num):
pid_obj.setKd(msg[1])
server.send_string('ACK')
elif msg[0] == 'set_outmax':
pid_obj.setOutmax(msg[1])
pid_obj.setOutmax(float(msg[1]))
server.send_string('ACK')
elif msg[0] == 'set_outmin':
pid_obj.setOutmin(msg[1])
pid_obj.setOutmin(float(msg[1]))
server.send_string('ACK')
elif msg[0] == 'get_setpoint':
#out_queue.put(pid_obj.getSetpoint() )

View File

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