source: trunk/fw_g473rct/SES/src/fast_current.c

Last change on this file was 20, checked in by f.jahn, 4 days ago

adc dma funktioniert und modbus funktioniert

File size: 2.5 KB
Line 
1/******************************************************************************
2*
3* @file    fast_current.c
4* @author  ECS, Falko Jahn
5* @version V1.0.0
6* @date    2022-01-16
7* @brief       
8*
9******************************************************************************/
10
11//      --- INCLUDES -----------------------------------------------------------------
12#include "fast_current.h"
13#include "main.h"
14#include "sysdata.h"
15
16//      --- EXTERNE VARIABLEN --------------------------------------------------------
17
18//      --- LOKALE DEFINES - bitte hier dokumentieren --------------------------------
19//#define FAST_CURRENT_FILTER  2
20
21
22
23#define I_SENSE_GAIN    40.0
24
25
26  #if (DEVICETYPE == 500)
27    #define SHUNT_RESISTOR      0.000125       
28  #elif (DEVICETYPE == 250)
29    #define SHUNT_RESISTOR      0.000250       
30  #elif (DEVICETYPE == 125)
31    #define SHUNT_RESISTOR      0.000500       
32  #else
33  #error No valid device type
34  #endif
35               
36
37
38
39
40//      --- LOKALE TYPE DEFS - bitte hier dokumentieren-------------------------------
41
42//      --- DEFINITIONEN GLOBALER VARIABLEN - Bitte in Header dokumentieren ----------
43
44//      --- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------
45
46//      --- LOKALE FUNKTIONS PROTOTYPEN ----------------------------------------------
47
48//      --- LOKALE FUNKTIONEN - bitte hier dokumentieren -----------------------------
49
50//      --- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------
51
52
53void FAST_CURRENT_Exec(uint32_t newvalP, uint32_t newvalM )
54{
55  static int measCounter;
56  static unsigned long avgsumP = 0;
57  uint32_t avgvalP;
58
59  if (measCounter < INT32_MAX) measCounter++;
60
61
62  // Filterlängen in 2er-Potenzen --> Compiler optimiert
63 // avgsumP -= avgsumP / FAST_CURRENT_FILTER;
64 // avgsumP += newvalP;
65//  avgvalP = avgsumP / FAST_CURRENT_FILTER;
66
67//  static unsigned long avgsumM = 0;
68//  uint32_t avgvalM;
69  // Filterlängen in 2er-Potenzen --> Compiler optimiert
70//  avgsumM -= avgsumM / FAST_CURRENT_FILTER;
71//  avgsumM += newvalM;
72//  avgvalM = avgsumM / FAST_CURRENT_FILTER;
73
74
75  //Berechne Differenzspannung am ADC Eingnag
76  double diff;
77  diff = (int32_t) newvalP - (int32_t) newvalM; 
78  diff = (diff * sys_data.s.values.realVdd)  / 65536;
79
80  //Umrechung auf Strom
81  double temp_current;
82  temp_current = (diff / I_SENSE_GAIN) /  SHUNT_RESISTOR;
83  sys_data.s.values.fast_current = temp_current * (sys_data.s.parameter.batteryCurrentGainCorrectionFaktor / 1000000.0);
84 
85}
86
87/*************************** End of file ****************************/
Note: See TracBrowser for help on using the repository browser.