Changeset 73 for trunk/fw_g473rct/Core/Src/main.c
- Timestamp:
- Aug 4, 2026, 1:53:58 PM (25 hours ago)
- File:
-
- 1 edited
-
trunk/fw_g473rct/Core/Src/main.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/Core/Src/main.c
r71 r73 42 42 #include "modbus.h" 43 43 #include "chip_temperature.h" 44 #include "battery_voltage .h"44 #include "battery_voltage_fast.h" 45 45 #include "ads1260.h" 46 #include "shunt_voltage .h"46 #include "shunt_voltage_fast.h" 47 47 #include "fast_current.h" 48 48 #include "int_bat_voltage.h" … … 92 92 93 93 94 __IO uint32_t adc1Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1_CRC")));95 __IO uint32_t adc2Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1_CRC")));96 __IO uint32_t adc3Data[3];97 __IO uint32_t adc4Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1_CRC")));98 __IO uint32_t adc5Data[4];94 __IO int32_t adc1Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1_CRC"))); 95 __IO int32_t adc2Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1_CRC"))); 96 __IO int32_t adc3Data[3]; 97 __IO int32_t adc4Data[SAMPLE_ARRAY_SIZE] __attribute__((section(".RAM1_CRC"))); 98 __IO int32_t adc5Data[4]; 99 99 int silentmode = 0; 100 100 static volatile uint32_t newADC124Data = 0; … … 162 162 163 163 /* USER CODE BEGIN Init */ 164 164 /* ------------------------------------------ INFO ----------------- 165 - Einige Module sind zum Stromsparen ausgeschaltet 166 167 */ 165 168 /* USER CODE END Init */ 166 169 … … 187 190 MX_CRC_Init(); 188 191 MX_RTC_Init(); 189 //MX_IWDG_Init();192 MX_IWDG_Init(); 190 193 MX_TIM3_Init(); 194 #ifndef NO_USB_SUPPORT 191 195 MX_USB_Device_Init(); 192 196 MX_UCPD1_Init(); 197 #endif 193 198 /* USER CODE BEGIN 2 */ 199 194 200 printf("Test debug io\r\n"); 195 printf("adc samplerate core clock: %d kHz\r\n", (uint32_t) GetADCSampleRate() / 1000U); 201 196 202 SYS_DATA_Init(); 197 203 WH_COUNTER_Init(); … … 225 231 mbInit(&modbusData, sys_data.s.parameter.baudrate, sys_data.s.parameter.parityMode, sys_data.s.parameter.stopBit, &huart2); 226 232 HAL_IWDG_Refresh(&hiwdg); 233 HAL_Delay(500); 234 HAL_IWDG_Refresh(&hiwdg); 235 227 236 // STM32G0 Chiptemperatur Kalibrierung 228 237 CHIP_TEMPERATURE_Calibration(); 229 238 230 HAL_ADCEx_Calibration_Start(&hadc1, ADC_DIFFERENTIAL_ENDED); 231 HAL_ADCEx_Calibration_Start(&hadc2, ADC_DIFFERENTIAL_ENDED); 232 HAL_ADCEx_Calibration_Start(&hadc3, ADC_SINGLE_ENDED); 233 HAL_ADCEx_Calibration_Start(&hadc4, ADC_DIFFERENTIAL_ENDED); 234 HAL_ADCEx_Calibration_Start(&hadc5, ADC_SINGLE_ENDED); 239 if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_DIFFERENTIAL_ENDED) != HAL_OK) Error_Handler(); 240 if (HAL_ADCEx_Calibration_Start(&hadc2, ADC_DIFFERENTIAL_ENDED) != HAL_OK) Error_Handler(); 241 if (HAL_ADCEx_Calibration_Start(&hadc3, ADC_SINGLE_ENDED) != HAL_OK) Error_Handler(); 242 if (HAL_ADCEx_Calibration_Start(&hadc4, ADC_DIFFERENTIAL_ENDED) != HAL_OK) Error_Handler(); 243 if (HAL_ADCEx_Calibration_Start(&hadc5, ADC_SINGLE_ENDED) != HAL_OK) Error_Handler(); 244 245 246 247 printf("%u, %u, %u\n", LL_ADC_GetCalibrationFactor(ADC1, LL_ADC_DIFFERENTIAL_ENDED), LL_ADC_GetCalibrationFactor(ADC2, LL_ADC_DIFFERENTIAL_ENDED), LL_ADC_GetCalibrationFactor(ADC4, LL_ADC_DIFFERENTIAL_ENDED)); 235 248 HAL_IWDG_Refresh(&hiwdg); 249 236 250 237 251 //SET_BIT(hadc2.Instance->CFGR, ADC_CFGR_DMAEN); //Enable DMA transfer for ADC slave (ADC12_CCR.MDMA = 0b00 -> MDMA mode disabled) … … 267 281 268 282 /* USBPD initialisation ---------------------------------*/ 283 #ifndef NO_USB_SUPPORT 269 284 MX_USBPD_Init(); 270 285 #endif 271 286 /* Infinite loop */ 272 287 /* USER CODE BEGIN WHILE */ … … 274 289 { 275 290 /* USER CODE END WHILE */ 291 #ifndef NO_USB_SUPPORT 276 292 USBPD_DPM_Run(); 277 293 #endif 278 294 /* USER CODE BEGIN 3 */ 279 295 HAL_IWDG_Refresh(&hiwdg); 280 296 if (newADC124Data == 7) 281 297 { 282 SHUNT_VOLTAGE_Exec( adc4Data[0]); 298 299 SHUNT_VOLTAGE_FAST_Exec( adc4Data[SAMPLE_ARRAY_SIZE-1]); 283 300 //Mit ADC_DIV2,Sample time 12,5Cycklen, ADC Clock 50Mhz, Oversampling 256 284 301 //Tconv = 6400 Takte = 0,128ms Pro Konvertierung. Also für 100 messwerte 12,8mS 285 BATTERY_VOLTAGE_ Exec( adc2Data[SAMPLE_ARRAY_SIZE-1]);302 BATTERY_VOLTAGE_FAST_Exec( adc2Data[SAMPLE_ARRAY_SIZE-1]); 286 303 FAST_CURRENT_Exec(adc1Data[SAMPLE_ARRAY_SIZE-1]); 287 304 ESR_FAST_Exec(); … … 290 307 newADC124Data = 0; 291 308 292 //Auskommentiert, bringt komiscxherweise Spannungsschwankungen, beim loggen,... Spannung springt bis zu 50mv293 // HAL_ADCEx_Calibration_Start(&hadc1, ADC_DIFFERENTIAL_ENDED);294 // HAL_ADCEx_Calibration_Start(&hadc2, ADC_DIFFERENTIAL_ENDED);295 // HAL_ADCEx_Calibration_Start(&hadc4, ADC_DIFFERENTIAL_ENDED);296 297 298 309 299 310 … … 301 312 if (HAL_ADC_Start_DMA(&hadc2,(uint32_t*)adc2Data,SAMPLE_ARRAY_SIZE)) Error_Handler(); //Start ADC interleaved mode 302 313 if (HAL_ADC_Start_DMA(&hadc4,(uint32_t*)adc4Data,SAMPLE_ARRAY_SIZE)) Error_Handler(); //Start ADC interleaved mode 314 315 303 316 } 304 317 … … 368 381 if (silentmode == 0) 369 382 { 370 //HAL_GPIO_TogglePin(LED_FUNCTION_GPIO_Port, LED_FUNCTION_Pin);383 HAL_GPIO_TogglePin(LED_FUNCTION_GPIO_Port, LED_FUNCTION_Pin); 371 384 //HAL_GPIO_TogglePin(AUX_EN_GPIO_Port, AUX_EN_Pin); 372 385 } … … 425 438 case COMMAND_GOTO_SYS_BOOTLOADER: bootLoaderMark = GOTO_SYSTEM_BOOTLOADER_MARK; 426 439 HAL_NVIC_SystemReset(); break; 427 case COMMAND_SET_VOLTAGE_MEAS_TO_ZERO: BATTERY_VOLTAGE_ZeroCal(); break; 440 case COMMAND_SET_VOLTAGE_MEAS_TO_ZERO: BATTERY_VOLTAGE_FAST_ZeroCal(); 441 ADS1260_BatteryVoltageZeroCal(); 442 ADS1260_ShuntVoltageZeroCal(); 443 SHUNT_VOLTAGE_FAST_ZeroCal(); 444 break; 428 445 429 446 default: printf("UNKNOWN COMMAND\n"); … … 475 492 } 476 493 494 //HAL_SuspendTick(); 495 //HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); 496 //HAL_ResumeTick(); 497 498 499 #ifndef NO_USB_SUPPORT 477 500 if (rb_available(&usb_in_buff) > 8) // 8 minimum packet size in Modbus RTU RHR/WHR 478 501 { // Theres something in our USB buffer. We need to process it 479 502 processUSB(&usb_in_buff, &usb_out_buff); 480 503 } 504 481 505 482 506 if (rb_available(&usb_out_buff) > 0) … … 499 523 lastTime_ms = HAL_GetTick(); 500 524 } 501 525 #endif 502 526 } 503 527 /* USER CODE END 3 */ … … 563 587 /* USER CODE BEGIN 4 */ 564 588 589 #ifndef NO_USB_SUPPORT 565 590 void processUSB(ring_buffer_t* const ring_in_buff, ring_buffer_t* const ring_out_buff) 566 591 { … … 719 744 } 720 745 } 721 746 #endif 722 747 //------------------------------------------------------------------------------ 723 748 … … 804 829 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) 805 830 { 806 if (hadc->Instance ==ADC1)831 if (hadc->Instance == ADC1) 807 832 { 808 833 newADC124Data |= 1; … … 814 839 else if (hadc->Instance==ADC3) 815 840 { 816 newADC3Data =1;841 newADC3Data = 1; 817 842 } 818 843 else if (hadc->Instance==ADC4) 819 844 { 820 newADC124Data |= 4;845 newADC124Data |= 4; 821 846 } 822 847 else if (hadc->Instance==ADC5) 823 848 { 824 newADC5Data =1;849 newADC5Data = 1; 825 850 } 826 851 }
Note:
See TracChangeset
for help on using the changeset viewer.
