Hi all,
Has anyone played around with the ADC on the ESP8226? I'm trying to boost my sample rate which is currently at 9.5kHz with the code below. I reckon it can go a lot faster given that the chip's clock frequency is 26-52 MHz. I've tried adjusting the prescaler which works on the ATMega chips but I can't find any examples or literature to supports this on the ESP8226.
//#define FASTADC 1 // defines for setting and clearing register bits
//#ifndef cbi
//#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
//#endif
//#ifndef sbi
//#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
//#endif
#include <ESP8266WiFi.h>
int i;
int z[1000];
unsigned long t[1000];
void setup() {
Serial.begin(115200);
// #if FASTADC
// // set prescale to 16
// sbi(ADCSRA, ADPS2) ;
// cbi(ADCSRA, ADPS1) ;
// cbi(ADCSRA, ADPS0) ;
//#endif
}
void loop() {
for(i=0;i<1000;i++){
z[i] = analogRead(A0);
t[i] = micros();
delayMicroseconds(10);
}
for(i=0;i<1000;i++){
Serial.println(z[i]);
Serial.print("\t");
Serial.println(t[i]);
}
delay(1000);
}