High resolution counter?
-
I noticed that Cortex-M3 has feature called SysTick which allows to get high resolution counter from various clock sources.
Does Mono Framework use or initialize SysTick at all? i.e. can I change its settings without affecting Mono Framework?
-
Hi @malaire
Mono Framework is built on top of mbed, that utilizes this SysTick counter to create software timers. mbed basically creates an abstraction above the hardware SysTick counter.
Mbed documentation states that you can create as many mbed timers as you wish. Of course this is an exaggeration. However, you can create a lot of timers - which are called
Ticker
in the mbed library.#include <mbed.h> mbed::Ticker timer1; timer1.attach_us(&my_callback_function, 1000);
This creates a SysTick based timer that calls
my_callback_function
every 1000 µs.You can tinker with the SysTick counter yourself, but it will break the mbed timers, and mono framework timers.
-
I don't want callback timers, I want to get elapsed time. It seems that
Timer
from mbed can be used here, but it's not working:#include <mbed.h> ... mbed::Timer t;
gives error
app_controller.cpp: In member function 'void AppController::updateDisplay()': app_controller.cpp:34:3: error: 'Timer' is not a member of 'mbed' mbed::Timer t;
ps. I can't use just
Timer
because ofusing namespace mono
-
Oh! It my bad - I have forgot an include in
mbed.h
- will add it on next release. Meanwhile you can includeTimer.h
manually:#include <Timer.h>
A full mono project will look like:
app_controller.h
#ifndef app_controller_h #define app_controller_h #include <mono.h> #include <Timer.h> class AppController : public mono::IApplication { public: mbed::Timer t; AppController(); void monoWakeFromReset(); void monoWillGotoSleep(); void monoWakeFromSleep(); }; #endif /* app_controller_h */
app_controller.cpp
#include "app_controller.h" AppController::AppController() { } void AppController::monoWakeFromReset() { t.start(); } void AppController::monoWillGotoSleep() { t.stop(); } void AppController::monoWakeFromSleep() { printf("timer: %i\r\n", t.read_us()); t.reset(); t.start(); }