adc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. ******************************************************************************
  3. * File Name : ADC.h
  4. * Description : This file provides code for the configuration
  5. * of the ADC instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __adc_H
  21. #define __adc_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "main.h"
  27. /* USER CODE BEGIN Includes */
  28. #include <math.h>
  29. /* USER CODE END Includes */
  30. extern ADC_HandleTypeDef hadc1;
  31. extern ADC_HandleTypeDef hadc2;
  32. extern ADC_HandleTypeDef hadc3;
  33. /* USER CODE BEGIN Private defines */
  34. #define ADC1_CHANEL_COUNT 1
  35. #define ADC1_SAMPLE_COUNT 1000
  36. #define ADC2_CHANEL_COUNT 2
  37. #define ADC2_SAMPLE_COUNT 256
  38. #define ADC3_CHANEL_COUNT 5
  39. #define ADC3_SAMPLE_COUNT 180
  40. #define LIMIT_MOVE_FILTER 8
  41. #define CURRENT_LIMIT_MOVE_FILTER 4
  42. #define VOLTAGE_LIMIT_MOVE_FILTER 8
  43. typedef struct{
  44. uint16_t idx_put;
  45. uint32_t buffer[LIMIT_MOVE_FILTER];
  46. uint32_t value;
  47. }MOVE_AVG_FILTER;
  48. /* USER CODE END Private defines */
  49. void MX_ADC1_Init(void);
  50. void MX_ADC2_Init(void);
  51. void MX_ADC3_Init(void);
  52. /* USER CODE BEGIN Prototypes */
  53. extern uint8_t filter_move_avg(MOVE_AVG_FILTER *data, uint32_t value);
  54. extern uint8_t Current_filter_move_avg(MOVE_AVG_FILTER *data, uint32_t value) ;
  55. extern uint8_t Voltage_filter_move_avg(MOVE_AVG_FILTER *data, uint32_t value) ;
  56. //extern uint16_t vRms_cal(uint16_t *data, uint16_t length);
  57. extern uint16_t cRms_cal(uint16_t *data, uint16_t length);
  58. extern uint16_t GFRms_cal(uint16_t *data, uint16_t length);
  59. extern uint16_t avg_cal(uint16_t *data, uint16_t length);
  60. #ifdef FUNC_TEMP_SENSOR_WITH_NEG_VALUE
  61. extern int16_t getTemperature(uint16_t adc_raw);
  62. #else
  63. extern uint16_t getTemperature(uint16_t adc_raw);
  64. #endif
  65. extern uint16_t vRms_cal2(uint16_t *data, uint16_t length) ;
  66. //extern uint16_t cRms_cal2(uint16_t *data, uint16_t length) ;
  67. extern uint16_t RlyVmax_cal(uint16_t *data, uint16_t length) ;
  68. extern uint16_t avg_v_cal(uint16_t *data, uint16_t length) ;
  69. extern uint32_t ADC1_Buffer[ADC1_CHANEL_COUNT*ADC1_SAMPLE_COUNT];
  70. extern uint32_t ADC2_Buffer[ADC2_CHANEL_COUNT*ADC2_SAMPLE_COUNT];
  71. extern uint16_t ADC2_Buffer_Each[ADC2_CHANEL_COUNT][ADC2_SAMPLE_COUNT];
  72. extern uint32_t ADC3_Buffer[ADC3_CHANEL_COUNT*ADC3_SAMPLE_COUNT];
  73. extern uint16_t ADC3_Buffer_Each[ADC3_CHANEL_COUNT][ADC3_SAMPLE_COUNT];
  74. extern uint8_t isDMAEnd_ADC1;
  75. extern uint8_t isDMAEnd_ADC2;
  76. extern uint8_t isDMAEnd_ADC3;
  77. struct ADC_VALUE{
  78. MOVE_AVG_FILTER ADC3_IN9_Voltage_L1;
  79. MOVE_AVG_FILTER ADC3_IN14_UL_1998;
  80. MOVE_AVG_FILTER ADC3_IN15_Temp;
  81. MOVE_AVG_FILTER ADC3_IN4_GMI_VL1;
  82. MOVE_AVG_FILTER ADC3_IN5_Current_L2;
  83. MOVE_AVG_FILTER ADC3_IN6_Current_L3;
  84. MOVE_AVG_FILTER ADC3_IN7_Current_L1;
  85. MOVE_AVG_FILTER ADC3_IN8_Voltage_L2;
  86. MOVE_AVG_FILTER ADC3_IN10_Voltage_L3;
  87. MOVE_AVG_FILTER ADC1_IN4_CP;
  88. MOVE_AVG_FILTER ADC2_IN5_Welding;
  89. MOVE_AVG_FILTER ADC2_IN6_GF;
  90. };
  91. extern struct ADC_VALUE adc_value;
  92. extern uint16_t ADCWDGHighThreshold;
  93. extern uint16_t ADCWDGLowThreshold;
  94. extern uint8_t is60Hz;
  95. /* USER CODE END Prototypes */
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif /*__ adc_H */
  100. /**
  101. * @}
  102. */
  103. /**
  104. * @}
  105. */
  106. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/