對于ADC采集 程序源碼如下:1 /* ADC1 Example 2 3 This example code is in the Public Domain (or CC0 licensed, at your option.) 4 5 Unless required by applicable law or agreed to in writing, this 6 software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 CONDITIONS OF ANY KIND, either express or implied. 8 */ 9 #include <stdio.h> 10 #include <string.h> 11 #include <stdlib.h> 12 #include "freertos/FreeRTOS.h" 13 #include "freertos/task.h" 14 #include "freertos/queue.h" 15 #include "driver/gpio.h" 16 #include "driver/adc.h" 17 18 #define ADC1_TEST_CHANNEL (4) 19 20 void adc1task(void* arg) 21 { 22 // initialize ADC 23 adc1_config_width(ADC_WIDTH_12Bit); 24 adc1_config_channel_atten(ADC1_TEST_CHANNEL,ADC_ATTEN_11db); 25 while(1){ 26 printf("The adc1 value:%d\n",adc1_get_voltage(ADC1_TEST_CHANNEL)); 27 vTaskDelay(1000/portTICK_PERIOD_MS); 28 } 29 } 30 31 void app_main() 32 { 33 xTaskCreate(adc1task, "adc1task", 1024*3, NULL, 10, NULL); 34 } ESP32集成了兩個(gè)12位SAR(“逐次逼近寄存器”)ADC(模數(shù)轉(zhuǎn)換器),并支持18通道(模擬使能引腳)的測量。這些引腳中的一些可用于構(gòu)建用于測量小型模擬信號的可編程增益放大器。 ADC驅(qū)動(dòng)程序API目前僅支持ADC1(9個(gè)通道,連接到GPIO 32-39)。 進(jìn)行ADC讀取需要以所需的精度和注意事項(xiàng)設(shè)置ADC,然后調(diào)用adc1_get_voltage()來讀取通道。 本例程選用adc1task對adc進(jìn)行初始化設(shè)置 ?。?)adc1_config_width(),設(shè)定捕獲寬度,其中
程序源碼如下;燒寫程序后,將GPIO32連接到一個(gè)可以改變的電壓輸出口,打開minicom,觀察電壓輸出值,調(diào)節(jié)電壓,觀察輸出值變化。 硬件連接如下
minicom輸出如下圖所示
相關(guān)知識:AD轉(zhuǎn)換相關(guān)函數(shù)API接口
|
|