convert raw reading from GPIO39 to voltage would result in crash

erik2727
Posts: 8
Joined: Fri Apr 12, 2019 2:26 pm

convert raw reading from GPIO39 to voltage would result in crash

Postby erik2727 » Fri Apr 12, 2019 2:39 pm

<r>I could not understanding why ESP-IDF voltage calculation if apply to convert the raw reading from GPIO39 would result in crash
<br/>
uint32_t voltage = esp_adc_cal_raw_to_voltage(read_raw, adc_chars);<br/>
<br/>
Below is the simple source code<br/>
<br/>
  1. #include <stdio.h><br/>
  2. #include <stdlib.h><br/>
  3. #include "freertos/FreeRTOS.h"<br/>
  4. #include "freertos/task.h"<br/>
  5. #include "freertos/queue.h"<br/>
  6. #include "driver/gpio.h"<br/>
  7. #include "driver/adc.h"<br/>
  8. #include "driver/dac.h"<br/>
  9. #include "esp_system.h"<br/>
  10. #include "esp_adc_cal.h"<br/>
  11. #define BLINK_GPIO 2
  12. <br/>
  13. <br/>
  14. static void Read_GPIO39() {<br/>
  15.     int read_raw = 0;<br/>
  16.     adc1_config_width(ADC_WIDTH_BIT_12);<br/>
  17.     adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_11);<br/>
  18.     read_raw=adc1_get_raw(ADC1_CHANNEL_3);<br/>
  19.     **//uint32_t voltage = esp_adc_cal_raw_to_voltage(read_raw, adc_chars);**<br/>
  20.     printf("Intensity : %d\n", read_raw);<br/>
  21. <br/>
  22.     //printf("Voltage: %d\n", voltage);<br/>
  23.     gpio_pad_select_gpio(BLINK_GPIO);<br/>
  24.     gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);<br/>
  25.     gpio_set_level(BLINK_GPIO, 1);<br/>
  26. }<br/>
  27. <br/>
  28. <br/>
  29. void app_main() {<br/>
  30.     ESP_ERROR_CHECK(nvs_flash_init());<br/>
  31.     // initialise_wifi();<br/>
  32.     while (1) {<br/>
  33.         Read_GPIO39();<br/>
  34. <br/>
  35.         vTaskDelay(3000 / portTICK_PERIOD_MS);<br/>
  36.         gpio_set_level(BLINK_GPIO, 0);<br/>
  37. }<br/>
  38. }

ESP_Sprite
Posts: 9773
Joined: Thu Nov 26, 2015 4:08 am

Re: convert raw reading from GPIO39 to voltage would result in crash

Postby ESP_Sprite » Mon Apr 15, 2019 3:34 am

What is adc_chars? How did you define it?

erik2727
Posts: 8
Joined: Fri Apr 12, 2019 2:26 pm

Re: convert raw reading from GPIO39 to voltage would result in crash

Postby erik2727 » Mon Apr 15, 2019 11:40 am

with below statement , 7% variance is observed. I have doubt on the atten not sure should this be ADC_ATTEN_DB_11 or some others value for GPIO39 , voltage reading is very unstable on genuine espressif dev Wrover B development board


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);

Who is online

Users browsing this forum: ignisuti, jcolebaker and 79 guests