From f925d2c9c53ef4b0308e69a2a043e0d6a7baaedd Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Wed, 14 Nov 2018 11:45:03 +0100 Subject: [PATCH] pt100: new register setting 'multiplex' --- pt100/main.c | 1 + pt100/main.h | 1 + pt100/tempmeas.c | 25 +++++++++++++++---------- pt100/uart.c | 11 ++++++++--- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/pt100/main.c b/pt100/main.c index 0c979fd..8192bb0 100644 --- a/pt100/main.c +++ b/pt100/main.c @@ -46,6 +46,7 @@ void read_calib() { calib_settings.period = eeprom_read(10); calib_settings.uselcd = eeprom_read(11); calib_settings.average = eeprom_read(12); + calib_settings.multiplex = eeprom_read(13); time = 0; } diff --git a/pt100/main.h b/pt100/main.h index db0b10c..bb40a7e 100644 --- a/pt100/main.h +++ b/pt100/main.h @@ -67,4 +67,5 @@ struct calib_t { uint16_t period; //measurement period in timer ticks (2ms) uint16_t uselcd; //set to 0 to disable LCD (0xb) uint16_t average; //how many samples to average (0xc) + uint16_t multiplex; //set to 0 to disable multiplexing the channels (0xd) }; diff --git a/pt100/tempmeas.c b/pt100/tempmeas.c index fdaaa40..808763d 100644 --- a/pt100/tempmeas.c +++ b/pt100/tempmeas.c @@ -45,7 +45,7 @@ int32_t res_to_temp(int16_t res) { void set_inhibit_signals(int on_off) { // PORTC = (PORTC & 0x3F) | (on_off << 6); - if(on_off == 0) { + if ((on_off == 0) || (calib_settings.multiplex == 0)) { MUX_C_ON(); MUX_T_ON(); } @@ -56,15 +56,20 @@ void set_inhibit_signals(int on_off) { } void select_channel(void) { - if (current_channel == 8) { - // temperature measurement - set_inhibit_signals(0); + if (calib_settings.multiplex == 0) { + PORTA = (PORTA & 0x8F) | (0x00 << 4); } else { - // update the select outputs - PORTA = (PORTA & 0x8F) | (current_channel << 4); - // clear inhibit signals - set_inhibit_signals(0); + if (current_channel == 8) { + // temperature measurement + set_inhibit_signals(0); + } + else { + // update the select outputs + PORTA = (PORTA & 0x8F) | (current_channel << 4); + // clear inhibit signals + set_inhibit_signals(0); + } } } @@ -140,13 +145,13 @@ void do_measurement_step(void) { con = ADCL; con += (ADCH<<8); - if (con < connect_threshold) { + if (con < connect_threshold || calib_settings.multiplex == 0) { adc_result = SPI_transceive_16bit(conf_register); } } else if(measurement_step < (CONNECTED_SENSORS*4) && (measurement_step & 0x3) == 0x3) { set_inhibit_signals(1); - if (con < connect_threshold) { + if (con < connect_threshold || calib_settings.multiplex == 0) { // read value adc_result += SPI_transceive_16bit(0x0000); adc_result /= 2; diff --git a/pt100/uart.c b/pt100/uart.c index 029cb33..caa0077 100644 --- a/pt100/uart.c +++ b/pt100/uart.c @@ -26,7 +26,8 @@ #define ISMYADDR() (rxbuf[2] == '0') uint8_t rxcnt = 0, txpoint = 0; -volatile uint8_t txcnt = 0; +volatile uint8_t txcnt = 0; +volatile uint8_t busy = 0; uint8_t rxbuf[15]; uint8_t txbuf[15]; @@ -53,7 +54,9 @@ void forward_msg(uint8_t i) { if(rxbuf[0] == 'A') rxbuf[2]++; else rxbuf[2]--; sei(); - while(TX_BUSY()); + while (TX_BUSY()) {}; + while (busy == 1) {}; + busy = 1; memcpy ((uint8_t*)txbuf,(uint8_t*)rxbuf,i); STARTTX(i); } @@ -71,6 +74,8 @@ uint8_t is_my_address(uint8_t s) { void send_answer_hex(uint8_t type, uint8_t chan, uint32_t v) { sei(); + while (busy == 1) {}; + busy = 1; while(TX_BUSY()); txbuf[0]='A'; txbuf[1]=type; @@ -155,6 +160,6 @@ ISR(USART0_UDRE_vect) { txpoint = 0; txcnt = 0; UCSR0B &= ~(1<< UDRIE0); - + busy = 0; } } \ No newline at end of file -- 2.43.0