adc(6305).c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /*
  17. *
  18. * ADC 0 :DL TX
  19. * ADC 1 :DL RX
  20. * ADC 2 :TEMP
  21. * */
  22. void ADC_Value_Get(){
  23. uint16_t CalcRet = 0 ;
  24. /*DL TX Calc*/
  25. Currstatus.DownLink_Forward_Det_H = ((ADC1value[0] & 0xFF00) >> 8);
  26. Currstatus.DownLink_Forward_Det_L = (ADC1value[0] & 0x00FF);
  27. /*DL RX Calc*/
  28. Currstatus.DownLink_Reverse_Det_H = ((ADC1value[1] & 0xFF00) >> 8);
  29. Currstatus.DownLink_Reverse_Det_L = (ADC1value[1] & 0x00FF);
  30. /*Temp Calc*/
  31. Currstatus.Temp_Monitor = ((ADC1value[1] & 0xFF00) >> 8);
  32. }
  33. void ADC_Initialize(){
  34. while(!(HAL_ADCEx_Calibration_Start(&hadc1)==HAL_OK));
  35. HAL_ADC_Start_DMA(&hadc1, (uint16_t*)ADC1value,(uint32_t) 3);
  36. }
  37. void ADC_Check(){
  38. float tempval = 0;
  39. for(int i = 0 ; i < ADC1_CNT; i++){
  40. tempval = (ADC1value[i] * (3.3 / 4095));
  41. // tempval *= 1000;
  42. }
  43. // printf("ADC1value[%d] : %f \r\n",i,tempval);
  44. // printf("ADC1value[%d] : %d \r\n",i,ADC1value[i] );
  45. #if 1 // PYJ.2020.08.26_BEGIN --
  46. Currstatus.DownLink_Forward_Det_H
  47. = (((uint16_t)tempval & 0xFF00) >> 8);
  48. Currstatus.DownLink_Forward_Det_L
  49. = (((uint16_t)tempval & 0x00FF) );
  50. #endif // PYJ.2020.08.26_END --
  51. adc1cnt = 0;
  52. }
  53. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
  54. {
  55. if(hadc->Instance == hadc1.Instance)
  56. {
  57. // if(adc1cnt < ADC_AVERAGECNT){
  58. // for(int i = 0; i < ADC1_CNT; i++){
  59. // ADC1valuearray[i][adc1cnt] = ADC1value[i];
  60. // }
  61. // adc1cnt++;
  62. // }
  63. }
  64. }