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 of using namespace mono

  • Oh! It my bad - I have forgot an include in mbed.h - will add it on next release. Meanwhile you can include Timer.h manually:

    #include <Timer.h>

    A full mono project will look like:


    #ifndef app_controller_h
    #define app_controller_h
    #include <mono.h>
    #include <Timer.h>
    class AppController : public mono::IApplication {
        mbed::Timer t;
        void monoWakeFromReset();
        void monoWillGotoSleep();
        void monoWakeFromSleep();
    #endif /* app_controller_h */


    #include "app_controller.h"
    void AppController::monoWakeFromReset()
    void AppController::monoWillGotoSleep()
    void AppController::monoWakeFromSleep()
        printf("timer: %i\r\n", t.read_us());

Log in to reply