Jelajahi Sumber

add:添加原始adc值

Dozingfiretruck 3 tahun lalu
induk
melakukan
730742654d
3 mengubah file dengan 13 tambahan dan 11 penghapusan
  1. 9 8
      app/port/luat_adc_air101.c
  2. 1 1
      include/driver/wm_adc.h
  3. 3 2
      platform/drivers/adc/wm_adc.c

+ 9 - 8
app/port/luat_adc_air101.c

@@ -42,27 +42,28 @@ int luat_adc_read(int ch, int *val, int *val2)
     switch (ch)
     {
     case 0:
-        voltage = adc_get_inputVolt(ch);
+        voltage = adc_get_inputVolt(ch, val);
         break;
     case 1:
-        voltage = adc_get_inputVolt(ch);
+        voltage = adc_get_inputVolt(ch, val);
         break;
     case 2:
-        voltage = adc_get_inputVolt(ch);
+        voltage = adc_get_inputVolt(ch, val);
         break;
     case 3:
-        voltage = adc_get_inputVolt(ch);
+        voltage = adc_get_inputVolt(ch, val);
         break;
     case 10:
         voltage = adc_temp();
+        *val = voltage;
         return 0;
     case 11:
         voltage = adc_get_interVolt();
+        *val = voltage;
         return 0;
     default:
         return 1;
     }
-    *val = voltage;
     *val2 = voltage;
     if (*val < 46134) {
         *val2 = 0;
@@ -70,9 +71,9 @@ int luat_adc_read(int ch, int *val, int *val2)
     else if (*val > 123405) {
         *val2 = 2300;
     }
-    else {
-        *val2 = (int)((double)(*val - 46134) / (double)(32.196));
-    }
+    // else {
+    //     *val2 = (int)((double)(*val - 46134) / (double)(32.196));
+    // }
     return 0;
 }
 

+ 1 - 1
include/driver/wm_adc.h

@@ -270,7 +270,7 @@ int adc_get_interTemp(void);
  *
  * @note            None
  */
-int adc_get_inputVolt(u8 channel);
+int adc_get_inputVolt(u8 channel, int* origin);
 
 /**
  * @brief           This function is used to read internal voltage.

+ 3 - 2
platform/drivers/adc/wm_adc.c

@@ -526,7 +526,7 @@ int adc_get_interTemp(void)
 	return adc_temp();
 }
 
-int adc_get_inputVolt(u8 channel)
+int adc_get_inputVolt(u8 channel, int* origin)
 {
 	int average = 0;
 	double voltage = 0.0;
@@ -544,7 +544,8 @@ int adc_get_inputVolt(u8 channel)
 
 	waitForAdcDone();
 	average = tls_read_adc_result();
-	signedToUnsignedData(&average); 	
+	signedToUnsignedData(&average);
+	*origin = average; 	
 	tls_adc_stop(0);
 
 	if ((channel == 8) || (channel == 9))