Naguissa / uTimerLib

Arduino tiny and cross-device compatible timer library
https://www.foroelectro.net/electronica-digital-microcontroladores-f8/utimerlib-libreria-arduino-para-eventos-temporizad-t191.html
GNU Lesser General Public License v3.0
20 stars 9 forks source link

ARDUINO_STM32 - setInterval_s not correctly trigged #8

Closed mignon-ne closed 4 years ago

mignon-ne commented 4 years ago

I have try with Maple compatible board. When call with any value, it trig on every 1 second.

As example: void setup() { Serial.begin(57600); TimerLib.setInterval_s(timed_function, 2); prevMillis = millis(); }

Will result in 1000

However, TimerLib.setInterval_us return correctly. TimerLib.setInterval_us(timed_function, 2000000); Will result in 2000

Naguissa commented 4 years ago

I see examples are not very correct, as you shouldn't use time-based functions inside an interrupt.

I will test this later, but, could you check this modified example result?

#include "Arduino.h"
#include "uTimerLib.h"

volatile unsigned long int prevMillis = 0;
volatile unsigned long int actMillis = 0;

void timed_function() {
    Serial.println(actMillis - prevMillis);
    prevMillis = actMillis;
}

void setup() {
    Serial.begin(57600);
    TimerLib.setInterval_s(timed_function, 2);
    prevMillis = millis();
}

void loop() {
  actMillis = millis();
}
Naguissa commented 4 years ago

OK, fixed.

There was a part missing when managing interrupts on STM32 for "seconds" functions.

Also, I enhanced examples with more correct coding.

mignon-ne commented 4 years ago

Hi Naguissa,

Wow, that is super fast.

Great to have your response.

It is working now.

One question, if you don’t mind.

Can I have 2 independent timer?

Best regards,

Naguissa commented 4 years ago

It's not possible with this library. But I suggest to do a broker function and call it at Maximum Common Divissor.

Timers is a scarce resource, so you should preserve them. Also, Arduino functions and libraries are using some of them.

I try to use less common ones, so using even more timers will limit your options.

mignon-ne commented 4 years ago

Thank you very much.

Not sure relate to an update or not, but seem the location is moved. When compiled, it is completd and run successful. However, I have warning. Possible my own issue,

Resetting USB to switch back to runtime mode Invalid library found in C:\Users...\Documents\Arduino\libraries\uTimerLib: no headers files (.h) found in C:\Users...\Documents\Arduino\libraries\uTimerLib Invalid library found in C:\Users...\Documents\Arduino\libraries\uTimerLib: no headers files (.h) found in C:\Users...\Documents\Arduino\libraries\uTimerLib

Naguissa commented 4 years ago

How did you installed/updated the library? You can do it via Library Manager on Arduino IDE.

You should check that location, seems to have any invalid copy there....

mignon-ne commented 4 years ago

Solved, my own issue.

Found that your library name is "arduino_339753". Probably from update, during open that folder "uTimerLib" and files. Removed and re-install solved. Thanks.