adc_hal.c 845 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. // The HAL layer for ADC (common part)
  7. #include "hal/adc_hal.h"
  8. #include "hal/adc_hal_conf.h"
  9. #include "hal/adc_types.h"
  10. int adc_hal_hall_convert(void)
  11. {
  12. int Sens_Vp0;
  13. int Sens_Vn0;
  14. int Sens_Vp1;
  15. int Sens_Vn1;
  16. int hall_value;
  17. // convert for 4 times with different phase and outputs
  18. adc_ll_hall_phase_disable(); // hall phase
  19. adc_hal_convert( ADC_NUM_1, ADC_CHANNEL_0, &Sens_Vp0 );
  20. adc_hal_convert( ADC_NUM_1, ADC_CHANNEL_3, &Sens_Vn0 );
  21. adc_ll_hall_phase_enable();
  22. adc_hal_convert( ADC_NUM_1, ADC_CHANNEL_0, &Sens_Vp1 );
  23. adc_hal_convert( ADC_NUM_1, ADC_CHANNEL_3, &Sens_Vn1 );
  24. hall_value = (Sens_Vp1 - Sens_Vp0) - (Sens_Vn1 - Sens_Vn0);
  25. return hall_value;
  26. }