无法将原始ADC1读数转换为电压



我不明白为什么 ESP-IDF 电压计算如果用于转换来自 GPIO39 的原始读数会导致崩溃?

uint32_t电压 = esp_adc_cal_raw_to_voltage(read_raw, adc_chars(;

下面是简单的源代码

 #include <stdio.h>
    #include <stdlib.h>
    #include "freertos/FreeRTOS.h"
    #include "freertos/task.h"
    #include "freertos/queue.h"
    #include "driver/gpio.h"
    #include "driver/adc.h"
    #include "driver/dac.h"
    #include "esp_system.h"
    #include "esp_adc_cal.h"
    #define BLINK_GPIO 2
    static const adc_atten_t atten = ADC_ATTEN_DB_11;
    static const adc_unit_t unit = ADC_UNIT_1;
    #define DEFAULT_VREF    1100
    static void Read_GPIO39() {
        int read_raw = 0;
        adc1_config_width(ADC_WIDTH_BIT_12);
        adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_11);
        read_raw=adc1_get_raw(ADC1_CHANNEL_3);
       adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));

esp_adc_cal_characterize(unit, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF,adc_chars);
       **//uint32_t voltage = esp_adc_cal_raw_to_voltage(read_raw, adc_chars);**
        printf("Intensity : %dn", read_raw);
        //printf("Voltage: %dn", voltage);
        gpio_pad_select_gpio(BLINK_GPIO);
        gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
        gpio_set_level(BLINK_GPIO, 1);
    }

    void app_main() {
        ESP_ERROR_CHECK(nvs_flash_init());
        // initialise_wifi();
        while (1) {
            Read_GPIO39();
            vTaskDelay(3000 / portTICK_PERIOD_MS);
            gpio_set_level(BLINK_GPIO, 0);
        }

    }

通过下面的两个陈述,电压读数可以显示与实际电压读数的+/-7%偏差,原始读数最大=4095或2^12位~= 3.3v。该范围似乎在其他人之前测试和记录的区域内。

static const adc_atten_t atten = ADC_ATTEN_DB_11;
    static const adc_unit_t unit = ADC_UNIT_1;
    #define DEFAULT_VREF    1100
 adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
 esp_adc_cal_characterize(unit, atten, ADC_WIDTH_BIT_12, DEFAULT_VREF,adc_chars);

相关内容

  • 没有找到相关文章

最新更新