]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
added functions for converting adc to resistance and resistance to temperature
authorJan Michel <j.michel@gsi.de>
Wed, 5 Aug 2015 15:44:31 +0000 (17:44 +0200)
committerJan Michel <j.michel@gsi.de>
Wed, 5 Aug 2015 15:44:31 +0000 (17:44 +0200)
pt100/main.c
pt100/main.h
pt100/tempmeas.c

index 791f638433151f899c02a6073dfacbba8e269b00..e54de4da947cc9196ecc0382a31e72876efda70c 100644 (file)
@@ -33,7 +33,7 @@ void read_calib() {
     calib_settings.offset_res[i] = eeprom_read(i);
     }
   calib_settings.nominal_offset = eeprom_read(8);  
-  calib_settings.gain_current   = eeprom_read(10)<<16 | eeprom_read(9);
+  calib_settings.gain_current   = eeprom_read(9);
   }
 
 /******************
index e2a63a21e9b00bb2948660832b0a589b1ae5f34b..dda6c1b2be0b81ef50195d7b9599d52dfb695f09 100644 (file)
@@ -50,9 +50,10 @@ extern volatile uint8_t keys_pressed;
 extern uint8_t  connected_sensors;
 extern volatile uint16_t time;
 extern volatile uint8_t  measurement_active;
+extern struct calib_t calib_settings;
 
 struct calib_t {
   uint16_t    offset_res[8];        //precise offset in Milliohm minus nominal value
   uint16_t    nominal_offset;       //approximate offset resistor, in Ohm, 100 as default
-  uint32_t    gain_current;         //gain times current in nA (about 20E6)
+  uint16_t    gain_current;         //2^29 / (gain * current[uA])  (about 53700)
   };
index c4affefc9dc136a572e40470d24a6e1c5a70d560..72decf0fd83857a83363ac2c7b948cf8d5f10a46 100644 (file)
@@ -4,6 +4,39 @@
 uint8_t connected_sensors = 0x1a;
 uint8_t measurement_step;
 
+
+//factors: gain_current has 2^29, ADC has 2^7 steps per mV
+//hence shift by 36 necessary, 6 as part of multiplication by 1E6
+int16_t adc_to_res(int16_t adc, uint8_t chan) {
+  int32_t value;
+  value = (int32_t)adc * (uint32_t)calib_settings.gain_current;
+  value >>= 14;
+  value *= 15625;
+  value >>= 16;
+  value += calib_settings.offset_res[chan];
+  return (int16_t)value;
+  }
+
+  
+//T = -1 + 41919 * 2^-14 * R + 135 * 2^-27 * R^2
+//units in mOhm, mK
+
+int32_t res_to_temp(int16_t res) {
+  int32_t result = -1;
+  int32_t t = (int32_t)res * 41919;
+  result += t >> 14;
+  
+  t = (int32_t)res * res;
+  t >>= 7;
+  t *= 135;
+  result += t >> 20;
+  
+  return result;
+  }
+
+
+  
+  
 //measurement_active gets set once per second
 //do_measurement_step is called once every 2ms by main as long as measurement_active is set.
 //'measurement_step' gives the number of the current step