Explorar el Código

Исправил вычисления АЦП.

Vladimir N. Shilov hace 8 años
padre
commit
49b995e4f2
Se han modificado 1 ficheros con 21 adiciones y 11 borrados
  1. 21 11
      lib/adc.c

+ 21 - 11
lib/adc.c

@@ -27,16 +27,26 @@
 #define ADC1_DR_ADDRESS     ((uint16_t)0x5344)
 #define ADC_BUFFER_ADDRESS  ((uint16_t)(&ADC_Buffer))
 
-#define ADC_REF             3300
-// 4095 * 20 (Ку ОУ) * 0.01 (Rш)
-#define ADC_DIV             819
-// 32760 * 20 (Ку ОУ) * 0.01 (Rш)
-#define ADC_ODIV            6552
-#define ADC_DIV_H           410
-#define ADC_ODIV_H          3276
-#define ADC_VOLT_K          11
+// Suply voltage
+#define ADC_REF             3305
+// Normal K for current channel = 4095 * 20 (Ку ОУ) * 0.01 (Rш)
+#define ADC_CURR_DIV        819
+#define ADC_CURR_DIV_H      410
+// Oversampl K for current channel = 32760 * 20 (Ку ОУ) * 0.01 (Rш)
+#define ADC_CURR_ODIV       6552
+#define ADC_CURR_ODIV_H     3276
+// Curren amplifier multiplier
 #define ADC_CURR_K          20
-#define ADC_CURR_SH         100
+// Current shunt resistance in miliOhms
+#define ADC_CURR_SH         10
+// Input Voltage divider
+#define ADC_VOLT_K          11
+// ADC resolution 12 bit
+#define ADC_DIV             4095
+#define ADC_DIV_H           2048
+// ADC oversampled resolution 15 bit
+#define ADC_ODIV            32760
+#define ADC_ODIV_H          16380
 
 // (Частота МК (16 МHz) / Предделитель таймера (8) * Нужное время в секундах (0.0015625)) - 1
 #define TIM_PERIOD          ((uint16_t)3128)
@@ -239,8 +249,8 @@ uint16_t * ADC_GetValues(void) {
   curr += 4;
   curr /= 8;
   curr *= ADC_REF;
-  curr += ADC_ODIV_H; // для округления
-  curr /= ADC_ODIV; // делим на К
+  curr += ADC_CURR_ODIV_H; // для округления
+  curr /= ADC_CURR_ODIV; // делим на К
 
   /* так как шунт стоит в разрыве земли до выхода из БП
      компенсируем падение напряжения на нём. */