maybe fixed main

master
Dario Ernst 15 years ago
parent 88d4d3a4bd
commit b0907aae44

@ -6,6 +6,7 @@
#include "debug.h" #include "debug.h"
#include <math.h> #include <math.h>
#include "filter.h" #include "filter.h"
#include <util/delay.h>
uint16_t timertmp; uint16_t timertmp;
uint16_t temperatures[4]; uint16_t temperatures[4];
@ -54,53 +55,95 @@ int __attribute__((noreturn)) main(void) {
muxer_set(1); muxer_set(1);
uint8_t active_sensor = 0; uint8_t active_sensor = 0;
int16_t data;
for(;;){ for(;;){
SOFTTIMER(1,10) { // measure temps 5*2 times
if(mcpadc_has_new_data()) { for(int i=0; i<5; i++) {
int16_t data = mcpadc_get_data(); for(int active_sensor=0; active_sensor<2; active_sensor++) { // only measuring two probes atm
float f = filter_voltage_to_temp( muxer_set(active_sensor);
((float)data) * 0.000625 ); while(!mcpadc_has_new_data()) _delay_ms(1);
// total gain is 100 (50 from INA, 2 from ADC) mcpadc_get_data(); // first data after switch to trash
// full signed range on ADC is +-2.048V while(!mcpadc_has_new_data()) _delay_ms(1);
// with 16bit, 1LSB is worth 0.0625mV
// with the gain added in that's 0.000625mV
data = mcpadc_get_data();
float f = filter_voltage_to_temp(((float)data) * 0.000625 );
filter_average_input(active_sensor, f); filter_average_input(active_sensor, f);
if(filter_average_done(active_sensor,16)){ if(filter_average_done(active_sensor,16)){
float noise = filter_average_noise(active_sensor); filter_average_noise(active_sensor);
float temp = filter_average_result(active_sensor); temperatures[active_sensor] = filter_average_result(active_sensor);
dbgLog("temp: %3.3f°C (lastval %i), noise: %e\n",temp, data, noise);
} }
} }
} }
/* SOFTTIMER(2,500){ // measure 2 offsets
for(int i=0; i<4; i++) { for(int active_sensor=0; active_sensor<2; active_sensor++) { // only measuring two offsets atm
if(sensor_active[i]) { muxer_set(active_sensor);
int32_t temp = temp_avg_cumul[i]; offset_measure_start(active_sensor);
temp /= temp_avg_count[i]; while(!mcpadc_has_new_data()) _delay_ms(1);
temp_avg_count[i] = 0; temp_avg_cumul[i] = 0; mcpadc_get_data(); // first data after switch to trash
int32_t nV = (temp * 625); while(!mcpadc_has_new_data()) _delay_ms(1);
int32_t mK = nV/39;
dbgLog("temp-%i: %6li (%li µV, %li mK)\n",i,temp,nV/1000, mK); data = mcpadc_get_data();
} // TODO: what to do with the offset?
}
}
*/
SOFTTIMER(3,4000){
static uint8_t toggle;
if(toggle){
offset_measure_start(1);
toggle=0;
dbgLog("measuring offset\n");
} else {
offset_measure_stop(); offset_measure_stop();
toggle=1;
dbgLog("stopping offset-measuring\n");
} }
SOFTTIMER(1,8000) { // maybe measure coldjunction comp
muxer_set(23); // TODO: channel for ntc?!
// first measure ntc offset?! maybe?
offset_measure_start(active_sensor);
while(!mcpadc_has_new_data()) _delay_ms(1);
mcpadc_get_data(); // first data after switch to trash
while(!mcpadc_has_new_data()) _delay_ms(1);
data = mcpadc_get_data();
offset_measure_stop();
// now measure temp-data
while(!mcpadc_has_new_data()) _delay_ms(1);
mcpadc_get_data(); // first data after switch to trash
while(!mcpadc_has_new_data()) _delay_ms(1);
data = mcpadc_get_data();
} }
/* SOFTTIMER(1,10) { */
/* if(mcpadc_has_new_data()) { */
/* int16_t data = mcpadc_get_data(); */
/* float f = filter_voltage_to_temp( */
/* ((float)data) * 0.000625 ); */
/* // total gain is 100 (50 from INA, 2 from ADC) */
/* // full signed range on ADC is +-2.048V */
/* // with 16bit, 1LSB is worth 0.0625mV */
/* // with the gain added in that's 0.000625mV */
/* filter_average_input(active_sensor, f); */
/* if(filter_average_done(active_sensor,16)){ */
/* float noise = filter_average_noise(active_sensor); */
/* float temp = filter_average_result(active_sensor); */
/* dbgLog("temp: %3.3f°C (lastval %i), noise: %e\n",temp, data, noise); */
/* } */
/* } */
/* } */
/* SOFTTIMER(3,4000){ */
/* static uint8_t toggle; */
/* if(toggle){ */
/* offset_measure_start(1); */
/* toggle=0; */
/* dbgLog("measuring offset\n"); */
/* } else { */
/* offset_measure_stop(); */
/* toggle=1; */
/* dbgLog("stopping offset-measuring\n"); */
/* } */
/* } */
} }
} }

Loading…
Cancel
Save