Hi, I'm very new to this field so I'm here to ask for some knowledge. My project is to adjust the sampling rate of the input signal. My goal was to adjust the maximum to 14,000. I used the Basic timer interrupt to be able to adjust the sample rate as needed : https://techtutorialsx.com/2017/10/07/e ... nterrupts/ , but when I tested it it turned out that the maximum sample rate was only 2000. Even though I tried adjusting the prescaler and the value is still 2000, what should I do?
this is my code:
volatile int interruptCounter;
int totalInterruptCounter;
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR onTimer() {
portENTER_CRITICAL_ISR(&timerMux);
interruptCounter++;
portEXIT_CRITICAL_ISR(&timerMux);
}
String data_max;
void setup() {
Serial.begin(115200);
timer = timerBegin(0, 16, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 1000, true);
timerAlarmEnable(timer);
}
void loop() {
if (interruptCounter > 0) {
portENTER_CRITICAL(&timerMux);
interruptCounter--;
portEXIT_CRITICAL(&timerMux);
totalInterruptCounter++;
//Serial.print("An interrupt as occurred. Total number: ");
//Serial.println(totalInterruptCounter);
getReadings();
}
}
void getReadings(){
data_max = String(analogRead(35));
Serial.println(data_max);
}
ESP32:How to in crease ADC sampling rate with timer interrupt
Who is online
Users browsing this forum: Bing [Bot] and 88 guests