Skip to content

Commit 82da5a6

Browse files
committed
fix examples
1 parent acd8672 commit 82da5a6

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

libraries/ESP32/examples/Timer/RepeatTimer/RepeatTimer.ino

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Stop button is attached to PIN 0 (IO0)
1212
#define BTN_STOP_ALARM 0
1313

14-
hw_timer_t * timer = NULL;
14+
hw_timer_t timer = NULL;
1515
volatile SemaphoreHandle_t timerSemaphore;
1616
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
1717

@@ -38,20 +38,15 @@ void setup() {
3838
// Create semaphore to inform us when the timer has fired
3939
timerSemaphore = xSemaphoreCreateBinary();
4040

41-
// Use 1st timer of 4 (counted from zero).
42-
// Set 80 divider for prescaler (see ESP32 Technical Reference Manual for more
43-
// info).
44-
timer = timerBegin(0, 80, true);
41+
// Set timer frequency to 1Mhz
42+
timer = timerBegin(1000000, true);
4543

4644
// Attach onTimer function to our timer.
47-
timerAttachInterrupt(timer, &onTimer, true);
45+
timerAttachInterrupt(timer, &onTimer);
4846

4947
// Set alarm to call onTimer function every second (value in microseconds).
50-
// Repeat the alarm (third parameter)
51-
timerAlarmWrite(timer, 1000000, true);
52-
53-
// Start an alarm
54-
timerAlarmEnable(timer);
48+
// Repeat the alarm (third parameter) with unlimited count = 0 (fourth parameter).
49+
timerAlarmWrite(timer, 1000000, true, 0);
5550
}
5651

5752
void loop() {

libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const int button = 0; //gpio to use to trigger delay
44
const int wdtTimeout = 3000; //time in ms to trigger the watchdog
5-
hw_timer_t *timer = NULL;
5+
hw_timer_t timer = NULL;
66

77
void ARDUINO_ISR_ATTR resetModule() {
88
ets_printf("reboot\n");
@@ -14,11 +14,10 @@ void setup() {
1414
Serial.println();
1515
Serial.println("running setup");
1616

17-
pinMode(button, INPUT_PULLUP); //init control pin
18-
timer = timerBegin(0, 80, true); //timer 0, div 80
19-
timerAttachInterrupt(timer, &resetModule, true); //attach callback
20-
timerAlarmWrite(timer, wdtTimeout * 1000, false); //set time in us
21-
timerAlarmEnable(timer); //enable interrupt
17+
pinMode(button, INPUT_PULLUP); //init control pin
18+
timer = timerBegin(1000000, true); //timer 1Mhz resolution
19+
timerAttachInterrupt(timer, &resetModule); //attach callback
20+
timerAlarmWrite(timer, wdtTimeout * 1000, false, 0); //set time in us
2221
}
2322

2423
void loop() {

0 commit comments

Comments
 (0)