adc(3877).c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * adc.c
  3. *
  4. * Created on: 2020. 8. 3.
  5. * Author: parkyj
  6. */
  7. #include "main.h"
  8. #include "adc.h"
  9. #include "NessLab.h"
  10. extern ADC_HandleTypeDef hadc1;
  11. extern DMA_HandleTypeDef hdma_adc1;
  12. extern Nesslab_Prot Currstatus;
  13. volatile uint16_t ADC1valuearray[ADC1_CNT][ADC_AVERAGECNT];
  14. volatile uint16_t ADC1value[ADC1_CNT];
  15. uint16_t adc1cnt = 0 ;
  16. void ADC_Initialize(){
  17. while(!(HAL_ADCEx_Calibration_Start(&hadc1)==HAL_OK));
  18. HAL_ADC_Start_DMA(&hadc1, (uint16_t*)ADC1value,(uint32_t) 4);
  19. }
  20. void ADC_Check(){
  21. Currstatus.DownLink_Forward_Det_H
  22. = ((ADC1value[0] & 0xFF00) >> 8);
  23. Currstatus.DownLink_Forward_Det_L
  24. = ((ADC1value[0] & 0x00FF) );
  25. Currstatus.DownLink_Reverse_Det_H
  26. = ((ADC1value[0] & 0xFF00) >> 8);
  27. Currstatus.DownLink_Reverse_Det_L
  28. = ((ADC1value[0] & 0x00FF) );
  29. Currstatus.DC_Level_Det_H
  30. = ((ADC1value[0] & 0xFF00) >> 8);
  31. Currstatus.DC_Level_Det_L
  32. = ((ADC1value[0] & 0x00FF) );
  33. Currstatus.Temp_Monitor
  34. = ((ADC1value[0] & 0xFF00) >> 8);
  35. Currstatus.Temp_Monitor
  36. = ((ADC1value[0] & 0x00FF) );
  37. }
  38. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
  39. {
  40. if(hadc->Instance == hadc1.Instance)
  41. {
  42. if(adc1cnt < ADC_AVERAGECNT){
  43. for(int i = 0; i < 4; i++){
  44. ADC1valuearray[i][adc1cnt] = ADC1value[i];
  45. }
  46. adc1cnt++;
  47. }
  48. }
  49. }