Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: TeensyTimerTool

  1. #1
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    600

    TeensyTimerTool

    TeensyTimerTool - Easy to use interface to the Teensy Timers

    I just published TeensyTimerTool on GitHub https://github.com/luni64/TeensyTimerTool. The library provides an easy to use interface to the Teensy timers. Currently it works on the T4.0 and uses the GPT (2x) and QUAD (16x) timer modules/channels. Additionally it provides up to 20 software based timers with exactly the same interface. Extension to the PIT modules and the other boards is planned. All timers can be used in periodic and one-shot mode. You can either specify which hard/software timer you want to use; or -if you don't care- you can get the next free timer from a pool.

    Here a quick example how to use a timer from the pool and set it up in one-shot mode:

    Code:
    #include "TeensyTimerTool.h"
    using namespace TeensyTimerTool;
    
    
    Timer t1; 
    
    
    void setup() 
    {
        pinMode(LED_BUILTIN,OUTPUT);   
        t1.beginOneShot(callback); 
    }
    
    
    void loop()
    {   
        digitalWriteFast(LED_BUILTIN, HIGH); 
        t1.trigger(10'000); // trigger the timer with 10ms delay
    
    
        delay(500);
    } 
    
    
    void callback() // switch off LED
    {
        digitalWriteFast(LED_BUILTIN, LOW);  
    }
    If you want to use GPT1 instead, all you need to do is to replace the line
    Code:
    Timer t1;
    by
    Code:
    Timer t1(GPT1)
    The gitHub readme contains more examples demonstrating the usage.

    Callbacks
    In addition to the usual pointer to void functions all timers accept non static member functions, lambdas, funktors etc. as callbacks. This makes it very easy to pass state to the member function or do classes which embed timers and callbacks. Examples here. If for some reason you prefer a plain vanilla function pointer interface you can configure the library accordingly.

    Performance
    I tried to optimize the performance as much as possible. Any further optimization input would be very welcome. Due to the high speed of the ARM core the performance of the software timers is pretty amazing and actually beats the hardware timers if you don't generate too much instances.

    Status
    The code base is quite new and probably contains bugs and improvement possibilities.

    As always: Any feedback, bugreports and general rants are very welcome.

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    600
    Found time to add some more timers for T3.0 - T3.6. to the TeensyTimerTool. So, currently the library supports the following hard- and software timers.

    • T4.0: GPT1-GPT2(2 x 32bit channel each), TMR1-TMR4 (aka QUAD, 16 x 16bit channels), TCK (20 x 32bit channels)
    • T3.6: FTM0-FTM3 (20 x 16bit channels), TCK (20 x 32bit channels)
    • T3.5: FTM0-FTM3 (20 x 16bit channels), TCK (20 x 32bit channels)
    • T3.2: FTM0-FTM2 (12 x 16bit channels), TCK (20 x 32bit channels)
    • T3.0: FTM0-FTM1 (10 x 16bit channels), TCK (20 x 32bit channels)
    • TLC: TCK (10 x 32bit channels)


    Each timer works in periodic and one shot mode.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •