adc_global.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * adc_global.h
  3. *
  4. * Created on: Jan 12, 2021
  5. * Author: David Original work by Jose (PTDreamer), 2017
  6. */
  7. #ifndef GENERALIO_ADC_GLOBAL_H_
  8. #define GENERALIO_ADC_GLOBAL_H_
  9. #include "main.h"
  10. typedef struct{
  11. volatile uint16_t *adc_buffer; // Ptr to ADC buffer data
  12. volatile uint16_t prev_avg;
  13. volatile uint16_t last_avg; // Filtered (EMA calculation)
  14. volatile uint16_t prev_raw;
  15. volatile uint16_t last_raw; // Unfiltered, for quick Iron detection
  16. volatile uint32_t EMA_of_Input; // Stored filter data (acumulator for EMA)
  17. } ADCDataTypeDef_t;
  18. typedef struct {
  19. #ifdef ADC_1st
  20. uint16_t ADC_1st;
  21. #endif
  22. #ifdef ADC_2nd
  23. uint16_t ADC_2nd;
  24. #endif
  25. #ifdef ADC_3rd
  26. uint16_t ADC_3rd;
  27. #endif
  28. #ifdef ADC_4th
  29. uint16_t ADC_4th;
  30. #endif
  31. } adc_measures_t;
  32. extern volatile ADCDataTypeDef_t TIP;
  33. #ifdef USE_VIN
  34. extern volatile ADCDataTypeDef_t VIN;
  35. #endif
  36. #ifdef USE_NTC
  37. extern volatile ADCDataTypeDef_t NTC;
  38. #endif
  39. #ifdef USE_VREF
  40. extern volatile ADCDataTypeDef_t VREF;
  41. #endif
  42. typedef enum { ADC_Idle, ADC_Waiting, ADC_Sampling } ADC_Status_t;
  43. extern volatile ADC_Status_t ADC_Status;
  44. extern volatile uint16_t Tip_measures[ADC_BFSIZ];
  45. extern volatile adc_measures_t adc_measures[ADC_BFSIZ];
  46. uint16_t ADC_to_mV (uint16_t adc);
  47. void handle_ADC_Data(void);
  48. void DoAverage(volatile ADCDataTypeDef_t* InputData);
  49. void DEMA_Filter(ADCDataTypeDef_t* InputData);
  50. void ADC_Init(ADC_HandleTypeDef *adc);
  51. uint8_t ADC_Cal(void);
  52. void ADC_Stop_DMA(void);
  53. void ADC_Start_DMA(void);
  54. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* _hadc);
  55. #endif /* GENERALIO_ADC_GLOBAL_H_ */