Vladimir N. Shilov 5 anos atrás
pai
commit
83428ce190
3 arquivos alterados com 21 adições e 5 exclusões
  1. 7 0
      ReadMe.txt
  2. 13 4
      lib/ina219.c
  3. 1 1
      src/main.c

+ 7 - 0
ReadMe.txt

@@ -22,3 +22,10 @@
 ---
 ---
 2019.07.10
 2019.07.10
 Запустил I2C, INA219, RTOS.
 Запустил I2C, INA219, RTOS.
+---
+2019.07.11
+Исправил вычисления тока и мощности - 8 бит накладывают свои ограничения.
+нужно сделать отображение напряжения с шунта -Sh-
+нужно вернуть calculateValues
+попробовать ещё усреднять значения (3 раза за 250 мсек - 68.1 период измерения)
+ненулевой холостой ток...

+ 13 - 4
lib/ina219.c

@@ -101,7 +101,7 @@ uint32_t getMaxPower(void) {
 
 
 /** */
 /** */
 uint16_t readBusCurrent(void) {
 uint16_t readBusCurrent(void) {
-  uint16_t current;
+  uint32_t current;;
   int16_t tmp;
   int16_t tmp;
 
 
   status = i2c_rd_reg(INA219_ADDRESS, INA219_REG_CURRENT, (uint16_t *)&tmp);
   status = i2c_rd_reg(INA219_ADDRESS, INA219_REG_CURRENT, (uint16_t *)&tmp);
@@ -112,16 +112,25 @@ uint16_t readBusCurrent(void) {
   if (tmp < 0) {
   if (tmp < 0) {
     tmp = - tmp;
     tmp = - tmp;
   }
   }
-  current = (uint16_t)(((tmp * currentLSB) + 500) / 1000);
+  current = tmp;
+  current *= currentLSB;
+  current += 500;
+  current /= 1000;
 
 
-  return current;
+  return (uint16_t)current;
 }
 }
 
 
 /** */
 /** */
 uint32_t readBusPower(void) {
 uint32_t readBusPower(void) {
   uint16_t power;
   uint16_t power;
+  uint32_t tmp;
+
   i2c_rd_reg(INA219_ADDRESS, INA219_REG_POWER, &power);
   i2c_rd_reg(INA219_ADDRESS, INA219_REG_POWER, &power);
-  return (((power * powerLSB) + 500) / 1000);
+  tmp = power;
+  tmp *= powerLSB;
+  tmp += 500;
+  tmp /= 1000;
+  return (uint16_t)tmp;
 }
 }
 
 
 /**
 /**

+ 1 - 1
src/main.c

@@ -2,7 +2,7 @@
   ******************************************************************************
   ******************************************************************************
   * @file    Project/main.c
   * @file    Project/main.c
   * @author  "Vladimir N. Shilov" <shilow@ukr.net>
   * @author  "Vladimir N. Shilov" <shilow@ukr.net>
-  * @version v.0.3
+  * @version v.0.4
   * @date    08-July-2019
   * @date    08-July-2019
   * @brief   Main program body
   * @brief   Main program body
    ******************************************************************************
    ******************************************************************************