Are there any examples of timer ISR?
I need to sample the adc a a specified rate (9600 times a sec). I would like to attachinterrupt to an ISR. Here is what I'm doing in the ESP8266. How do I do this in the ESP32?
void timer_init(void) {
timer1_isr_init();
timer1_attachInterrupt(sample_isr);
timer1_enable(TIM_DIV1, TIM_EDGE, TIM_LOOP);
timer1_write(8333); // 9600 samples/s
}
void ICACHE_RAM_ATTR sample_isr() {
...do some stuff
}
Thanks!
William
Timer ISR
Re: Timer ISR
Max ADC sample rate has been quoted at 6khz
Re: Timer ISR
Where is this documented? Do you have a link? That is a pretty sad rate if true. My whole point of using the ESP32 was so I wouldn't have to use an external ADC, as I currently do on the esp8266.WiFive wrote:Max ADC sample rate has been quoted at 6khz
I would still like to figure out the ISR, as SPI ADC's run 200k samples and cost less than a dollar. But will be surely disappointed if 6k is the true limit.
Re: Timer ISR
I'm going to close this topic, as I got my answer elsewhere. I will open a new topic on the ADC sample rate discussion.
Here is an example timer sketch, for others
hw_timer_t * timer = NULL;
void onTimer(){
static unsigned int counter = 1;
Serial.print("onTimer ");
Serial.print(counter);
Serial.print(" at ");
Serial.print(millis());
Serial.println(" ms");
if (counter == 10)
endTimer();
counter++;
}
void startTimer() {
timer = timerBegin(0, 80, true); // timer_id = 0; divider=80; countUp = true;
timerAttachInterrupt(timer, &onTimer, true); // edge = true
timerAlarmWrite(timer, 1000000, true); //1000 ms
timerAlarmEnable(timer);
}
void endTimer() {
timerEnd(timer);
timer = NULL;
}
void setup() {
Serial.begin(115200);
startTimer();
}
void loop() {}
Here is an example timer sketch, for others
hw_timer_t * timer = NULL;
void onTimer(){
static unsigned int counter = 1;
Serial.print("onTimer ");
Serial.print(counter);
Serial.print(" at ");
Serial.print(millis());
Serial.println(" ms");
if (counter == 10)
endTimer();
counter++;
}
void startTimer() {
timer = timerBegin(0, 80, true); // timer_id = 0; divider=80; countUp = true;
timerAttachInterrupt(timer, &onTimer, true); // edge = true
timerAlarmWrite(timer, 1000000, true); //1000 ms
timerAlarmEnable(timer);
}
void endTimer() {
timerEnd(timer);
timer = NULL;
}
void setup() {
Serial.begin(115200);
startTimer();
}
void loop() {}
Re: Timer ISR
The maximum sampling frequency of 6000 times a second can be found here ...
https://esp32.com/viewtopic.php?f=2&t=1075
If I may ask, what kind of project needs to sample an analog input at more than 6000 times a second?
https://esp32.com/viewtopic.php?f=2&t=1075
If I may ask, what kind of project needs to sample an analog input at more than 6000 times a second?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: Timer ISR
I'm decoding AFSK1200. I take 8 samples per AFSK bit. I have this working fine with a 8266 and MCP3008 external ADC. I was hoping to eliminate the external ADC, by using the ESP32. However if the ADC rate is 6K, I guess it won't work.kolban wrote:The maximum sampling frequency of 6000 times a second can be found here ...
https://esp32.com/viewtopic.php?f=2&t=1075
If I may ask, what kind of project needs to sample an analog input at more than 6000 times a second?
William
Who is online
Users browsing this forum: No registered users and 151 guests