| 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 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | // --- LOKALE TYPE DEFS - bitte hier dokumentieren------------------------------- |
|---|
| 24 | |
|---|
| 25 | // --- DEFINITIONEN GLOBALER VARIABLEN - Bitte in Header dokumentieren ---------- |
|---|
| 26 | |
|---|
| 27 | // --- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------ |
|---|
| 28 | |
|---|
| 29 | // --- LOKALE FUNKTIONS PROTOTYPEN ---------------------------------------------- |
|---|
| 30 | |
|---|
| 31 | // --- LOKALE FUNKTIONEN - bitte hier dokumentieren ----------------------------- |
|---|
| 32 | |
|---|
| 33 | // --- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------ |
|---|
| 34 | void CurrentOffsetCal(uint32_t newVal) |
|---|
| 35 | { |
|---|
| 36 | sys_data.s.parameter.batteryCurrentOffsetFast = newVal-FAST_CURRENT_ADC_OFFSET; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | void CurrentGainCal(uint32_t newVal) |
|---|
| 40 | { |
|---|
| 41 | double correction; |
|---|
| 42 | double valWithoutGainCorrection; |
|---|
| 43 | |
|---|
| 44 | valWithoutGainCorrection = ((int32_t) newVal - FAST_CURRENT_ADC_OFFSET - sys_data.s.parameter.batteryCurrentOffsetFast) * VREF ; |
|---|
| 45 | valWithoutGainCorrection = valWithoutGainCorrection / FAST_CURRENT_ADC_RESOLUTION; |
|---|
| 46 | valWithoutGainCorrection = valWithoutGainCorrection / FAST_CURRENT_I_SENSE_GAIN ; |
|---|
| 47 | valWithoutGainCorrection = valWithoutGainCorrection / FAST_CURRENT_SHUNT_RESISTOR ; |
|---|
| 48 | |
|---|
| 49 | correction = (double) sys_data.s.parameter.batteryCurrentGainRefCurrent / valWithoutGainCorrection; |
|---|
| 50 | sys_data.s.parameter.batteryCurrentGainCorrectionFaktorFast = correction * 1000000; |
|---|
| 51 | |
|---|
| 52 | } |
|---|
| 53 | void FAST_CURRENT_Exec(uint32_t newVal ) |
|---|
| 54 | { |
|---|
| 55 | |
|---|
| 56 | //Umrechung auf Strom |
|---|
| 57 | double temp_current; |
|---|
| 58 | temp_current = ((int32_t) newVal - FAST_CURRENT_ADC_OFFSET - sys_data.s.parameter.batteryCurrentOffsetFast) * VREF ; |
|---|
| 59 | temp_current = temp_current / FAST_CURRENT_ADC_RESOLUTION; |
|---|
| 60 | temp_current = temp_current / FAST_CURRENT_I_SENSE_GAIN ; |
|---|
| 61 | temp_current = temp_current / FAST_CURRENT_SHUNT_RESISTOR ; |
|---|
| 62 | sys_data.s.values.fast_current = temp_current * (sys_data.s.parameter.batteryCurrentGainCorrectionFaktorFast / 1000000.0); |
|---|
| 63 | |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | /*************************** End of file ****************************/ |
|---|