-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Board
ESP32 Dev Module
Device Description
Hardware Configuration
16x2 LCD connected via I2C
SD card connected via SDMMC pins
Rotary encoder connected to general IO
Version
v2.0.2
IDE Name
Platformio 4.2.0 Visual Studio Code
Operating System
Windows 10 x64
Flash frequency
80 MHz
PSRAM enabled
no
Upload speed
921600
Description
The code below works in framework-arduinoespressif32 3.20001.0 (2.0.1) and below, but not 2.0.2 and above, including https://github.com/espressif/arduino-esp32.git#142fceb8563cd1795d619829e0a103770a344e1a (which I believe is 2.0.3 as based on the info from this issue: #6689 )
In 2.0.1 or below the serial output shows an increasing value for 'tick', but in any framework version greater than 2.0.1, 'tick' stays at 1 indicating that the interrupt is not retriggered by the timer code inside of it.
Using the PIO Arduino support 4.1.0 (2.0.1) <- Works, tick increments
Using the PIO Arduino support 4.2.0 (2.0.2) <- Does not work, tick is 1 (interrupt fired once)
Using the PIO Arduino support 4.2.0 (2.0.3 from the git hash mentioned above) <- Does not work, tick is 1 (interrupt fired once)
Sketch
#include <Arduino.h>
hw_timer_t *signalTimer;
#define IDLE_TIMER_EXECUTE 1000
volatile uint32_t tick = 0;
void IRAM_ATTR signalTimerFunc()
{
tick++;
timerWrite(signalTimer, 0);
// IDLE_TIMER_EXECUTE is used here for simplicity. The actual next interval would be calculated in the ISR
timerAlarmWrite(signalTimer, IDLE_TIMER_EXECUTE, false);
timerAlarmEnable(signalTimer);
}
void startTimer()
{
signalTimer = timerBegin(0, 40, true);
timerAttachInterrupt(signalTimer, &signalTimerFunc, true);
timerWrite(signalTimer, 0);
timerAlarmWrite(signalTimer, IDLE_TIMER_EXECUTE, false);
timerAlarmEnable(signalTimer);
}
void stopTimer()
{
timerAlarmDisable(signalTimer);
timerDetachInterrupt(signalTimer);
timerEnd(signalTimer);
signalTimer = NULL;
}
void setup()
{
Serial.begin(115200);
Serial.println("Starting timer");
startTimer();
}
void loop()
{
delay(10);
Serial.printf("tick: %d\n", tick);
}
Debug Message
No debug, just the serial output as described.
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Activity
VojtechBartoska commentedon May 5, 2022
Hello, are you please able to retest this with newly release 2.0.3 stable version please?
sweetlilmre commentedon May 5, 2022
Hi I will retest, just need confirmation on how I would set this up with Platformio. I am assuming that I can do something like this in my platformio.ini file:
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.3
I'll try this and get back to you.
Edit: I am specifying this to be clear:
platform = https://github.com/platformio/platform-espressif32.git#v4.2.0
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.3
sweetlilmre commentedon May 5, 2022
Just tested with the configuration below and the issue still persists:
Edit: doing further testing from a completely clean platformio installation.
sweetlilmre commentedon May 5, 2022
Full clean platformio install with 2.0.3 and the issue persists:
P-R-O-C-H-Y commentedon May 5, 2022
Hi @sweetlilmre,
Your implementation is wrong. The functions
timerAlarmWrite(signalTimer, IDLE_TIMER_EXECUTE, false);
the last parameter is, if you want to repeat the alarm. Set it toTRUE
and comment outtimerAlarmWrite(signalTimer, IDLE_TIMER_EXECUTE, false);
andtimerAlarmEnable(signalTimer);
fromvoid IRAM_ATTR signalTimerFunc()
:)sweetlilmre commentedon May 5, 2022
Hi @P-R-O-C-H-Y
Thank you for your response. The sample I have provided is just the smallest possible example of the functionality I am using in a bigger project.
I do not want the timer to repeat as per your code above. In the actual project:
So my implementation is logically correct and works as stated for anything pre 2.0.2. If there is a change in the API that would require me to implement this functionality differently then that would be helpful to understand.
I have updated the example code to make the use-case explicit. Apologies for any confusion caused.
atanisoft commentedon May 5, 2022
@sweetlilmre remove the call to
timerAlarmEnable
fromsignalTimerFunc
, it shouldn't be necessary and may actually be resetting your parameters!Be warned however, using HW Timers to adjust GPIO pins WILL generate inconsistencies in your signal! I initially was using the timers in this code and moved to the RMT for accuracy/compliance purposes. You can see some externally captured timing here.
sweetlilmre commentedon May 5, 2022
Hi @atanisoft I tried your suggestion. Unfortunately this does not solve the 2.0.3 issue and additionally stops the timer from re-firing in 2.0.1 so it seems to be necessary in this "repeating one-shot" context.
Luckily signal inconsistency is not a huge issue in my application and it definitely works for use-case.
Thank you very much for the links, I've been meaning to look into the RMT stuff for a while but the complexity scared me off.
16 remaining items