Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with timers #34

Closed
a7o opened this issue Jan 11, 2020 · 4 comments
Closed

Problem with timers #34

a7o opened this issue Jan 11, 2020 · 4 comments

Comments

@a7o
Copy link

a7o commented Jan 11, 2020

I tried to get general-purpose timers working, but couldn't succeed. Analyzing the library sources I've found that in the file
https://github.com/stevstrong/Arduino_STM32/blob/master/STM32F4/cores/maple/boards.cpp#L125
the function timerDefaultConfig() is eliminated by putting return statement in the first line. So all the timers aren't initialized and don't work.

@stevstrong
Copy link
Owner

What exactly is your application and what exactly is not working?
I made that change because I had an application where there was a problem with the default configuration.

@a7o
Copy link
Author

a7o commented Jan 11, 2020

Here's my very simple test sketch:

void setup() {

    Serial.begin(115200);
    while (!Serial) delay(10);
    delay(1000);    

    Serial.println ("Timer setup start");

    Timer2.pause();
    int period = Timer2.setPeriod(10000); // in microseconds
    Timer2.setOverflow(1000);
    Timer2.refresh();
    Timer2.resume();

    Serial.print ("Timer setup end, period="); Serial.println (period);
}

void loop() {
      uint16_t cnt = Timer2.getCount();
      Serial.print("timer2 counter: "); Serial.println(cnt);
      delay (500);
}

With your library, I see that the counter is always 0. After deleting the return statement, the counter changes as expected (up to 1000 and then from 0 again).

stevstrong added a commit that referenced this issue Jan 11, 2020
@stevstrong
Copy link
Owner

I am not going to enable that line in boards.cpp again.
But I just pushed a commit to solve the issue.

In order to use any timer from now on, one should call

TimerX.init();

This way the timer will be initialized and paused at the same time.

So in your sketch you have to replace
Timer2.pause();
with
Timer2.init();
Please try this and let me know if it works.

@stevstrong
Copy link
Owner

I just tested your sketch modified as suggested and it works, so I will close this now.
Reopen if it does not work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants