ESP32 analogRead too much noise when attaching timer to pin.
using WROOM 32 module and nodeMCU 32S ardunio board selection.
I can get a stable analog value on a seperate Nano from the sensor clocked from the ESP32.
#define CHANNEL 0
//#define FREQUENCY 40000000
#define FREQUENCY 40000000
#define OUTPIN 17
#define BITDEPTH 1
#define DUTY 1
#include <driver/adc.h>
int val=0;
const int aread_pin=32;
//#define aread_pin 32
void setup() {
pinMode(aread_pin,INPUT);
Serial.begin(115200);
int result =ledcSetup(CHANNEL, FREQUENCY, BITDEPTH);
delay(1000);
Serial.print ("result ok");
Serial.println(ESP_OK);
Serial.print ("result fail");
Serial.println(ESP_FAIL);
Serial.print ("result invalid");
Serial.println(ESP_ERR_INVALID_ARG);
Serial.print ("result ");
Serial.println(result);
ledcAttachPin(OUTPIN, CHANNEL);
ledcWrite(CHANNEL, DUTY);
//analogReference(DEFAULT);
//analogSetAttenuation(ADC_6db);
analogReadResolution(12);
adc1_config_width(ADC_WIDTH_11Bit);
adc1_config_channel_atten(ADC1_CHANNEL_4,ADC_ATTEN_0db);
}
void loop() {
val=0;
for (int i=0; i<100; i++) {
val=val+adc1_get_voltage(ADC1_CHANNEL_4);
//val=val+analogRead(aread_pin);
delay(20);
}
val=val/100;
Serial.print("anlog read = ");
// int val = adc1_get_voltage(ADC1_CHANNEL_4); // pin 32
Serial.println(analogRead(aread_pin));
Serial.println(val);
//Serial.println(analogRead(val));
delay(1000);
}
Output:
anlog read = 993
867
anlog read = 632
850
anlog read = 688
845
anlog read = 477
869
anlog read = 1056
866
anlog read = 483
839
anlog read = 688
829
anlog read = 950
861
anlog read = 1184
839
anlog read = 868
882
anlog read = 1047
851
anlog read = 864
876
anlog read = 960
875
anlog read = 482
854
anlog read = 640
873
anlog read = 624
817
anlog read = 1028
890
anlog read = 752
847
anlog read = 1174
858
anlog read = 880
831
anlog read = 754
900
anlog read = 843
858
anlog read = 1184
867
anlog read = 477
877
anlog read = 1005
879
anlog read = 1178
882
anlog read = 776
863
anlog read = 1029
904
anlog read = 884
859
anlog read = 656
898
anlog read = 769
859
anlog read = 921
864
anlog read = 1155
862
anlog read = 944
853
anlog read = 666
878
anlog read = 950
855
anlog read = 825
842
anlog read = 705
865
anlog read = 971
869
Timer seems to break ADC
Return to “General Discussion”
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: No registered users and 151 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.