pt100: new register setting 'multiplex'
authorPhilipp Klaus <philipp.l.klaus@web.de>
Wed, 14 Nov 2018 10:45:03 +0000 (11:45 +0100)
committerPhilipp Klaus <philipp.l.klaus@web.de>
Wed, 14 Nov 2018 10:45:03 +0000 (11:45 +0100)
pt100/main.c
pt100/main.h
pt100/tempmeas.c
pt100/uart.c

index 0c979fd6dba5dc7a98cee780836bd0e74ab67da7..8192bb0420c744a1ff377a747fb50151b49b4275 100644 (file)
@@ -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;
   }
 
index db0b10c74da87bc8a7b9a11ce1165c97890ad13f..bb40a7e659a0ac2bd6fd40e3f4e853f8db878588 100644 (file)
@@ -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)
   };
index fdaaa40d4cb8ba23dfceedeb06255c6c71783e60..808763d37bf0dd517fb53fe6616abcf72b7488ff 100644 (file)
@@ -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;
index 029cb333fff764600db81cfc1d714febf208cc45..caa0077b2ab1b501f8ed845c0634b95c5315c652 100644 (file)
@@ -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