Timer Interrupt Priority
Timer Interrupt Priority
I use timer interrupts and an LCD display. In timer interrupt tick I toggle a GPIO pin to create a square wave. After I started the timer, I run an infinite loop to show the counter on the LCD display. The timer period is 100ms, LCD display period is 1 sec.
When I comment LCD display code I get perfect GPIO output as a square wave. When I run LCD print code, There is a few lags on GPIO output for a few pulses. I think I2C communication causes this lag. This lag period is around 5 secs. For the probability of python garbage collection cause this, I will examine the LCD driver code to reduce garbage collection.
How can I make this timer interrupt with higher priority?
When I comment LCD display code I get perfect GPIO output as a square wave. When I run LCD print code, There is a few lags on GPIO output for a few pulses. I think I2C communication causes this lag. This lag period is around 5 secs. For the probability of python garbage collection cause this, I will examine the LCD driver code to reduce garbage collection.
How can I make this timer interrupt with higher priority?
Re: Timer Interrupt Priority
Unfortunately on ESP32 interrupts can only run as "soft interrupts" (see https://docs.micropython.org/en/latest/ ... rules.html ), so they are scheduled between Python instructions.
I'm surprised it's 5 seconds though. Can you explain what you mean by "LCD display period is 1 sec.".
Re: Timer Interrupt Priority
I display a counter with 1 sec period.
Code: Select all
while True:
self.displayController.print(self.counter, 0, 0)
self.counter += 1
sleep(1)
Re: Timer Interrupt Priority
Try using
Code: Select all
for i in range(100):
time.sleep_ms(10)
Code: Select all
time.sleep(1)
Re: Timer Interrupt Priority
it still has lags
Re: Timer Interrupt Priority
I don't know how to interpret that picture sorry -- doesn't have any labels.
Did changing that sleep make any difference?
Did changing that sleep make any difference?
Re: Timer Interrupt Priority
This is pin output with a timer interrupt. On each timer tick, output toggles. With perfect timing, all pulse width should be the same.
this output is the same before and after sleep change.
this output is the same before and after sleep change.
Re: Timer Interrupt Priority
ESP32 just doesn't have very good support for low-latency operations.
What I suspect is happening here is that the scheduler isn't getting a change to run because of some quirks with the way sleep works on ESP32. Perhaps instead of time.sleep() you could use a loop that runs until a certain amount of time has elapsed (i.e. use time.ticks_ms and time.ticks_diff to measure the time).
What I suspect is happening here is that the scheduler isn't getting a change to run because of some quirks with the way sleep works on ESP32. Perhaps instead of time.sleep() you could use a loop that runs until a certain amount of time has elapsed (i.e. use time.ticks_ms and time.ticks_diff to measure the time).
Re: Timer Interrupt Priority
I tried creating a thread and using an infinite loop to handle timing on Raspberry Pi with dotnet core. This system will communicate with a PC and an LCD display via I2C. Because of those operations and the garbage collection loop is not stable. I also tried nanoFramework and native code integration with custom events.
I think the best stable way to use an Arduino with hardware interrupts. I will write C++ on Arduino, Python on ESP32, and C# on PC. Arduino and ESP32 will communicate via I2C, ESP32 and PC will communicate via a serial port.
I think the best stable way to use an Arduino with hardware interrupts. I will write C++ on Arduino, Python on ESP32, and C# on PC. Arduino and ESP32 will communicate via I2C, ESP32 and PC will communicate via a serial port.