Переглянути джерело

Добавил счётчик ампер-часов, и вывод их при условии 0 на входе BTN.

Vladimir N. Shilov 8 роки тому
батько
коміт
eb5fe6bfd3
1 змінених файлів з 21 додано та 1 видалено
  1. 21 1
      src/main.c

+ 21 - 1
src/main.c

@@ -66,6 +66,7 @@
 #define LED_ANODE_ON2 LED_ANOD2_PORT->ODR |= LED_ANOD2_PIN;
 #define LED_ANODE_ON2 LED_ANOD2_PORT->ODR |= LED_ANOD2_PIN;
 #define LED_ANODE_ON3 LED_ANOD3_PORT->ODR |= LED_ANOD3_PIN;
 #define LED_ANODE_ON3 LED_ANOD3_PORT->ODR |= LED_ANOD3_PIN;
 
 
+#define SUB_SECOND_CNT  5
 
 
 /* Private function prototypes -----------------------------------------------*/
 /* Private function prototypes -----------------------------------------------*/
 static void ADC_Config(void);
 static void ADC_Config(void);
@@ -73,6 +74,7 @@ static void GPIO_Config(void);
 static void TIM1_Config(void);
 static void TIM1_Config(void);
 static void OutputToLed(void);
 static void OutputToLed(void);
 static void PrepareForLed(void);
 static void PrepareForLed(void);
+//static void CountCapacity(void);
 
 
 /* Private functions ---------------------------------------------------------*/
 /* Private functions ---------------------------------------------------------*/
 
 
@@ -80,8 +82,11 @@ static void PrepareForLed(void);
 __IO uint16_t ConversionBuffer[ADC_SMPLS];
 __IO uint16_t ConversionBuffer[ADC_SMPLS];
 __IO uint8_t BufferIndex = 0;
 __IO uint8_t BufferIndex = 0;
 static uint16_t Current = 0;
 static uint16_t Current = 0;
+static uint32_t Capacity = 0;
 static uint8_t LedDigits[3] = {0, 0, 0};
 static uint8_t LedDigits[3] = {0, 0, 0};
 static uint8_t LedPoint = 3;
 static uint8_t LedPoint = 3;
+static uint16_t SubSecondBfr = 0;
+static uint8_t SubSecondCnt = SUB_SECOND_CNT;
 
 
 void main(void)
 void main(void)
 {
 {
@@ -110,6 +115,7 @@ void main(void)
   RTOS_Init();
   RTOS_Init();
   RTOS_SetTask(OutputToLed, 0, 5);
   RTOS_SetTask(OutputToLed, 0, 5);
   RTOS_SetTask(PrepareForLed, 210, 200);
   RTOS_SetTask(PrepareForLed, 210, 200);
+  //RTOS_SetTask(CountCapacity, 1005, 1000);
 
 
   /* Infinite loop */
   /* Infinite loop */
   while (1)
   while (1)
@@ -142,6 +148,16 @@ void main(void)
         tbuf = (tbuf + 14) / 28; // get voltage from shunt
         tbuf = (tbuf + 14) / 28; // get voltage from shunt
         /* â Current òîê â ìèëèàìïåðàõ */
         /* â Current òîê â ìèëèàìïåðàõ */
         Current = (tbuf + 3) / 6; // shunt resistance in mOhms
         Current = (tbuf + 3) / 6; // shunt resistance in mOhms
+
+        SubSecondBfr += Current;
+        SubSecondCnt --;
+
+        if(SubSecondCnt == 0){
+          Capacity += SubSecondBfr;
+          SubSecondBfr = 0;
+          SubSecondCnt = SUB_SECOND_CNT;
+        }
+
     } // End of if (BufferIndex >= ADC_SMPLS)
     } // End of if (BufferIndex >= ADC_SMPLS)
 
 
     RTOS_DispatchTask();
     RTOS_DispatchTask();
@@ -155,7 +171,11 @@ void main(void)
 static void PrepareForLed(void) {
 static void PrepareForLed(void) {
   uint16_t value;
   uint16_t value;
 
 
-  value = Current;
+  if((BTN_PORT->IDR & BTN_PINS) == 0){
+    value = Capacity / 3600;
+  } else {
+    value = Current;
+  }
 
 
   if(value > 9999){
   if(value > 9999){
     LedPoint = 1;
     LedPoint = 1;