|
|
|
|
@ -3,8 +3,8 @@
|
|
|
|
|
#include "muxer.h"
|
|
|
|
|
#include "i2c_simple.h"
|
|
|
|
|
#include "mcp_adc.h"
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "math.h"
|
|
|
|
|
|
|
|
|
|
uint16_t timertmp;
|
|
|
|
|
uint16_t temperatures[4];
|
|
|
|
|
@ -30,8 +30,61 @@ int16_t temp_avg_count[4];
|
|
|
|
|
#define MUXER_CHANNEL_3 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t calc_temp(uint16_t val) {
|
|
|
|
|
// TODO: implement polygon ... wait, no, polyester, uh, no again? ... poly-thingy?
|
|
|
|
|
int32_t avg_temp(int16_t val, uint8_t channel) {
|
|
|
|
|
int32_t temp = temp_avg_cumul[channel];
|
|
|
|
|
temp /= temp_avg_count[channel];
|
|
|
|
|
temp_avg_count[channel] = 0;
|
|
|
|
|
temp_avg_cumul[channel] = 0;
|
|
|
|
|
return (temp * 625); // nV
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t calc_temp(int16_t val, uint8_t channel) {
|
|
|
|
|
float mV = ((float) avg_temp(val, channel))/1000000;
|
|
|
|
|
uint16_t temp;
|
|
|
|
|
if(mV < 0) {
|
|
|
|
|
/* t in mV
|
|
|
|
|
E = sum(i=0 to n) c_i t^i. ; n=10
|
|
|
|
|
*/
|
|
|
|
|
float coef[] = {
|
|
|
|
|
0.000000000000E+00,
|
|
|
|
|
0.394501280250E-01,
|
|
|
|
|
0.236223735980E-04,
|
|
|
|
|
-0.328589067840E-06,
|
|
|
|
|
-0.499048287770E-08,
|
|
|
|
|
-0.675090591730E-10,
|
|
|
|
|
-0.574103274280E-12,
|
|
|
|
|
-0.310888728940E-14,
|
|
|
|
|
-0.104516093650E-16,
|
|
|
|
|
-0.198892668780E-19,
|
|
|
|
|
-0.163226974860E-22
|
|
|
|
|
};
|
|
|
|
|
for(int i=0; i<11; i++) {
|
|
|
|
|
temp += coef[i] * pow(mV, i+1);
|
|
|
|
|
}
|
|
|
|
|
return temp;
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
t in mV
|
|
|
|
|
E = sum(i=0 to n) c_i t^i + a0 exp(a1 (t - a2)^2). ; n = 9
|
|
|
|
|
*/
|
|
|
|
|
float coef[] = {
|
|
|
|
|
-0.176004136860E-01,
|
|
|
|
|
0.389212049750E-01,
|
|
|
|
|
0.185587700320E-04,
|
|
|
|
|
-0.994575928740E-07,
|
|
|
|
|
0.318409457190E-09,
|
|
|
|
|
-0.560728448890E-12,
|
|
|
|
|
0.560750590590E-15,
|
|
|
|
|
-0.320207200030E-18,
|
|
|
|
|
0.971511471520E-22,
|
|
|
|
|
-0.121047212750E-25
|
|
|
|
|
};
|
|
|
|
|
float a[] = {0.118597600000E+00, -0.118343200000E-03, 0.126968600000E+03};
|
|
|
|
|
for(int i=0; i<10; i++) {
|
|
|
|
|
temp += coef[i]*pow(mV, i+1) + a[0] * pow(exp(a[1]*(mV - a[2])), 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* initializes the hardware */
|
|
|
|
|
@ -65,7 +118,7 @@ int __attribute__((noreturn)) main(void) {
|
|
|
|
|
SOFTTIMER(1,10) {
|
|
|
|
|
for(int i=0; i<4; i++) {
|
|
|
|
|
if(sensor_active[i] && mcpadc_has_new_data(i)) {
|
|
|
|
|
temperatures[i] = calc_temp( mcpadc_get_data(i) );
|
|
|
|
|
temperatures[i] = calc_temp( mcpadc_get_data(i), i );
|
|
|
|
|
temp_avg_cumul[i] += temperatures[i];
|
|
|
|
|
temp_avg_count[i] += 1;
|
|
|
|
|
}
|
|
|
|
|
|