Changeset 73 for trunk/fw_g473rct/SES/src
- Timestamp:
- Aug 4, 2026, 1:53:58 PM (29 hours ago)
- Location:
- trunk/fw_g473rct/SES/src
- Files:
-
- 8 edited
- 2 moved
-
ads1260.c (modified) (18 diffs)
-
battery_voltage_fast.c (moved) (moved from trunk/fw_g473rct/SES/src/battery_voltage.c ) (3 diffs)
-
chip_temperature.c (modified) (1 diff)
-
eeprom.c (modified) (10 diffs)
-
esr.c (modified) (9 diffs)
-
fast_current.c (modified) (2 diffs)
-
int_bat_voltage.c (modified) (1 diff)
-
outputs.c (modified) (3 diffs)
-
shunt_voltage_fast.c (moved) (moved from trunk/fw_g473rct/SES/src/shunt_voltage.c ) (3 diffs)
-
sysdata.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/SES/src/ads1260.c
r38 r73 51 51 #include "iwdg.h" 52 52 // --- EXTERNE VARIABLEN -------------------------------------------------------- 53 53 extern CRC_HandleTypeDef hcrc; 54 54 // --- LOKALE DEFINES - bitte hier dokumentieren -------------------------------- 55 55 … … 116 116 #define CHOP_MODE_RESET_MASK ~(0b11 << 5)/*Default*/ 117 117 118 #define CONVERSION_MODE_REGISTER (CHOP_MODE_REGISTER)118 #define CONVERSION_MODE_REGISTER (CHOP_MODE_REGISTER) 119 119 #define CONVERSION_MODE_CONTINIOUS (0 << 4)/*Default*/ 120 120 #define CONVERSION_MODE_PULSE (1 << 4) 121 121 #define CONVERSION_MODE_RESET_MASK ~(1 << 4) 122 122 123 #define CONVERSION_START_DELAY_REGISTER (CHOP_MODE_REGISTER)123 #define CONVERSION_START_DELAY_REGISTER (CHOP_MODE_REGISTER) 124 124 #define CONVERSION_START_DELAY_0u (0b0000 << 0) 125 125 #define CONVERSION_START_DELAY_50u (0b0001 << 0)/*Default*/ … … 173 173 #define POS_INPUT_MUX_SELECT_AIN3 (0b0100 << 4) 174 174 #define POS_INPUT_MUX_SELECT_AIN4 (0b0101 << 4) 175 #define POS_INPUT_MUX_SELECT_AIN5 (0b0110 << 4) 176 #define POS_INPUT_MUX_SELECT_AIN6 (0b0111 << 4) 177 #define POS_INPUT_MUX_SELECT_AIN7 (0b1000 << 4) 178 #define POS_INPUT_MUX_SELECT_AIN8 (0b1001 << 4) 179 #define POS_INPUT_MUX_SELECT_AIN9 (0b1010 << 4) 175 180 #define POS_INPUT_MUX_SELECT_INT_TEMP_SENSOR_POS (0b1011 << 4) 176 181 #define POS_INPUT_MUX_SELECT_INT_AVDD_DIV4_POS (0b1100 << 4) … … 185 190 #define NEG_INPUT_MUX_SELECT_AIN3 (0b0100 << 0) 186 191 #define NEG_INPUT_MUX_SELECT_AIN4 (0b0101 << 0) 192 #define NEG_INPUT_MUX_SELECT_AIN5 (0b0110 << 0) 193 #define NEG_INPUT_MUX_SELECT_AIN6 (0b0111 << 0) 194 #define NEG_INPUT_MUX_SELECT_AIN7 (0b1000 << 0) 195 #define NEG_INPUT_MUX_SELECT_AIN8 (0b1001 << 0) 196 #define NEG_INPUT_MUX_SELECT_AIN9 (0b1010 << 0) 187 197 #define NEG_INPUT_MUX_SELECT_INT_TEMP_SENSOR_NEG (0b1011 << 0) 188 198 #define NEG_INPUT_MUX_SELECT_INT_AVDD_DIV4_NEG (0b1100 << 0) … … 201 211 int32_t avgValWithOffsetCommonModeOffsetTemperatureCorrection; 202 212 double current; 213 double batteryvoltage; 214 double shuntVoltage; 203 215 double currentWithGainCorrection; 204 216 double currentWithGainAndGainShuntTempCorrection; … … 230 242 static void ADS_1260_SetInternalReference(SPI_HandleTypeDef * hspi); 231 243 static void ADS_1260_SetExternalReference(SPI_HandleTypeDef * hspi); 232 static void ADS_1260_InputMuxSelect(SPI_HandleTypeDef * hspi, uint8_t muxSelect );244 static void ADS_1260_InputMuxSelect(SPI_HandleTypeDef * hspi, uint8_t muxSelect, uint8_t crcmode); 233 245 static void ADS_1260_SetChopMode(SPI_HandleTypeDef * hspi, uint8_t chopMode); 234 246 static void ADS_1260_ActivateStatusData(void); … … 237 249 static uint32_t ADS1260_ProcessCurrent(int32_t current); 238 250 volatile uint32_t newCurrentValue=0; 251 volatile uint32_t channelInProgress; // 0 = current, 1 = voltage battery 239 252 //static uint32_t ADS1260_ProcessVoltage(int32_t voltage, sys_data_t * data); 240 253 //static uint32_t ADS1260_ProcessTemperature(int32_t temperature, sys_data_t * data); … … 383 396 * @retval kein 384 397 */ 385 static void ADS_1260_InputMuxSelect(SPI_HandleTypeDef * hspi, uint8_t muxSelect) 386 { 387 // Write 388 uint8_t spiData[3] = {(REGISTER_WRITE_COMMAND + INPUT_MUX_REGISTER), muxSelect, 0}; 389 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_RESET); 390 HAL_SPI_TransmitReceive(hspi, spiData, spiData, 2, DEFAULT_ADS1260_TRANSMIT_RECEIVE_TIMEOUT); 391 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_SET); 392 // Read 393 spiData[COMMAND_POS] = (REGISTER_READ_COMMAND + INPUT_MUX_REGISTER); 394 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_RESET); 395 HAL_SPI_TransmitReceive(hspi, spiData, spiData, 3, DEFAULT_ADS1260_TRANSMIT_RECEIVE_TIMEOUT); 396 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_SET); 397 // Verifie 398 if(spiData[RECEIVE_DATA_POS] != muxSelect) 399 { 400 printf("ERROR ADS_1260_InputMuxSelect\n"); 401 // while(1); 402 } 398 static void ADS_1260_InputMuxSelect(SPI_HandleTypeDef * hspi, uint8_t muxSelect,uint8_t crcmode) 399 { 400 if (crcmode==0) 401 { 402 // Write 403 uint8_t spiData[3] = {(REGISTER_WRITE_COMMAND + INPUT_MUX_REGISTER), muxSelect, 0}; 404 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_RESET); 405 HAL_SPI_TransmitReceive(hspi, spiData, spiData, 2, DEFAULT_ADS1260_TRANSMIT_RECEIVE_TIMEOUT); 406 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_SET); 407 // Read 408 spiData[COMMAND_POS] = (REGISTER_READ_COMMAND + INPUT_MUX_REGISTER); 409 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_RESET); 410 HAL_SPI_TransmitReceive(hspi, spiData, spiData, 3, DEFAULT_ADS1260_TRANSMIT_RECEIVE_TIMEOUT); 411 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_SET); 412 // Verifie 413 if(spiData[RECEIVE_DATA_POS] != muxSelect) 414 { 415 printf("ERROR ADS_1260_InputMuxSelect\n"); 416 } 417 } 418 else 419 420 { 421 422 // Write 423 uint8_t spiDataIn[6]; 424 spiDataIn[0] = REGISTER_WRITE_COMMAND + INPUT_MUX_REGISTER; 425 spiDataIn[1] = muxSelect; 426 spiDataIn[2] = HAL_CRC_Calculate(&hcrc, (uint32_t*) spiDataIn, 2); 427 spiDataIn[3] = 0; 428 429 uint8_t spiDataOut[6] = {0,0,0,0,0,0}; 430 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_RESET); 431 HAL_SPI_TransmitReceive(hspi, spiDataIn, spiDataOut, 4, DEFAULT_ADS1260_TRANSMIT_RECEIVE_TIMEOUT); 432 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_SET); 433 434 // Read back mux register 435 spiDataIn[0] = (REGISTER_READ_COMMAND + INPUT_MUX_REGISTER); 436 spiDataIn[1] = arbitraryByte; 437 spiDataIn[2] = HAL_CRC_Calculate(&hcrc, (uint32_t*) spiDataIn, 2); 438 spiDataIn[3] = 0; 439 spiDataIn[4] = 0; 440 spiDataIn[5] = 0; 441 442 443 444 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_RESET); 445 HAL_SPI_TransmitReceive(hspi, spiDataIn, spiDataOut, 6, DEFAULT_ADS1260_TRANSMIT_RECEIVE_TIMEOUT); 446 //HAL_GPIO_WritePin(ADC_SPI1_NSS_GPIO_Port, ADC_SPI1_NSS_Pin, GPIO_PIN_SET); 447 // Verifie 448 if(spiDataOut[4] != muxSelect) 449 { 450 printf("ERROR ADS_1260_InputMuxSelect\n"); 451 } 452 } 453 403 454 } 404 455 … … 613 664 static uint32_t ADS1260_ProcessCurrent(int32_t newval) 614 665 { 615 static signed long avgsum = 0;616 static int meas_counter;617 if (meas_counter < INT32_MAX) meas_counter++;618 int32_t avgval;666 //static signed long avgsum = 0; 667 //static int meas_counter; 668 //if (meas_counter < INT32_MAX) meas_counter++; 669 //int32_t avgval; 619 670 620 671 // Filterlängen in 2er-Potenzen --> Compiler optimiert 621 avgsum -= avgsum/ BATTERY_CURRENT_FILTER;622 avgsum += newval;623 avgval = avgsum / BATTERY_CURRENT_FILTER;624 sys_data.s.values.battryCurrentRaw = avgval;672 //avgsum -= avgsum/ BATTERY_CURRENT_FILTER; 673 //avgsum += newval; 674 //avgval = avgsum / BATTERY_CURRENT_FILTER; 675 sys_data.s.values.battryCurrentRaw = newval; 625 676 /**********************Offset Kompensation:*******************************/ 626 677 // Offset abziehen 627 avgValWithOffsetCompensation = avgval - sys_data.s.parameter.batteryCurrentOffset;678 avgValWithOffsetCompensation = newval - sys_data.s.parameter.batteryCurrentOffset; 628 679 // Temperaturabhängiges Offset abziehen 629 680 // in ADC Messwerten mal Abweichung von Referenttemperatur … … 739 790 740 791 741 if (meas_counter > (BATTERY_CURRENT_FILTER *10)) // Nur aktualiseren, wenn es schon ausreichend Messwerte gab742 {792 // if (meas_counter > (BATTERY_CURRENT_FILTER *10)) // Nur aktualiseren, wenn es schon ausreichend Messwerte gab 793 // { 743 794 // höchster und niedrigster Stromwert werden gespeichert 744 795 if(sys_data.s.values.batteryCurrent > sys_data.s.values.batteryCurrentMax) … … 750 801 sys_data.s.values.batteryCurrentMin = sys_data.s.values.batteryCurrent; 751 802 } 752 }803 // } 753 804 754 805 newCurrentValue=1; … … 757 808 } 758 809 810 static uint32_t ADS1260_ProcessBatteryVoltage(int32_t newval) 811 { 812 static signed long avgsum = 0; 813 static int meas_counter; 814 if (meas_counter < INT32_MAX) meas_counter++; 815 //int32_t avgval; 816 817 // Filterlängen in 2er-Potenzen --> Compiler optimiert 818 //avgsum -= avgsum/ BATTERY_CURRENT_FILTER; 819 //avgsum += newval; 820 //avgval = avgsum / BATTERY_CURRENT_FILTER; 821 822 /**********************Offset Kompensation:*******************************/ 823 // Offset abziehen 824 825 826 batteryvoltage = ((newval * (double) 1.5 * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / (double)0x800000); 827 sys_data.s.values.batteryVoltage = (batteryvoltage * 1000) - sys_data.s.parameter.batteryVoltageOffset; 828 829 //printf("battery voltage = %.4d V\n", (int32_t) (batteryvoltage*1000)); 830 831 832 833 834 835 836 837 838 return 0; 839 } 840 841 static uint32_t ADS1260_ProcessShuntVoltage(int32_t newval) 842 { 843 844 shuntVoltage = ((newval * (double) 1.5 * SHUNT_VOLTAGE_VOLTAGE_DIVIDER ) / (double)0x800000); 845 sys_data.s.values.shuntVoltage = (shuntVoltage * 1000) - sys_data.s.parameter.shuntVoltageOffset; 846 847 return 0; 848 } 759 849 760 850 // --- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------ … … 788 878 /* 6*/ ADS_1260_SetDataRate(&hspi3, DATA_RATE_20); 789 879 // /* 7*/ ADS_1260_SetDigitalFilter(&hspi1, FILTER_SINC4); 790 /* 8*/ ADS_1260_SetConversionMode(&hspi3, CONVERSION_MODE_ CONTINIOUS);880 /* 8*/ ADS_1260_SetConversionMode(&hspi3, CONVERSION_MODE_PULSE); 791 881 // langsamer 792 882 ADS_1260_SetChopMode(&hspi3, CHOP_MODE_CHOP_MODE); 793 ADS_1260_InputMuxSelect(&hspi3, POS_INPUT_MUX_SELECT_AIN2 + NEG_INPUT_MUX_SELECT_AIN3 );883 ADS_1260_InputMuxSelect(&hspi3, POS_INPUT_MUX_SELECT_AIN2 + NEG_INPUT_MUX_SELECT_AIN3,0); 794 884 795 885 ADS_1260_ActivateStatusData(); 796 886 HAL_IWDG_Refresh(&hiwdg); 797 ADS_1260_ActivateLock();798 HAL_IWDG_Refresh(&hiwdg);887 // ADS_1260_ActivateLock(); 888 // HAL_IWDG_Refresh(&hiwdg); 799 889 800 890 /*10*/ //ADS_1260_SelfOffsetCalibration(&hspi1); … … 804 894 ADS1260_StartConversion(); 805 895 HAL_IWDG_Refresh(&hiwdg); 896 channelInProgress=0; 806 897 } 807 898 … … 810 901 { 811 902 HAL_GPIO_WritePin(ADC_START_CONV_GPIO_Port, ADC_START_CONV_Pin, GPIO_PIN_SET); 903 904 //Vorbereitung aufg nächsten Start 905 812 906 } 813 907 814 908 void ADS1260_ReadConversion(void) 815 909 { 816 extern CRC_HandleTypeDef hcrc;910 817 911 convert_union_t convert; 912 HAL_GPIO_WritePin(ADC_START_CONV_GPIO_Port, ADC_START_CONV_Pin, GPIO_PIN_RESET); 913 818 914 819 915 // CRC2 … … 831 927 uint8_t STATUS_reg = spiDataOut[4]; 832 928 833 if ( (STATUS_reg & (1 << STATUS_LOCK)) &&(STATUS_reg & (1 << STATUS_DRDY)) && !(STATUS_reg & (1 << STATUS_CRCERR)) && !(STATUS_reg & (1 << STATUS_REFL_ALM)))929 if ( (STATUS_reg & (1 << STATUS_DRDY)) && !(STATUS_reg & (1 << STATUS_CRCERR)) && !(STATUS_reg & (1 << STATUS_REFL_ALM))) 834 930 { 835 931 // Rohwerte Byteswitch … … 864 960 } 865 961 866 ADS1260_ProcessCurrent(value); 962 if (channelInProgress==0) 963 { 964 ADS1260_ProcessCurrent(value); 965 ADS_1260_InputMuxSelect(&hspi3, POS_INPUT_MUX_SELECT_AIN4 + NEG_INPUT_MUX_SELECT_AIN5,1); 966 channelInProgress=1; 967 } 968 else if (channelInProgress==1) 969 { 970 ADS1260_ProcessBatteryVoltage(value); 971 ADS_1260_InputMuxSelect(&hspi3, POS_INPUT_MUX_SELECT_AIN6 + NEG_INPUT_MUX_SELECT_AIN7,1); 972 channelInProgress=2; 973 } 974 else if (channelInProgress==2) 975 { 976 ADS1260_ProcessShuntVoltage(value); 977 ADS_1260_InputMuxSelect(&hspi3, POS_INPUT_MUX_SELECT_AIN2 + NEG_INPUT_MUX_SELECT_AIN3,1); 978 channelInProgress=0; 979 } 980 981 ADS1260_StartConversion(); 867 982 } 868 983 … … 1041 1156 } 1042 1157 1158 void ADS1260_BatteryVoltageZeroCal(void) 1159 { 1160 sys_data.s.parameter.batteryVoltageOffset = sys_data.s.values.batteryVoltage + sys_data.s.parameter.batteryVoltageOffset ; 1161 } 1162 1163 void ADS1260_ShuntVoltageZeroCal(void) 1164 { 1165 sys_data.s.parameter.shuntVoltageOffset = sys_data.s.values.shuntVoltage + sys_data.s.parameter.shuntVoltageOffset ; 1166 } 1167 1168 1043 1169 //----------------------------------------------------------------------------- -
trunk/fw_g473rct/SES/src/battery_voltage_fast.c
r72 r73 10 10 11 11 // --- INCLUDES ----------------------------------------------------------------- 12 #include "battery_voltage .h"12 #include "battery_voltage_fast.h" 13 13 #include "main.h" 14 14 #include "sysdata.h" 15 15 #include "stdlib.h" 16 16 #include "stdio.h" 17 17 #include "tim.h" 18 18 // --- EXTERNE VARIABLEN -------------------------------------------------------- 19 19 20 20 // --- LOKALE DEFINES - bitte hier dokumentieren -------------------------------- 21 21 22 #define BATTERY_VOLTAGE_FILTER 3223 22 24 23 … … 27 26 // --- DEFINITIONEN GLOBALER VARIABLEN - Bitte in Header dokumentieren ---------- 28 27 extern ADC_HandleTypeDef hadc2; 28 extern __IO int32_t adc2Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1_CRC"))); 29 29 // --- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------ 30 int32_t BATTERY_VOLTAGE_adc_offset =0; 31 int32_t last_adc_value = 0 ; 30 31 32 32 33 // --- LOKALE FUNKTIONS PROTOTYPEN ---------------------------------------------- 33 void ADC2_SetOffset(uint32_t channel, int16_t offset); 34 34 35 // --- LOKALE FUNKTIONEN - bitte hier dokumentieren ----------------------------- 35 36 … … 37 38 38 39 39 void BATTERY_VOLTAGE_ Exec(int32_t newVal)40 void BATTERY_VOLTAGE_FAST_Exec(int32_t newVal) 40 41 { 41 static int measCounter; 42 static unsigned long avgSum = 0; 43 int32_t avgVal; 44 last_adc_value = newVal; 45 if (measCounter < INT32_MAX) measCounter++; 42 //Umrechung auf Eingangsspannung am Gerät mit Teiler 43 sys_data.s.values.batteryVoltageFast = ((newVal - BATTERY_VOLTAGE_FAST_ADC_OFFSET) * (int64_t)VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER / BATTERY_VOLTAGE_FAST_ADC_RESOLUTION) - sys_data.s.parameter.batteryVoltageFastOffset; 44 45 } 46 46 47 47 48 // Filterlängen in 2er-Potenzen --> Compiler optimiert 49 //avgSum -= avgSum / BATTERY_VOLTAGE_FILTER; 50 //avgSum += newVal; 51 //avgVal = avgSum / BATTERY_VOLTAGE_FILTER; 52 53 54 55 56 //Umrechung auf Eingangsspannung am Gerät mit Teiler 57 sys_data.s.values.batteryVoltage = ((newVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION; 58 59 60 61 62 //Max und Minwert 63 if (measCounter > BATTERY_VOLTAGE_FILTER * 10) 64 { 65 if (sys_data.s.values.batteryVoltage > sys_data.s.values.batteryVoltageMax) 66 { 67 sys_data.s.values.batteryVoltageMax = sys_data.s.values.batteryVoltage; 68 } 69 if (sys_data.s.values.batteryVoltage < sys_data.s.values.batteryVoltageMin) 70 { 71 sys_data.s.values.batteryVoltageMin = sys_data.s.values.batteryVoltage; 72 } 73 } 74 75 76 77 //Berechnung schnelle Wert ohne Glättung: 78 //Umrechung auf Eingangsspannung am Gerät mit Teiler 79 //sys_data.s.values.fast_voltage = ((newVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION; 80 81 82 48 void BATTERY_VOLTAGE_FAST_ZeroCal(void) 49 { 50 sys_data.s.parameter.batteryVoltageFastOffset = sys_data.s.values.batteryVoltageFast + sys_data.s.parameter.batteryVoltageFastOffset ; 83 51 } 84 85 ADC_ChannelConfTypeDef sConfig = {0};86 87 void BATTERY_VOLTAGE_ZeroCal(void)88 {89 BATTERY_VOLTAGE_adc_offset = last_adc_value - BATTERY_VOLTAGE_ADC_OFFSET;90 91 52 92 53 93 54 94 55 95 // 1. ADC2 stoppen und sicherstellen, dass er deaktiviert ist96 HAL_ADC_Stop(&hadc2);97 98 uint16_t offset_value = abs(BATTERY_VOLTAGE_adc_offset);99 100 if (BATTERY_VOLTAGE_adc_offset < 0 )101 {102 ADC2->OFR1 = (ADC_OFR1_OFFSET1_EN |103 (3 << ADC_OFR1_OFFSET1_CH_Pos) |104 (1 << ADC_OFR1_OFFSETPOS_Pos) |105 (offset_value ));106 }107 else108 {109 ADC2->OFR1 = (ADC_OFR1_OFFSET1_EN |110 (3 << ADC_OFR1_OFFSET1_CH_Pos) |111 (0 << ADC_OFR1_OFFSETPOS_Pos) |112 (offset_value ));113 }114 115 // 5. ADC2 wieder für die Wandlung starten116 HAL_ADC_Start(&hadc2);117 }118 119 120 121 56 /*************************** End of file ****************************/ -
trunk/fw_g473rct/SES/src/chip_temperature.c
r24 r73 72 72 } 73 73 74 void CHIP_TEMPERATURE_Exec( uint32_t chiptemperature)74 void CHIP_TEMPERATURE_Exec(int32_t chiptemperature) 75 75 { 76 76 double voltage; -
trunk/fw_g473rct/SES/src/eeprom.c
r38 r73 61 61 uint32_t currentGain; 62 62 63 63 64 int32_t currentOffsetFast; 64 65 uint32_t currentGainFast; 66 67 int32_t batteryVoltageOffset; 68 int32_t batteryVoltageFastOffset; 69 int32_t shuntVoltageOffset; 70 int32_t shuntVoltageFastOffset; 65 71 66 72 int64_t mAsCounter; … … 209 215 /* currentGainFast */ 1000000, //uint32_t currentGain; 210 216 217 /* batteryVoltageOffset */ 0, 218 /* batteryVoltageFastOffset */ 0, 219 /* shuntVoltageOffset */ 0, 220 /* shuntVoltageFastOffset */ 0, 221 211 222 /* mAsCounter */ 0, // mAsCounter 212 223 /* detectedCapacity */ -1, // detectedCapacity … … 223 234 /* iBatFull */ 10, // I-batt full 10%, 10A bei 100Ah akku 224 235 /* tBatFull */ 2, // t-batt full 2 Sekunden 225 #if defined SYSTEM_VOLTAGE_12V236 #if defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_12V 226 237 /* uBatFull */ 14000, // 14V olt Ubatt full, Neu: Bei 0: Erkung von Lipro LVP als 0% 227 238 /* uBatEmpty */ 12400, // 11,312V Ubatt Empty 228 #elif defined SYSTEM_VOLTAGE_24V239 #elif defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_24V 229 240 /* uBatFull */ 28000, // 14V olt Ubatt full, Neu: Bei 0: Erkung von Lipro LVP als 0% 230 241 /* uBatEmpty */ 24800, // 11,312V Ubatt Empty 231 #elif defined SYSTEM_VOLTAGE_48V242 #elif defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_48V 232 243 /* uBatFull */ 56000, // 14V olt Ubatt full, Neu: Bei 0: Erkung von Lipro LVP als 0% 233 244 /* uBatEmpty */ 49600, // 11,312V Ubatt Empty … … 239 250 /* socCalcMode */ 1, // SoC calculation mode: 0(default) 240 251 /* cellRatedDischargeTime */ 2, // cell rated current discharge time [C/x]. For example, if 40Ah cell is rated as 0.5c, then rated discharge time is 2 241 #if defined SYSTEM_VOLTAGE_12V252 #if defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_12V 242 253 /* lvpStart */ 12000, // uint16_t lvpStart; Spannung ab der die LOW Voltage Protection aktiv wird in mV 243 254 /* lvpStop */ 12500, // uint16_t lvpStop; Spannung ab der die LOW Voltage Protection wieder inaktiv wird 244 255 /* ovpStart */ 14800, // uint16_t ovpStart; Spannung ab der die OVER Voltage Protection aktiv wird in mV 245 256 /* ovpStop */ 14000, // uint16_t ovpStop; Spannung ab der die OVER Voltage Protection wieder inaktiv wird 246 #elif defined SYSTEM_VOLTAGE_24V257 #elif defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_24V 247 258 /* lvpStart */ 24000, // uint16_t lvpStart; Spannung ab der die LOW Voltage Protection aktiv wird in mV 248 259 /* lvpStop */ 25000, // uint16_t lvpStop; Spannung ab der die LOW Voltage Protection wieder inaktiv wird … … 250 261 /* ovpStop */ 28000, // uint16_t ovpStop; Spannung ab der die OVER Voltage Protection wieder inaktiv wird 251 262 252 #elif defined SYSTEM_VOLTAGE_48V263 #elif defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_48V 253 264 /* lvpStart */ 48000, // uint16_t lvpStart; Spannung ab der die LOW Voltage Protection aktiv wird in mV 254 265 /* lvpStop */ 50000, // uint16_t lvpStop; Spannung ab der die LOW Voltage Protection wieder inaktiv wird … … 284 295 /* uBatEmptyCompStartTemp */ 50, // 5°C We start calculating uBatEmpty compensations only when cell temperature is lower than this value 285 296 /* uBatEmptyCompStopTemp */ -200, // -20°C We stop calculating uBatEmpty compensations when cell temperature is lower than this value 286 #if defined SYSTEM_VOLTAGE_12V297 #if defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_12V 287 298 /* uBatEmptyCompStopVolt */ 10000, // 10V uBatEmpty voltage at temperatures lower than -20°C 288 #elif defined SYSTEM_VOLTAGE_24V299 #elif defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_24V 289 300 /* uBatEmptyCompStopVolt */ 20000, // 10V uBatEmpty voltage at temperatures lower than -20°C 290 #elif defined SYSTEM_VOLTAGE_48V301 #elif defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_48V 291 302 /* uBatEmptyCompStopVolt */ 40000, // 10V uBatEmpty voltage at temperatures lower than -20°C 292 303 #else … … 298 309 /* Battery Empty Detection Mode*/ 1, // Auto, from BMS 299 310 /* AUX MODE */ AUX_MODE_HEATER,// Heizung 300 #if defined SYSTEM_VOLTAGE_12V311 #if defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_12V 301 312 /* AUX SETPOINT ON */ 13600, // Erkennung Ladegerät ab 13,6V 302 #elif defined SYSTEM_VOLTAGE_24V313 #elif defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_24V 303 314 /* AUX SETPOINT ON */ 27200, // Erkennung Ladegerät ab 13,6V 304 #elif defined SYSTEM_VOLTAGE_48V315 #elif defined DEFAULT_PARAMETER_SYSTEM_VOLTAGE_48V 305 316 /* AUX SETPOINT ON */ 54400, // Erkennung Ladegerät ab 13,6V 306 317 #else 307 #error No valid device type 318 #error "No valid default voltage for factory parameter" 308 319 #endif 309 320 /* AUX SETPOINT OFF */ 100, // Batterie Entladung wird erkannt bei -100mA … … 396 407 eepromData.changedData.currentOffsetFast = data->s.parameter.batteryCurrentOffsetFast; 397 408 eepromData.changedData.currentGainFast = data->s.parameter.batteryCurrentGainCorrectionFaktorFast; 409 eepromData.changedData.batteryVoltageOffset = data->s.parameter.batteryVoltageOffset; 410 eepromData.changedData.batteryVoltageFastOffset = data->s.parameter.batteryVoltageFastOffset; 411 eepromData.changedData.shuntVoltageOffset = data->s.parameter.shuntVoltageOffset; 412 eepromData.changedData.shuntVoltageFastOffset = data->s.parameter.shuntVoltageFastOffset; 413 398 414 399 415 eepromData.changedData.batteryCurrentGainRefTempShunt = data->s.parameter.batteryCurrentGainRefTempShunt; … … 510 526 dataToStore->changedData.currentGainFast = data->s.parameter.batteryCurrentGainCorrectionFaktorFast; 511 527 528 dataToStore->changedData.batteryVoltageOffset = data->s.parameter.batteryVoltageOffset; 529 dataToStore->changedData.batteryVoltageFastOffset = data->s.parameter.batteryVoltageFastOffset; 530 dataToStore->changedData.shuntVoltageOffset = data->s.parameter.shuntVoltageOffset; 531 dataToStore->changedData.shuntVoltageFastOffset = data->s.parameter.shuntVoltageFastOffset; 512 532 513 533 // AH COUNTER Einstellungen … … 615 635 data->s.parameter.batteryCurrentGainCorrectionFaktorFast = dataToStore->changedData.currentGainFast; 616 636 637 data->s.parameter.batteryVoltageOffset = dataToStore->changedData.batteryVoltageOffset; 638 data->s.parameter.batteryVoltageFastOffset = dataToStore->changedData.batteryVoltageFastOffset; 639 data->s.parameter.shuntVoltageOffset = dataToStore->changedData.shuntVoltageOffset; 640 data->s.parameter.shuntVoltageFastOffset = dataToStore->changedData.shuntVoltageFastOffset; 617 641 //Einstellungenm für AH counter 618 642 data->s.parameter.cef = dataToStore ->changedData.cef; -
trunk/fw_g473rct/SES/src/esr.c
r71 r73 4 4 #include "esr.h" 5 5 #include <stdlib.h> 6 #include <stdio.h> 6 7 #include "main.h" 7 #include "battery_voltage .h"8 #include "battery_voltage_fast.h" 8 9 #include "fast_current.h" 9 #include "stdio.h"10 10 11 #define I_MULTIPLIER ((int64_t) VREF / FAST_CURRENT_SHUNT_RESISTOR / FAST_CURRENT_I_SENSE_GAIN / FAST_CURRENT_ADC_RESOLUTION) 12 #define U_MULTIPLIER ((int64_t) VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER / BATTERY_VOLTAGE_FAST_ADC_RESOLUTION ) 11 13 12 14 int32_t current_buffer[SAMPLE_ARRAY_SIZE]; … … 14 16 15 17 16 extern uint32_t adc1Data[SAMPLE_ARRAY_SIZE];17 extern uint32_t adc2Data[SAMPLE_ARRAY_SIZE];18 extern uint32_t adc4Data[SAMPLE_ARRAY_SIZE];18 extern int32_t adc1Data[SAMPLE_ARRAY_SIZE]; 19 extern int32_t adc2Data[SAMPLE_ARRAY_SIZE]; 20 extern int32_t adc4Data[SAMPLE_ARRAY_SIZE]; 19 21 20 21 //int16_t ESR_Exec(void)22 //{23 24 25 // static int32_t last_refresh;26 // int x;27 28 // //Anzeige vor wieviel Sekunden zuletzt aktualisiert wurd.29 // sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh;30 31 // for (x=SAMPLE_ARRAY_SIZE-1; x>0; x--)32 // {33 // current_buffer[x] = current_buffer[x-1];34 // voltage_buffer[x] = voltage_buffer[x-1];35 // }36 37 // // Neue Werte ins array aufnehmen38 // current_buffer[0] = sys_data.s.values.batteryCurrent;39 // voltage_buffer[0] = sys_data.s.values.batteryVoltage;40 41 42 // //Suche Min und max werte im Array43 // int32_t minU=INT32_MAX;44 // int32_t maxU=0;45 // int32_t minI=INT32_MAX;46 // int32_t maxI=0;47 // int32_t minIPos = -1;48 // int32_t maxdIPos = -1;49 // int32_t minUPos = -1;50 // int32_t maxUPos = -1;51 52 // //Suche min und max werte53 // for (x=0; x < SAMPLE_ARRAY_SIZE; x++)54 // {55 // if (abs(current_buffer[x]) < minI) { minI = abs(current_buffer[x]); minIPos = x; }56 // if (abs(current_buffer[x]) >= maxI) { maxI = abs(current_buffer[x]); maxdIPos = x; }57 // if (abs(voltage_buffer[x]) < minU) { minU = abs(voltage_buffer[x]); minUPos = x; }58 // if (abs(voltage_buffer[x]) > maxU) { maxU = abs(voltage_buffer[x]); maxUPos = x; }59 // }60 61 62 // //Suche Zeitpunkt der größten Änderung in I63 64 // //Delta berechnen65 // int32_t dI = abs (maxI - minI);66 // int32_t dU = abs (maxU - minU);67 68 // //Minimale Belastung Prüfen ob es genügent Änderungen gab69 // // 1/20 des Nennstroms70 // // Bei 100Ah Batterie mit 0,5 Std discharge --> 50A --> /20 =2,5 A71 // int32_t min_dI;72 // min_dI = sys_data.s.parameter.cellCapacity / sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom in mA73 // min_dI = min_dI / 20 ;74 75 // int32_t min_dU = 25;76 77 // if( dI < min_dI)78 // {79 80 // return -1;81 // }82 83 // printf("1)dI change!\r\n");84 85 // if (dU < min_dU) {86 // return -2;87 // }88 89 // //printf("dU change!\r\n");90 91 92 // int32_t dIMax=-1;93 // int32_t dIx=-1;;94 // int32_t dIMaxPos=-1;95 96 // for (x=0; x < (SAMPLE_ARRAY_SIZE-1); x++)97 // {98 // dIx = abs(current_buffer[x+1] - current_buffer[x]);99 // if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; }100 // }101 102 103 104 // if (dIMaxPos == SAMPLE_ARRAY_SIZE / 2)105 // {106 // //ESR berechnen!107 // sys_data.s.values.esr = ( (double)dU / (double) dI) * 1000;108 // last_refresh = sys_data.s.values.onTime;109 110 111 // for (x=0; x < SAMPLE_ARRAY_SIZE; x++)112 // {113 // sys_data.s.values.current_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc1Data[x];114 // sys_data.s.values.voltage_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc2Data[x];115 // }116 117 118 119 // }120 // return 0;121 //}122 22 123 23 … … 125 25 { 126 26 127 printf("esr\r\n");27 // printf("esr\r\n"); 128 28 static int32_t last_refresh; 129 29 int x; … … 137 37 //Suche Min und max werte im Array 138 38 int32_t minUBatt=INT32_MAX; 139 int32_t maxUBatt= 0;39 int32_t maxUBatt=INT32_MIN; 140 40 int32_t minUOut=INT32_MAX; 141 int32_t maxUOut= 0;41 int32_t maxUOut=INT32_MIN; 142 42 int32_t minI=INT32_MAX; 143 int32_t maxI= 0;43 int32_t maxI=INT32_MIN; 144 44 int32_t minIPos = -1; 145 int32_t max dIPos = -1;45 int32_t maxIPos = -1; 146 46 int32_t minUBattPos = -1; 147 47 int32_t maxUBattPos = -1; … … 149 49 int32_t maxUOutPos = -1; 150 50 51 52 //Entferne Offset 53 for (x=0; x < SAMPLE_ARRAY_SIZE -1; x++) 54 { 55 adc1Data[x] = adc1Data[x] - FAST_CURRENT_ADC_OFFSET; 56 adc2Data[x] = adc2Data[x] - BATTERY_VOLTAGE_FAST_ADC_OFFSET; 57 adc4Data[x] = adc4Data[x] - BATTERY_VOLTAGE_FAST_ADC_OFFSET; 58 } 59 60 61 151 62 //Suche min und max werte 152 63 for (x=0; x < SAMPLE_ARRAY_SIZE -1; x++) 153 64 { 154 if (adc1Data[x] < minI) { minI = adc1Data[x]; minIPos = x; }155 if (adc1Data[x] >= maxI) { maxI = adc1Data[x]; max dIPos = x; }156 if (adc2Data[x] < minUBatt) { minUBatt = adc2Data[x]; minUBattPos = x; }157 if (adc2Data[x] > maxUBatt) { maxUBatt = adc2Data[x]; maxUBattPos = x; }158 if (adc4Data[x] < minUOut) { minUOut = adc4Data[x]; minUOutPos = x; }159 if (adc4Data[x] > maxUOut) { maxUOut = adc4Data[x]; maxUOutPos = x; }65 if (adc1Data[x] <= minI) { minI = adc1Data[x]; minIPos = x; } 66 if (adc1Data[x] >= maxI) { maxI = adc1Data[x]; maxIPos = x; } 67 if (adc2Data[x] <= minUBatt) { minUBatt = adc2Data[x]; minUBattPos = x; } 68 if (adc2Data[x] >= maxUBatt) { maxUBatt = adc2Data[x]; maxUBattPos = x; } 69 if (adc4Data[x] <= minUOut) { minUOut = adc4Data[x]; minUOutPos = x; } 70 if (adc4Data[x] >= maxUOut) { maxUOut = adc4Data[x]; maxUOutPos = x; } 160 71 } 161 162 163 72 164 73 165 74 //Delta berechnen 166 int32_t dI = maxI - minI; 167 168 //Nehme nicht mehr die gesamte maximale Differenz der Spannungen, sondern nehme das delt U wo auch das Delta I gemessen wurde 169 //Funktioniert nur bei Synchroner Messug von Strom und Spannung 170 //int32_t dU = maxU - minU; 171 int32_t dUBatt = adc2Data[maxdIPos] - adc2Data[minIPos]; 172 int32_t dUOut = adc4Data[maxdIPos] - adc4Data[minIPos]; 75 int32_t dI; 76 int32_t dUBatt; 77 int32_t dUOut; 78 79 if (maxIPos > minIPos) 80 { 81 dI = maxI - minI; 82 //Nehme nicht mehr die gesamte maximale Differenz der Spannungen, sondern nehme das delt U wo auch das Delta I gemessen wurde 83 //Funktioniert nur bei Synchroner Messug von Strom und Spannung 84 //int32_t dU = maxU - minU; 85 dUBatt= adc2Data[maxIPos] - adc2Data[minIPos]; 86 dUOut= adc4Data[maxIPos] - adc4Data[minIPos]; 87 } 88 else 89 { 90 dI = minI - maxI; 91 dUBatt= adc2Data[minIPos] - adc2Data[maxIPos]; 92 dUOut= adc4Data[minIPos] - adc4Data[maxIPos]; 93 } 94 173 95 174 96 //Umrechnung in mV / mA 175 dI = dI * ((double) VREF / FAST_CURRENT_SHUNT_RESISTOR / FAST_CURRENT_I_SENSE_GAIN / FAST_CURRENT_ADC_RESOLUTION); 176 dI = dI * (sys_data.s.parameter.batteryCurrentGainCorrectionFaktor / 1000000.0); 177 178 dUBatt = dUBatt * (double )VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER / BATTERY_VOLTAGE_ADC_RESOLUTION ; 179 dUOut = dUOut * (double )VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER / BATTERY_VOLTAGE_ADC_RESOLUTION ; 97 dI = dI * I_MULTIPLIER; 98 dUBatt = dUBatt * U_MULTIPLIER; 99 dUOut = dUOut * U_MULTIPLIER; 180 100 181 101 //Minimale Belastung Prüfen ob es genügent Änderungen gab … … 184 104 int32_t min_dI; 185 105 min_dI = sys_data.s.parameter.cellCapacity / sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom in mA 186 min_dI = min_dI / 10 0;106 min_dI = min_dI / 10 ; 187 107 188 108 … … 195 115 } 196 116 197 printf("2)dI change!\r\n");198 117 118 119 120 int absMax = abs(maxI); 121 int absMin = abs(minI); 122 123 //Suche die Spitze 124 //if (absMax > absMin){ 125 // //Der größte absolut wert steht in maxI 126 // //schauen ob die spitze nicht am Anfang oder Ende des arrays ist 127 // if ((maxIPos < 10) || (maxIPos > 53)) 128 // { 129 //return -3; 130 // } 131 132 //} 133 //else 134 //{ 135 136 // if ((minIPos < 10) || (minIPos > 53)) 137 // { 138 //return -3; 139 // } 140 //} 199 141 //if (abs(dU) < min_dU) { 200 142 // return -2; … … 204 146 205 147 206 int32_t dIMax=-1;207 int32_t dIx=-1;;208 int32_t dIMaxPos=-1;148 // int32_t dIMax=-1; 149 // int32_t dIx=-1;; 150 // int32_t dIMaxPos=-1; 209 151 210 152 211 153 212 154 //Finde Position der flanke 213 for (x=0; x < (SAMPLE_ARRAY_SIZE-1); x++)214 {215 dIx = adc1Data[x+1] - adc1Data[x];216 if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; }217 }155 // for (x=0; x < (SAMPLE_ARRAY_SIZE-2); x++) 156 // { 157 // dIx = adc1Data[x+1] - adc1Data[x]; 158 // if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; } 159 // } 218 160 219 161 sys_data.s.values.neg_I_peak = (minI ) * I_MULTIPLIER / 10; 162 sys_data.s.values.pos_I_peak = (maxI ) * I_MULTIPLIER / 10 ; 163 164 sys_data.s.values.neg_U_Batt_peak = (minUBatt ) * U_MULTIPLIER / 10; 165 sys_data.s.values.pos_U_Batt_peak = (maxUBatt ) * U_MULTIPLIER / 10; 166 sys_data.s.values.neg_U_Shunt_peak = (minUOut ) * U_MULTIPLIER / 10; 167 sys_data.s.values.pos_U_Shunt_peak = (maxUOut ) * U_MULTIPLIER / 10; 168 169 sys_data.s.values.neg_I_Buffer_pos = minIPos; 170 sys_data.s.values.pos_I_Buffer_pos = maxIPos; 171 220 172 221 173 222 174 //ESR berechnen! 223 sys_data.s.values.esr_ fast =( (double)dUBatt / (double) dI) * 1000;224 sys_data.s.values.esr =( (double)dUOut / (double) dI) * 1000;175 sys_data.s.values.esr_batt = ( (double)dUBatt / (double) dI) * 1000; 176 sys_data.s.values.esr_shunt = ( (double)dUOut / (double) dI) * 1000; 225 177 last_refresh = sys_data.s.values.onTime; 226 178 … … 228 180 for (x=0; x < SAMPLE_ARRAY_SIZE; x++) 229 181 { 230 sys_data.s.values.current_buffer_fast[x] = (int32_t) adc1Data[x] - FAST_CURRENT_ADC_OFFSET ; 231 sys_data.s.values.voltage_buffer_fast[x] = (int32_t) adc2Data[x] - BATTERY_VOLTAGE_ADC_OFFSET ; 182 sys_data.s.values.current_buffer[x] = adc1Data[x] ; 183 sys_data.s.values.voltage_buffer_batt[x] = adc2Data[x] ; 184 sys_data.s.values.voltage_buffer_shunt[x] = adc4Data[x] ; 232 185 } 233 186 234 187 188 //Auswertung darf nur erfolgen wenn Singulares Erreigniss nicht am Anfang oder Ende des Buffers erfolgt. 189 //Also z.B. bei der Belastung mit elektronischer Last. Da ansonsten eventuell nicht der Beginn der Kurve mit aufgezeichnet wird 190 //printf("delta I: %d, deltaUBatt=%d, deltaUOut=%d,posMax=%d; posMin=%d, esr1=%d, esr2=%d \r\n",dI,dUBatt,dUOut,maxIPos, minIPos,sys_data.s.values.esr_batt,sys_data.s.values.esr_shunt); 235 191 236 192 -
trunk/fw_g473rct/SES/src/fast_current.c
r26 r73 32 32 33 33 // --- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------ 34 void CurrentOffsetCal( uint32_t newVal)34 void CurrentOffsetCal(int32_t newVal) 35 35 { 36 36 sys_data.s.parameter.batteryCurrentOffsetFast = newVal-FAST_CURRENT_ADC_OFFSET; 37 37 } 38 38 39 void CurrentGainCal( uint32_t newVal)39 void CurrentGainCal(int32_t newVal) 40 40 { 41 41 double correction; 42 42 double valWithoutGainCorrection; 43 43 44 valWithoutGainCorrection = ( (int32_t)newVal - FAST_CURRENT_ADC_OFFSET - sys_data.s.parameter.batteryCurrentOffsetFast) * VREF ;44 valWithoutGainCorrection = ( newVal - FAST_CURRENT_ADC_OFFSET - sys_data.s.parameter.batteryCurrentOffsetFast) * VREF ; 45 45 valWithoutGainCorrection = valWithoutGainCorrection / FAST_CURRENT_ADC_RESOLUTION; 46 46 valWithoutGainCorrection = valWithoutGainCorrection / FAST_CURRENT_I_SENSE_GAIN ; … … 51 51 52 52 } 53 void FAST_CURRENT_Exec( uint32_t newVal )53 void FAST_CURRENT_Exec(int32_t newVal ) 54 54 { 55 55 56 56 //Umrechung auf Strom 57 57 double temp_current; 58 temp_current = ( (int32_t)newVal - FAST_CURRENT_ADC_OFFSET - sys_data.s.parameter.batteryCurrentOffsetFast) * VREF ;58 temp_current = ( newVal - FAST_CURRENT_ADC_OFFSET - sys_data.s.parameter.batteryCurrentOffsetFast) * VREF ; 59 59 temp_current = temp_current / FAST_CURRENT_ADC_RESOLUTION; 60 60 temp_current = temp_current / FAST_CURRENT_I_SENSE_GAIN ; -
trunk/fw_g473rct/SES/src/int_bat_voltage.c
r24 r73 35 35 36 36 // --- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------ 37 void INT_BAT_VOLTAGE_Exec( uint32_t newval)37 void INT_BAT_VOLTAGE_Exec(int32_t newval) 38 38 { 39 39 // Messung Externe Spannung basierend auf 3,3V Versorgungsspannung -
trunk/fw_g473rct/SES/src/outputs.c
r55 r73 76 76 void OUTPUTS_OverwriteChargeCtrl_Disabled(void) 77 77 { 78 79 78 80 GPIO_InitTypeDef GPIO_InitStruct = {0}; 79 81 GPIO_InitStruct.Pin = OVERWRITE_CHARGE_CTRL_Pin; … … 202 204 printf("OUTPUT LVP OK\n"); 203 205 sys_data.s.values.lvpState = OUTPUTS_LVP_OK; 206 #ifndef NO_TRISTATE_OUTPUTS 204 207 OUTPUTS_OverwriteDischargeCtrl_Disabled(); 208 #else 209 OUTPUTS_OverwriteDischargeCtrl_DischargeEnabled(); 210 #endif 205 211 } 206 212 } … … 295 301 printf("OUTPUT OVP OK\n"); 296 302 sys_data.s.values.ovpState = OUTPUTS_OVP_OK; 297 OUTPUTS_OverwriteChargeCtrl_Disabled(); // externer steuerung 303 #ifndef NO_TRISTATE_OUTPUTS 304 OUTPUTS_OverwriteChargeCtrl_Disabled(); 305 #else 306 OUTPUTS_OverwriteChargeCtrl_ChargeEnabled(); 307 #endif 298 308 } 299 309 } -
trunk/fw_g473rct/SES/src/shunt_voltage_fast.c
r72 r73 12 12 #include <stdio.h> 13 13 #include "sysdata.h" 14 #include "shunt_voltage .h"14 #include "shunt_voltage_fast.h" 15 15 #include "adc.h" 16 #include "tim.h" 16 17 // --- EXTERNE VARIABLEN -------------------------------------------------------- 18 extern __IO int32_t adc4Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1_CRC"))); 19 // --- LOKALE DEFINES - bitte hier dokumentieren -------------------------------- 20 #define SHUNT_VOLTAGE_FAST_ADC_RESOLUTION 65536 21 #define SHUNT_VOLTAGE_FAST_ADC_OFFSET 32768 17 22 18 // --- LOKALE DEFINES - bitte hier dokumentieren --------------------------------19 #define ADC_RESOLUTION 32768 //65536/2 da im differential mode20 #define ADC_OFFSET 3276821 22 #if defined SYSTEM_VOLTAGE_12V23 #define SHUNT_VOLTAGE_DIVIDER 6.024 #elif defined SYSTEM_VOLTAGE_24V25 #define SHUNT_VOLTAGE_DIVIDER 11.026 #elif defined SYSTEM_VOLTAGE_48V27 #define SHUNT_VOLTAGE_DIVIDER 21.028 #else29 #error "System voltage not defined"30 #endif31 23 32 24 … … 37 29 38 30 // --- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------ 31 39 32 40 33 // --- LOKALE FUNKTIONS PROTOTYPEN ---------------------------------------------- … … 52 45 53 46 54 //#define SHUNT_FILTER 12855 47 56 48 57 void SHUNT_VOLTAGE_ Exec(int32_t newval)49 void SHUNT_VOLTAGE_FAST_Exec(int32_t newval) 58 50 { 59 sys_data.s.values.shuntVoltage = ((newval-ADC_OFFSET) * VREF * SHUNT_VOLTAGE_DIVIDER ) / ADC_RESOLUTION;51 sys_data.s.values.shuntVoltageFast = ((newval - SHUNT_VOLTAGE_FAST_ADC_OFFSET) * (int64_t) (VREF) * SHUNT_VOLTAGE_VOLTAGE_DIVIDER / SHUNT_VOLTAGE_FAST_ADC_RESOLUTION) - sys_data.s.parameter.shuntVoltageFastOffset ; 60 52 53 } 54 55 void SHUNT_VOLTAGE_FAST_ZeroCal(void) 56 { 57 sys_data.s.parameter.shuntVoltageFastOffset = sys_data.s.values.shuntVoltageFast + sys_data.s.parameter.shuntVoltageFastOffset ; 61 58 } 62 59 -
trunk/fw_g473rct/SES/src/sysdata.c
r65 r73 29 29 sys_data.s.values.detectedEnergy = -1; //(int32_t)sys_data.s.parameter.battEnergy; 30 30 31 sys_data.s.values.esr = -1;32 sys_data.s.values.esr_ fast= -1;31 sys_data.s.values.esr_batt = -1; 32 sys_data.s.values.esr_shunt= -1; 33 33 34 34 sys_data.s.values.selfDischarge = -1;
Note:
See TracChangeset
for help on using the changeset viewer.
