Arduino Uno R4 Minima wrong Delay

More the delay value is high more the delay time is wrong. For example a delay(1000) generates about a 1044ms delay inside the loop. A delay of 5 generates almost a 5ms delay

Have a nice day
GMG

Is it an original Arduino UNO R4 Minima or a low-cost version?

It's original from Arduino

Oh! Then it should not behave like this. Let's see what the admins have to say.

Hello gmgunderground

Read here:
https://www.arduino.cc/reference/en/language/functions/time/millis/
and check out

Notes and Warnings

There are no references to Renesas' R4, which has completely different management compared to the other micros. I would expect from a micro like this that the delays are always correct. However, now I'm just running tests on the functionality of a custom shield and then going to program it with e2Studio directly

Can you post the code that shows the delay(1000) generating a 1044mS delay?

Yes, source code is very simple, 1Hz LED Blink, half period delay is 522ms using a delay(500), look the next mage

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

void loop() 
{
    digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(500);                // wait for a second
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    delay(500);       
}

Did you check by using delayMicroseconds() too?

The documentation seems to indicate that there is no external oscillator/resonator on the board, can you confirm if your R4 Minima has one mounted? Otherwise the processor would be running off the internal oscillator, which generally lacks accuracy.

1 Like

yes, same result, 522ms

I confirm that there is no external oscillator, but still 4.5% error per second is definitely too high even for an internal oscillator. The internal oscillator can have some ns of error, not ms

A PWM signal that is generated by a timer is very precise, so it's not a micro problem, there is something wrong in the Arduino implementation

Definitely sounds like a problem.
Is the error linear with delay time?

Looking inside Arduino source code there is a Renesas function R_BSP_SoftwareDelay, that can be the problem.
https://renesas.github.io/fsp/group___b_s_p___m_c_u.html#gaf3219448adfd1531cf69f68697ab184b
I suggest a different metod to implement the delay

void DelayMs(unsigned long t)
{
    unsigned long t0 = millis();
    while(millis() < (t0 + t)){}
}

This delay implementation works perfectly. Millis tick are interrupt generated and so are very precise

However, the fact remains that the original Arduino delay does not work correctly. I suppose the same issue there is with R4 WiFi version

It must be the way that delay() is implemented on the R4 Minima.
I can confirm that my Uno R4 Minima has exactly the same delay of 522ms.

However if you use the example sketch "Blink Without Delay", which uses millis() for its timing, then the delay is correct.
(With interval changed to 500ms for comparison purposes.)

1 Like