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);
}
/******************
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)
};
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