]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
pt100: compile errors fixed
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Fri, 7 Aug 2015 07:01:31 +0000 (09:01 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Fri, 7 Aug 2015 07:01:31 +0000 (09:01 +0200)
pt100/main.h
pt100/tempmeas.c
pt100/uart.c

index dda6c1b2be0b81ef50195d7b9599d52dfb695f09..6fed2214a027e732e67675e1b67cee54c9a25603 100644 (file)
@@ -47,7 +47,7 @@ void do_measurement_step(void);
 
 extern volatile uint16_t control_reg;
 extern volatile uint8_t keys_pressed;
-extern uint8_t  connected_sensors;
+extern uint8_t  num_connected_sensors;
 extern volatile uint16_t time;
 extern volatile uint8_t  measurement_active;
 extern struct calib_t calib_settings;
index 93d93d34e8361553bc16cc9dad9a9cdfc9f85ee1..ab1625693d835ddce90b4f8c25609fb3fbbc243a 100644 (file)
@@ -5,7 +5,7 @@
 
 uint8_t measurement_step;
 uint8_t current_channel = 0;
-
+uint8_t num_connected_sensors = 8;
 
 //factors: gain_current has 2^29, ADC has 2^7 steps per mV
 //hence shift by 36 necessary, 6 as part of multiplication by 1E6
@@ -39,7 +39,38 @@ int32_t res_to_temp(int16_t res) {
   return result;
   }
 
+void set_inhibit_signals(int on_off) {
+  PORTC = (PORTC & 0x3F) | (on_off << 6);
+  }
+
+void select_channel(void) {
+  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);
+    }
+  }
 
+
+
+char SPI_transceive(unsigned char cData){
+  SPDR = cData;
+  while (!(SPSR & (1<<SPIF)))
+    ;
+  return SPDR;
+  }
+
+uint16_t SPI_transceive_16bit(uint16_t data){
+  char high, low;
+  high = SPI_transceive(data>>8);
+  low = SPI_transceive(data&0xFF);
+  return (high << 8) | low;
+  }
   
   
 //measurement_active gets set once per second
@@ -65,18 +96,18 @@ int32_t res_to_temp(int16_t res) {
 //35 send ADC temperature
  
 void do_measurement_step(void) {
-  if(measurement_step < (CONNECTED_SENSORS*4) && measurement_step & 0x3 == 0x0) {
+  if(measurement_step < (CONNECTED_SENSORS*4) && (measurement_step & 0x3) == 0x0) {
     LED1_ON();
     select_channel();
     }
-  else if(measurement_step < (CONNECTED_SENSORS*4) && measurement_step & 0x3 == 0x1) {
+  else if(measurement_step < (CONNECTED_SENSORS*4) && (measurement_step & 0x3) == 0x1) {
     ADCSRA |= (1<<ADSC); //start ADC conversion
     uint16_t conf_register = (ADS_MODE_S | ADS_GAIN_025V |
         ADS_SConv | ADS_WRITE_CONFIG | ADS_PULLUP_DRDY | ADS_1600SPS);
     conf_register |= ADS_MUX_AIN0_AIN3;
     SPI_transceive_16bit(conf_register);
     }
-  else if(measurement_step < (CONNECTED_SENSORS*4) && measurement_step & 0x3 == 0x2) {
+  else if(measurement_step < (CONNECTED_SENSORS*4) && (measurement_step & 0x3) == 0x2) {
     set_inhibit_signals(1);
     uint16_t x;
     // read on / off
@@ -89,51 +120,23 @@ void do_measurement_step(void) {
     if (x < 58112) {
       // read value
       x = SPI_transceive_16bit(0x0000);
-      x = res_to_temp(adc_to_res(x));
-      void send_answer_hex(0, 0, x);
+      x = res_to_temp(adc_to_res(x, current_channel));
+      send_answer_hex(0, 0, x);
       }
     else {
-      void send_answer_hex(0, 0, (1<< (5*4)));
+      num_connected_sensors = 8;
+      uint32_t nc_msg = 0x100000;
+      send_answer_hex(0, 0, nc_msg);
       }
-  else if(measurement_step < (CONNECTED_SENSORS*4) && measurement_step & 0x3 == 0x3) {
-    selected_channel += 1;
+    }
+  else if(measurement_step < (CONNECTED_SENSORS*4) && (measurement_step & 0x3) == 0x3) {
+    current_channel += 1;
     }
   measurement_step += 1;
   if(measurement_step == 36)
     measurement_step = 0;
-    selected_channel = 0
+    current_channel = 0;
     LED1_OFF();
     measurement_active = 0;
   }
 
-
-void set_inhibit_signals(int on_off) {
-  PORTC = (PORTC & 0x3F) | (on_off << 6);
-  }
-
-void select_channel() {
-  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);
-    }
-  }
-
-uint16_t SPI_transceive_16bit(uint16_t data){
-  char high, low;
-  high = SPI_transceive(data>>8);
-  low = SPI_transceive(data&0xFF);
-  return (high << 8) | low;
-  }
-
-char SPI_transceive(unsigned char cData){
-  SPDR = cData;
-  while (!(SPSR & (1<<SPIF)))
-    ;
-  return SPDR;
-  }
\ No newline at end of file
index 0df6c0b18acade163b7730045fa52c367f84a3a0..77a6e993953098522f049e6700cdd6d9faf9a913 100644 (file)
@@ -93,8 +93,8 @@ void send_information(void) {
   txbuf[5]=nib_to_hex(FIRMWARE_VERSION,2);
   txbuf[6]=nib_to_hex(FIRMWARE_VERSION,1);
   txbuf[7]=nib_to_hex(FIRMWARE_VERSION,0);
-  txbuf[8]=nib_to_hex(connected_sensors,1);
-  txbuf[9]=nib_to_hex(connected_sensors,0);
+  txbuf[8]=nib_to_hex(num_connected_sensors,1);
+  txbuf[9]=nib_to_hex(num_connected_sensors,0);
   txbuf[10]='\n';
   STARTTX(11);  
   }