What happens once every milisecond (1000 Hz) and halts tasks

nkukenberger
Posts: 1
Joined: Thu Aug 23, 2018 7:38 pm

What happens once every milisecond (1000 Hz) and halts tasks

Postby nkukenberger » Thu Aug 23, 2018 8:00 pm

Hi!

I can reproduce the issue on a genuine UNO board which makes me believe it's an Arduino thing.

My code is super simple:

Code: Select all

void setup() {
  pinMode(5, OUTPUT);
}
    

void loop() {
  digitalWrite(5, 1);
  digitalWrite(5, 0);
  }
Bitbanging on pin 5 to achieve approximately 50% duty cycle PWM. So looking at it on the oscilloscope it's really odd that every millisecond there is a halt in state-changing that lasts about 7 us. At 4 to 9 MHz this is very noticeable and hinders my project.
Someone else observed this already:
viewtopic.php?t=3689

The code I'm going to be using in my project is more complicated but it doesn't affect the issue, I tried by taking chunks off - no difference. Keep in mind that the issue comes up on both genuine Arduino boards and ESP32 ones (tested on two new)..
On ESP32 it goes away when using ledc PWM and on UNO noInterrupts() solves the issue. So I'm guessing the ledc HW PWM (ESP32) is not affected by the software on top and on UNO noInterrupts() does something that results in no disturbances in code execution.
vTaskEnterCritical() does reduce the number of halts in created tasks but it doesn't eliminate them - measuring this with ccount, they last approximately 1500 - 2000 cycles. Has some effect in loopTask, halves no. of halts.
Core pinning has no effect, nor has moving Arduino loopTask to core 0 and tick rate change (FREERTOS_HZ).

What I haven't tried (on it as I'm writing this) is unicore operation and making my code an ISR. Oh and ditching the Arduino environment altogether.

Basically what I'm trying to achieve is critical code all the time or at least for a second (only one task needs to be run).
Is this possible?

So any idea what it might be? What happens every millisecond and is not processor specific?

Sorry if I was unclear or wrong anywhere, thank you for your time in advance :)

Who is online

Users browsing this forum: Google [Bot] and 56 guests