|
|
|
|
@ -5,12 +5,12 @@
|
|
|
|
|
#include "mcp_adc.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "filter.h"
|
|
|
|
|
#include "offset.h"
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <util/delay.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t timertmp;
|
|
|
|
|
uint16_t temperatures[4];
|
|
|
|
|
|
|
|
|
|
@ -21,9 +21,6 @@ uint16_t temperatures[4];
|
|
|
|
|
* - multiplexer:
|
|
|
|
|
* C3: inhibit
|
|
|
|
|
* C0-C2: muxer select
|
|
|
|
|
* - offset measurement
|
|
|
|
|
* D0-D3 offset compensation
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* amp 0 is on muxer channel 2
|
|
|
|
|
*/
|
|
|
|
|
@ -39,7 +36,6 @@ void hardinit() {
|
|
|
|
|
spi_init();
|
|
|
|
|
|
|
|
|
|
muxer_init();
|
|
|
|
|
offset_measure_init();
|
|
|
|
|
|
|
|
|
|
i2c_init();
|
|
|
|
|
|
|
|
|
|
@ -65,6 +61,8 @@ int __attribute__((noreturn)) main(void) {
|
|
|
|
|
int16_t data;
|
|
|
|
|
for(;;){
|
|
|
|
|
printf("====== loop iteration\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// measure temps 5*2 times
|
|
|
|
|
for(uint8_t i=0; i<5; i++) {
|
|
|
|
|
@ -82,22 +80,21 @@ int __attribute__((noreturn)) main(void) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("====== now measuring offsets\n");
|
|
|
|
|
// measure 2 offsets
|
|
|
|
|
for(uint8_t active_sensor=0; active_sensor<2; active_sensor++) { // only measuring two offsets atm
|
|
|
|
|
printf("=== active sensor: %i\n",active_sensor);
|
|
|
|
|
muxer_set(active_sensor);
|
|
|
|
|
offset_measure_start(active_sensor);
|
|
|
|
|
while(!mcpadc_has_new_data()) _delay_ms(10);
|
|
|
|
|
mcpadc_get_data(); // first data after switch to trash
|
|
|
|
|
while(!mcpadc_has_new_data()) _delay_ms(10);
|
|
|
|
|
|
|
|
|
|
data = mcpadc_get_data();
|
|
|
|
|
printf("retrieved offset data %i\n", data);
|
|
|
|
|
// TODO: what to do with the offset?
|
|
|
|
|
|
|
|
|
|
offset_measure_stop();
|
|
|
|
|
}
|
|
|
|
|
for(uint8_t active_sensor=0; active_sensor<2; active_sensor++)
|
|
|
|
|
if(offset_measure[active_sensor]) {
|
|
|
|
|
printf("=== measuring offset, sensor: %i\n",active_sensor);
|
|
|
|
|
muxer_set(active_sensor);
|
|
|
|
|
while(!mcpadc_has_new_data()) _delay_ms(10);
|
|
|
|
|
mcpadc_get_data(); // first data after switch to trash
|
|
|
|
|
while(!mcpadc_has_new_data()) _delay_ms(10);
|
|
|
|
|
|
|
|
|
|
offset_val[active_sensor] = mcpadc_get_data();
|
|
|
|
|
|
|
|
|
|
while(offset_measure[active_sensor]) {
|
|
|
|
|
offset_val[active_sensor] += mcpadc_get_data();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// measure ambient
|
|
|
|
|
printf("====== now measuring ambient\n");
|
|
|
|
|
|