|
|
|
|
@ -6,18 +6,11 @@
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
|
uint8_t foo;
|
|
|
|
|
uint16_t bar;
|
|
|
|
|
uint16_t timertmp;
|
|
|
|
|
uint16_t temperatures[4];
|
|
|
|
|
|
|
|
|
|
int32_t temp_avg_cumul;
|
|
|
|
|
int16_t temp_avg_count;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void baz() {
|
|
|
|
|
foo++;
|
|
|
|
|
}
|
|
|
|
|
uint8_t sensor_active[4];
|
|
|
|
|
int32_t temp_avg_cumul[4];
|
|
|
|
|
int16_t temp_avg_count[4];
|
|
|
|
|
|
|
|
|
|
/* pinout
|
|
|
|
|
* - i2c:
|
|
|
|
|
@ -36,9 +29,8 @@ void baz() {
|
|
|
|
|
#define MUXER_CHANNEL_2 1
|
|
|
|
|
#define MUXER_CHANNEL_3 3
|
|
|
|
|
|
|
|
|
|
/* initializes the hardware */
|
|
|
|
|
void hardinit() {
|
|
|
|
|
/* initializes the hardware */
|
|
|
|
|
|
|
|
|
|
// enable softtimer isr
|
|
|
|
|
TCCR1A = _BV(WGM10);
|
|
|
|
|
TCCR1B = _BV(WGM12) | _BV(CS11); // clk/8 prescaler, 4kHz PWM-freq.
|
|
|
|
|
@ -47,53 +39,45 @@ void hardinit() {
|
|
|
|
|
spi_init();
|
|
|
|
|
|
|
|
|
|
muxer_init();
|
|
|
|
|
|
|
|
|
|
i2c_init();
|
|
|
|
|
|
|
|
|
|
sei();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void softinit() {
|
|
|
|
|
|
|
|
|
|
//test values
|
|
|
|
|
foo = 0x87;
|
|
|
|
|
bar= 0xfafa;
|
|
|
|
|
|
|
|
|
|
mcpadc_init(ADC_GAIN_2|ADC_CONV_CONT|ADC_BITS_16);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int __attribute__((noreturn)) main(void) {
|
|
|
|
|
temperatures[2]=1;
|
|
|
|
|
hardinit();
|
|
|
|
|
temperatures[2]=10;
|
|
|
|
|
softinit();
|
|
|
|
|
|
|
|
|
|
muxer_set(MUXER_CHANNEL_0);
|
|
|
|
|
temperatures[2]=0;
|
|
|
|
|
dbgLog("Hallo, Welt!\n");
|
|
|
|
|
|
|
|
|
|
for(;;){
|
|
|
|
|
|
|
|
|
|
SOFTTIMER(1,10) {
|
|
|
|
|
if(mcpadc_has_new_data()) {
|
|
|
|
|
temperatures[0] = mcpadc_get_data();
|
|
|
|
|
temperatures[2]++;
|
|
|
|
|
int16_t temp = temperatures[0];
|
|
|
|
|
temp_avg_cumul += temp;
|
|
|
|
|
temp_avg_count += 1;
|
|
|
|
|
}
|
|
|
|
|
temperatures[1] = 22;
|
|
|
|
|
for(int i=0; i<4; i++) {
|
|
|
|
|
if(sensor_active[i] && mcpadc_has_new_data(i)) {
|
|
|
|
|
temperatures[i] = mcpadc_get_data(i);
|
|
|
|
|
temp_avg_cumul[i] += temperatures[i];
|
|
|
|
|
temp_avg_count[i] += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SOFTTIMER(2,500){
|
|
|
|
|
int32_t temp = temp_avg_cumul;
|
|
|
|
|
temp /= temp_avg_count;
|
|
|
|
|
temp_avg_count = 0; temp_avg_cumul = 0;
|
|
|
|
|
int32_t nV = (temp * 625);
|
|
|
|
|
int32_t mK = nV/39;
|
|
|
|
|
|
|
|
|
|
dbgLog("temp: %6li (%li µV, %li mK)\n",temp,nV/1000, mK);
|
|
|
|
|
SOFTTIMER(2,500){
|
|
|
|
|
for(int i=0; i<4; i++) {
|
|
|
|
|
if(sensor_active[i]) {
|
|
|
|
|
int32_t temp = temp_avg_cumul[i];
|
|
|
|
|
temp /= temp_avg_count[i];
|
|
|
|
|
temp_avg_count[i] = 0; temp_avg_cumul[i] = 0;
|
|
|
|
|
int32_t nV = (temp * 625);
|
|
|
|
|
int32_t mK = nV/39;
|
|
|
|
|
dbgLog("temp-%i: %6li (%li µV, %li mK)\n",i,temp,nV/1000, mK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|