-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hardware Timers #214
Comments
hw_timer_t * timer = NULL;
void onTimer(){
Serial.print("timer ");
Serial.println(millis());
}
// start/stop the timer
void toggleTimer(){
if(timer){
timerEnd(timer);
timer = NULL;
} else {
timer = timerBegin(3, 80, 1);//div 80
timerAttachInterrupt(timer, &onTimer, 1);
timerAlarmWrite(timer, 1000000, true);//1000ms
timerAlarmEnable(timer);
}
} |
Edit: @me-no-dev was faster :) There is example which call 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() {} |
@arcao you asked me as I was looking at the issue :D |
Thanks Guys, That was perfect. Thanks again for the quick response |
:) |
Thanks! I used your timer example successfully to implement my project.
Thanks again
GitHub - williamhemmingsen/WSPR-ESP32: WSPR implementation using the ESP32 and Si5351
|
|
|
| | |
|
|
|
| |
GitHub - williamhemmingsen/WSPR-ESP32: WSPR implementation using the ESP32 ...
WSPR-ESP32 - WSPR implementation using the ESP32 and Si5351 | |
|
|
From: Martin Sloup <[email protected]>
To: espressif/arduino-esp32 <[email protected]>
Cc: William Hemmingsen <william.hemmingsen@*********.***>; Author <[email protected]>
Sent: Friday, February 17, 2017 7:23 AM
Subject: Re: [espressif/arduino-esp32] Hardware Timers (#214)
There is example which call onTimer every second: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() {}—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Your comment is exposing your email address |
not anymore :) |
How to restart timer ? I test by
timer not new start. |
where to download the lib |
so if i end the timer,how can i restart it? |
is seems that it just relay for 1 seconds but dont know whether the timer is stopped or not |
Are there any examples of hardware timers for Arduino IDE? I have used ESP32 hw timers a lot, but can't make since of them in the ESP32.
I need to sample the adc a a specified rate. I would like to attachinterrupt to and 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!
The text was updated successfully, but these errors were encountered: