Arduino Due libraries (official and 3rd party)

Hi all,

I have made a small improvement to WInterrupts.c which allows a faster interrupt dispatching associated to generic I/O pins. That is, the callbacks we set with function attachInterrupt().

Basically I have modified the code of the interrupt handler functions PIOA_Handler(), PIOB_Handler(), PIOC_Handler() and PIOD_handler() in the original WInterrupts.c. The improvement consists mainly in taking advantage of ATSAM3XE assembler instruction CLZ. With this instruction it is possible to calculate the number of leading zeros in a 32 bit value in just one machine instruction. CLZ is available in C/C++ using CMSIS function __CLZ().

Using this small improvement I have been able to get to a bit rate of 115200 with my software serial library for the DUE, soft_uart (using the example provided with soft_uart and two stop bits). Take into account that soft_uart uses the interrupt for pin level changes on the RX pin associated to the software serial object when used. Without the improvement soft_uart could only get to 57600 (same example also with two stop bits).

Herein I include attached the file WInterrupts.c with the PIO handlers modified (the previous versions of the handlers are also on the file, but commented). To illustrate the change here you have the code for handler PIOA_Handler() (the previous one appears commented), the other ones are alike:

//void PIOA_Handler(void) {
//      uint32_t isr = PIOA->PIO_ISR;                                                 
//      uint32_t i;
//      for (i=0; i<32; i++, isr>>=1) {                                               
//              if ((isr & 0x1) == 0)                                                 
//                      continue;
//              if (callbacksPioA[i])                                                 
//                      callbacksPioA[i]();                                           
//      }       
//}                     

void PIOA_Handler(void) {                                                             
 register uint32_t isr = PIOA->PIO_ISR;                                              
 register uint8_t leading_zeros;                                                     
 while((leading_zeros=__CLZ(isr))<32)
 {
   register uint8_t pin=32-leading_zeros-1;                                          
   if(callbacksPioA[pin]) callbacksPioA[pin]();                                      
   isr=isr&(~(1<<pin));
 }
}

If you want to check this version of WInterrupts.c just overwrite the original with this new one.

Sincerely, I consider this change can benefit any code using interrupts associated to any Arduino DUE I/O pin with function attachInterrupt(). Once tested enough by more people, maybe it might be convenient to apply the change to the official Arduino DUE standard library. Anybody knows to whom I have to address to propose the change?.

WInterrupts.c (5.42 KB)

@antodom

""Anybody knows to whom I have to address to propose the change?""

i am not sure but probably Nick Gammon is the one you are looking for.

Hi, I'm having a lot of problems with the libraries of DHT22 humidity and temperature sensor and Arduino DUE.

It seems to have an ARM microcontroller, that driver must have a configuación different pins, and not just go well.

There is someone who can send me a code that I work at least to put the value in a variable moisture and other temperature value?

From there and I would deal myself.

Thank you so much for everything.

Cheers,
Xavi

is there meanwhile a reasonable USB keyb lib available feat. standard C keyboard functions (stdin) like e.g.

kbhit()
getch()
getche()
getchar()
gets()
scanf()

?

currently the implementation of the USB.task is really weird, keyPressed and keyReleased don't return anything and it's totally osbscured how and when they do either or anything meaningful,
currently it's not even possible to indicate if a key was hit at all or not (like provided by kbhit() ),
usb.Task has to be called repeatedly but then blocks program execution intermediately and repeatedly for many seconds (which is unconscionable in the main loop() but shockingly also hinders different additional Scheduler multitasking threads ).

I noticed my post on the Eigen library was for the pc and not the arduino one I wrote for the Due.
I used the library tutorial and got the newest stable release of Eigen to run.
I wold add my ziped library file if I could to make it easier to run Eigen libraries on the DUE in win/linux/mac.
A header and ccp file was needed I named the folder in home/arduino/libraries EIGEN.
The header file was Eigen.h and program file Eigen.cpp

/*
  Eigen.h - Library for adding Eigen library code.
  Created by Joshua Wojnas, September 15, 2015.
*/

#ifndef Eigen_h
#define Eigen_h

#include "Dense"
#include "LU"
#include "Arduino.h" //statement that gives you access to the standard types and constants of the Arduino

using Eigen::MatrixXd;
using namespace std;
using namespace Eigen;


#endif
/*
  Eigen.cpp - Library for adding Eigen library code.
  Created by Joshua Wojnas, September 15, 2015.
*/

#include "Dense"
#include "LU"
#include "Arduino.h"//give the rest of the code access to the standard Arduino functions 
#include "Eigen.h"

using Eigen::MatrixXd;
using namespace std;
using namespace Eigen;

Then their was the program I used to test it by randomvibe

//Eigan library test by josheeg example by random vibe and eigen library team.
#include <Eigen.h>

// PRINT MATRIX (float type)
// By: randomvibe
//-----------------------------


void print_mtxf(const Eigen::MatrixXf& K);


void setup()
{
  Serial.begin(9600);

  // DECLARE MATRICES
  //--------------------
  MatrixXf Pp(6, 6);  // Produces 6x6 float matrix class
  MatrixXf H(6, 6);   // Note: without "using namespace Eigen", declaration would be: Eigen::MatrixXf H(6,6);
  MatrixXf R(6, 6);
  MatrixXf X(6, 6);
  MatrixXf K(6, 6);
  MatrixXf Z(6, 6);

  // INPUT MATRICES (so-called comma-initialize syntax)
  //---------------------------------------------------------
  Pp << 0.3252,  0.3192,  1.0933, -0.0068, -1.0891, -1.4916,
  -0.7549,  0.3129,  1.1093,  1.5326,  0.0326, -0.7423,
  1.3703, -0.8649, -0.8637, -0.7697,  0.5525, -1.0616,
  -1.7115, -0.0301,  0.0774,  0.3714,  1.1006,  2.3505,
  -0.1022, -0.1649, -1.2141, -0.2256,  1.5442, -0.6156,
  -0.2414,  0.6277, -1.1135,  1.1174,  0.0859,  0.7481 ;

  H << 0.8147, 0.2785, 0.9572, 0.7922, 0.6787, 0.7060,
  0.9058, 0.5469, 0.4854, 0.9595, 0.7577, 0.0318,
  0.1270, 0.9575, 0.8003, 0.6557, 0.7431, 0.2769,
  0.9134, 0.9649, 0.1419, 0.0357, 0.3922, 0.0462,
  0.6324, 0.1576, 0.4218, 0.8491, 0.6555, 0.0971,
  0.0975, 0.9706, 0.9157, 0.9340, 0.1712, 0.8235;

  R << 0.3252,  0.3192,  1.0933, -0.0068, -1.0891, -1.4916,
  -0.7549,  0.3129,  1.1093,  1.5326,  0.0326, -0.7423,
  1.3703, -0.8649, -0.8637, -0.7697,  0.5525, -1.0616,
  -1.7115, -0.0301,  0.0774,  0.3714,  1.1006,  2.3505,
  -0.1022, -0.1649, -1.2141, -0.2256,  1.5442, -0.6156,
  -0.2414,  0.6277, -1.1135,  1.1174,  0.0859,  0.7481;


  // Kalman Gain Example; Matlab form:  K = Pp * H' * inv(H * Pp * H' + R)
  //-----------------------------------
  X  = H * Pp * H.transpose() + R;
  K  = Pp * H.transpose() * X.inverse();


  // Print Result
  //----------------------------
  print_mtxf(K);      // Print Matrix Result (passed by reference)


}

void loop()
{
 }


// PRINT MATRIX (float type)
// By: randomvibe
//-----------------------------
void print_mtxf(const Eigen::MatrixXf& X)  
{
   int i, j, nrow, ncol;
   
   nrow = X.rows();
   ncol = X.cols();

   Serial.print("nrow: "); Serial.println(nrow);
   Serial.print("ncol: "); Serial.println(ncol);      
   Serial.println();
   
   for (i=0; i<nrow; i++)
   {
       for (j=0; j<ncol; j++)
       {
           Serial.print(X(i,j), 6);   // print 6 decimal places
           Serial.print(", ");
       }
       Serial.println();
   }
   Serial.println();
}

I found the quick reply does not let me add the zip file of my arduino due library to connect the Eigen library.

Also here is some test code after the arduino due eigen library is installed.

//Eigan library test by josheeg example by random vibe and eigen library team.
#include <Eigen.h>

// PRINT MATRIX (float type)
// By: randomvibe
//-----------------------------


void print_mtxf(const Eigen::MatrixXf& K);


void setup()
{
  Serial.begin(9600);

  // DECLARE MATRICES
  //--------------------
  MatrixXf Pp(6, 6);  // Produces 6x6 float matrix class
  MatrixXf H(6, 6);   // Note: without "using namespace Eigen", declaration would be: Eigen::MatrixXf H(6,6);
  MatrixXf R(6, 6);
  MatrixXf X(6, 6);
  MatrixXf K(6, 6);
  MatrixXf Z(6, 6);

  // INPUT MATRICES (so-called comma-initialize syntax)
  //---------------------------------------------------------
  Pp << 0.3252,  0.3192,  1.0933, -0.0068, -1.0891, -1.4916,
  -0.7549,  0.3129,  1.1093,  1.5326,  0.0326, -0.7423,
  1.3703, -0.8649, -0.8637, -0.7697,  0.5525, -1.0616,
  -1.7115, -0.0301,  0.0774,  0.3714,  1.1006,  2.3505,
  -0.1022, -0.1649, -1.2141, -0.2256,  1.5442, -0.6156,
  -0.2414,  0.6277, -1.1135,  1.1174,  0.0859,  0.7481 ;

  H << 0.8147, 0.2785, 0.9572, 0.7922, 0.6787, 0.7060,
  0.9058, 0.5469, 0.4854, 0.9595, 0.7577, 0.0318,
  0.1270, 0.9575, 0.8003, 0.6557, 0.7431, 0.2769,
  0.9134, 0.9649, 0.1419, 0.0357, 0.3922, 0.0462,
  0.6324, 0.1576, 0.4218, 0.8491, 0.6555, 0.0971,
  0.0975, 0.9706, 0.9157, 0.9340, 0.1712, 0.8235;

  R << 0.3252,  0.3192,  1.0933, -0.0068, -1.0891, -1.4916,
  -0.7549,  0.3129,  1.1093,  1.5326,  0.0326, -0.7423,
  1.3703, -0.8649, -0.8637, -0.7697,  0.5525, -1.0616,
  -1.7115, -0.0301,  0.0774,  0.3714,  1.1006,  2.3505,
  -0.1022, -0.1649, -1.2141, -0.2256,  1.5442, -0.6156,
  -0.2414,  0.6277, -1.1135,  1.1174,  0.0859,  0.7481;


  // Kalman Gain Example; Matlab form:  K = Pp * H' * inv(H * Pp * H' + R)
  //-----------------------------------
  X  = H * Pp * H.transpose() + R;
  K  = Pp * H.transpose() * X.inverse();


  // Print Result
  //----------------------------
  print_mtxf(K);      // Print Matrix Result (passed by reference)


}

void loop()
{
 }


// PRINT MATRIX (float type)
// By: randomvibe
//-----------------------------
void print_mtxf(const Eigen::MatrixXf& X)  
{
   int i, j, nrow, ncol;
   
   nrow = X.rows();
   ncol = X.cols();

   Serial.print("nrow: "); Serial.println(nrow);
   Serial.print("ncol: "); Serial.println(ncol);      
   Serial.println();
   
   for (i=0; i<nrow; i++)
   {
       for (j=0; j<ncol; j++)
       {
           Serial.print(X(i,j), 6);   // print 6 decimal places
           Serial.print(", ");
       }
       Serial.println();
   }
   Serial.println();
}

EIGEN.zip (758 KB)

(perhaps cross posted, sorry)
I found this one, does this help?

EDIT: Solved: Managed to find WInterrupts.c in C:\Users<USERNAME>\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4\cores\arduino
not sure if this is common but that's where is located in my installation, I can't remember if I did something strange when installing or if I had to add DUE at a later time than when I initially installed it.

antodom:
Hi all,

I have made a small improvement to WInterrupts.c which allows a faster interrupt dispatching associated to generic I/O pins. That is, the callbacks we set with function attachInterrupt().

Basically I have modified the code of the interrupt handler functions PIOA_Handler(), PIOB_Handler(), PIOC_Handler() and PIOD_handler() in the original WInterrupts.c. The improvement consists mainly in taking advantage of ATSAM3XE assembler instruction CLZ. With this instruction it is possible to calculate the number of leading zeros in a 32 bit value in just one machine instruction. CLZ is available in C/C++ using CMSIS function __CLZ().
[...]

@antodom & all

I'm drawing a blank here - I can't find the WInterrupts.c in my installation containing PIOA_Handler, PIOB_Handler, etc, just the one for AVR based boards. I searched the arduino installation folder and that's the only one I have. Any help locating it would be greatly appreciated, I have IDE v1.6.5
By the way, the __CLZ solution is brilliant, looks to be about 4 times faster than the for() loop.
Thanks in advance

Hi there @sharpx,

WInterrupts.c for Atmel's Due uC ATSAM3xE should be included in "$HOME/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino" (I´m using Arduino IDE 1.6.5) in Ubuntu 14.04 (the one I usually use), and in Windows last time I saw was something like "C:\Users<your-user-name>\AppData\Roaming\arduino15\packages\arduino\hardware\sam\1.6.4\cores\arduino".

If you can not find it there, maybe, have you changed your installation paths for the Arduino IDE?.

Best

@antodom
found it after I posted the message, crossed my mind to search the whole drive. There's probably a way to default installation to the same folder but since it works I'll leave it for now.
Thanks for the __CLZ trick, it's great - wish they added it to the dist since it's significantly faster especially if you're closer to the LSB, my 4+ times test was with bits 14 and 15.

Hi,

Does anyone know about a digitalIo library which works on the Due? This is the only one I'm missing at the moment, while I'm trying to migrate my gateway (NRF24L01, Ethernet shield) to Due from Mega...
Thank you!

@sharpx

I have already summited the WInterrupts.c improvement through a pull request for its inclusion in the Arduino standard library for the DUE. I hope it gets in soon.

Best.

Hi all,

This post is just to announce that the software serial library for the DUE, soft_uart (already mentioned in a previous post) is now on GitHub, in this link:

In addition, I would like to comment that the library has been improved with a new mode of operation in half-duplex, and a new bunch of examples illustrating its use. The library is completely compatible with the hardware serial objects Serial, Serial1, Serial2 and Serial3, and you can use the software serial objects provided by the library using the same serial API. Moreover, another improvement is that right now you can compile and upload the library and the examples on command line using CMake.

So far we have checked the library intensively with the hardware we have available, but any feedback or suggestion for improvement will be welcomed.

1 Like

is there an update to USB keyboard libs for the Due USB host port (HID, stdin), like on Raspberry Pi or on Windows PCs?

ArthurD:
is there meanwhile a reasonable USB keyb lib available feat. standard C keyboard functions (stdin) like e.g.

kbhit()
getch()
getche()
getchar()
gets()
scanf()

?

currently the implementation of the USB.task is really weird, keyPressed and keyReleased don't return anything and it's totally osbscured how and when they do either or anything meaningful,
currently it's not even possible to indicate if a key was hit at all or not (like provided by kbhit() ),
usb.Task has to be called repeatedly but then blocks program execution intermediately and repeatedly for many seconds (which is unconscionable in the main loop() but shockingly also hinders different additional Scheduler multitasking threads ).

looks and sounds as if the DUE finally has been abandoned by Arduino.cc (or at least is treated more than stepmotherly)

:frowning: :frowning:

Greetings to all.
@ josheeg i want to find eigen values and eigen vector of complex matrix in arduino. And don't know how to do that . I have downloaded your eigen library and also the one that is available at github,,

Actually i am converting a matlab code to arduino . I am using arduino due board . Below is the sample code of matlab that i want to convert in arduino

[V,Dia] = eig(Rxx);
[Y,Index] = sort(diag(Dia));
EN = V(:,Index(1:6-1));

Rxx is complex matrix of 6x6. I have created this matrix in arduino using complex.h library. Now i have to find eigen values and eigen vectors of this matrix. So what should i do ,can any one help?

ArthurD:
currently the implementation of the USB.task is really weird, keyPressed and keyReleased don't return anything and it's totally osbscured how and when they do either or anything meaningful,
currently it's not even possible to indicate if a key was hit at all or not (like provided by kbhit() ),
usb.Task has to be called repeatedly but then blocks program execution intermediately and repeatedly for many seconds (which is unconscionable in the main loop() but shockingly also hinders different additional Scheduler multitasking threads ).

I recently began investigating USB host on Due. The keyboard example works OK here. There is an OTG to host cable on the native port for the keyboard. The programming port is connected to a PC. External power is plugged into the barrel connector. The keyboard does not work without external power.

IDE 1.6.6, Due board package 1.6.6., Due USB Host library 1.0.4. Latest versions of everything.

I wish there were another non-HID example because the ADK example is very confusing. I hooked an Android tablet but nothing happens on the Due or the tablet. I guess I have to dig in and find out what app, if any, is required on the Android side. And turn on trace debug.

Some keyboard output.

Program started
Pressed:   key:20 mod:0 => q
Released:  key:20 mod:0 => q
Pressed:   key:26 mod:0 => w
Released:  key:26 mod:0 => w
Pressed:   key:8 mod:0 => e
Released:  key:8 mod:0 => e
Pressed:   key:21 mod:0 => r
Released:  key:21 mod:0 => r
Pressed:   key:23 mod:0 => t
Released:  key:23 mod:0 => t

Hi Guys,

I'm trying to implement the awesome TVOut library on the arduino due....

my results so far... Arduino DUE TVOut Library almost succeeded - YouTube

when I have the library working I'll upload it, for now, I think I'm getting somewhere...

by the way... this is the Sync Generation.... you may say it's like Grug from The Croods... but if you saw the video, it's working nice so far :wink:

volatile int syncON, syncOFF;
volatile int LineCount;
char v1;
int i, r;
int vLines;

#define HRes 744
#define VRes 240
#define ScreenRatioCorrection (VRes * 53 / 18) / HRes
const float AspectRatioY = 4301075 / 10000000;
#define LinesToWait 10
#define ArraySize int(HRes/8 * VRes)
#define ScreenTop 0
#define ScreenBot VRes - 1

#define NOP __asm__("nop\n\t")
#define NOP10 NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP
#define NOP100 NOP10;NOP10;NOP10;NOP10;NOP10;NOP10;NOP10;NOP10;NOP10;NOP10

#define NOPLineSync NOP100;NOP100;NOP10;NOP10;NOP10;NOP10;NOP10;NOP10;NOP;NOP;NOP;NOP;NOP;NOP;NOP//;NOP//NOP10
#define NOPPrePixels NOP100;NOP100;NOP100;NOP100;NOP//;NOP//;NOP//;NOP;NOP//;NOP//;NOP//;NOP  //NOPLineSync
#define NOPPixel400 NOP;NOP;NOP;NOP;NOP;
#define NOPPixel640 NOP//;NOP

void setup() {
  Serial.begin(115200);
  pinMode(2, OUTPUT);
  pinMode(23, OUTPUT);
  pinMode(3, OUTPUT);   // port B pin 25
  analogWrite(3, 255);  // sets up some other registers I haven't worked out yet
  REG_TC2_WPMR = 0x54494D00; // enable write to registers
  //               33222222222211111111110000000000
  //               10987654321098765432109876543210
  REG_TC2_CMR1 = 0b00000000000010011100010000000000;
  // 1/50/625*84000000 - 1 = 2688: 64uS PER LINE /PAL STD
  // 1/60/525*84000000 - 1 = 2669.5: 63.55uS PER LINE /NTSC STD
  REG_TC2_RC1 = 2670;
  REG_TC2_RA1 = 0;  // PWM value 4.7uS
  REG_TC2_CCR1 = 0b101;  // start counter
  REG_TC2_IER1 = 0b00010000; // enable interrupt on counter=rc
  REG_TC2_IDR1 = 0b11101111; // disable other interrupts
  NVIC_EnableIRQ(TC7_IRQn); // enable TC7 interrupts
  NVIC_SetPriority(TC7_IRQn, 0); //sets Interrupt Priority to top

  LineCount = 0;
  syncON = ~1 << 25; // PIOB.25-->Pin D2 on the board
  syncOFF = 1 << 25;

  draw_line(0, 0, 0, VRes - 1, 1);
  draw_line(0, VRes - 1, HRes - 1, VRes - 1, 1);
  draw_line(HRes - 1, VRes - 1, HRes - 1, 0, 1);
  draw_line(HRes - 1, 0, 0, 0, 1);

  draw_line(HRes / 2 - 1, 0, HRes / 2 - 1, VRes - 1, 1);
  draw_line(0, VRes / 2 - 1, HRes - 1, VRes / 2 - 1, 1);

  draw_circle(HRes / 2 - 1, VRes / 2 - 1, 240, 1, 0);
  DrawEllipse(HRes / 2 - 1, VRes / 2 - 1, 100, 50, 1, 0);
  draw_circle(HRes / 2 - 1, VRes / 2 - 1, 50, 2, 1);
  randomSeed(analogRead(0));

}

void TC7_Handler()  // Interrupt every 64.07uS (PALSTD)
{
  long dummy = REG_TC2_SR1; // vital - reading this clears some flag otherwise you get infinite interrupts start the Horizontal sync pulse
  
  // **************************
  // ***** Sync Generation ****
  // **************************
  PIOB->PIO_ODSR = syncON;
  if (LineCount <= ScreenBot) NOPLineSync; // Generates the 4.7uS 0V sync pulse
  if (LineCount == 248) {   syncON = 1 << 25;    syncOFF = ~1 << 25;    NOPLineSync;  }
  if (LineCount == 251) {   syncON = ~1 << 25;    syncOFF = 1 << 25;    NOPLineSync;  }
  if (LineCount == 263) {    LineCount = 0;    NOPLineSync;  }
  if (LineCount <= (ScreenBot) && LineCount >= (ScreenTop + LinesToWait)) {    i = (LineCount - LinesToWait) * HRes / 8;  }
  PIOB->PIO_ODSR = syncOFF;
  // **************************
  // ***** Sync Generation ****
  // **************************

  if ((LineCount) <= (ScreenBot) && (LineCount) >= (ScreenTop + LinesToWait))
  {
    NOPPrePixels;
    for (int j = 0; j < int(HRes / 8); j++) {
      v1 = screen[i + j] ;
      PIOA->PIO_ODSR = (v1 & 128) <<  7;//NOPPixel640;  // PIOA.14-->Pin D23 on the board
      PIOA->PIO_ODSR = (v1 &  64) <<  8;//NOPPixel640;
      PIOA->PIO_ODSR = (v1 &  32) <<  9;//NOPPixel640;
      PIOA->PIO_ODSR = (v1 &  16) << 10;//NOPPixel640;
      PIOA->PIO_ODSR = (v1 &   8) << 11;//NOPPixel640;
      PIOA->PIO_ODSR = (v1 &   4) << 12;//NOPPixel640;
      PIOA->PIO_ODSR = (v1 &   2) << 13;//NOPPixel640;
      PIOA->PIO_ODSR = (v1 &   1) << 14;//NOPPixel640;
    }  
    PIOA->PIO_ODSR = ~1 << 14;
  }
  LineCount++;

}

I thank Stimmer for the Due Timer and the TVOut library designer for this project, they were the inspiration...

Next... NTSC Video overlay (Video Experimenter @ Video Experimenter: Arduino shield that lets you do all kinds of experiments with video) :wink:

this is the Arduino MEGA overlay using Video Experimenter concept :Hud arduino mega - YouTube
cheers

Program started

Pressed:  key:20 mod:0 => q
Released:  key:20 mod:0 => q
Pressed:  key:26 mod:0 => w
Released:  key:26 mod:0 => w
Pressed:  key:8 mod:0 => e
Released:  key:8 mod:0 => e
Pressed:  key:21 mod:0 => r
Released:  key:21 mod:0 => r
Pressed:  key:23 mod:0 => t
Released:  key:23 mod:0 => t

this is not how it is expected to work.

It should work by stdio.h and possibly conio.h functionality like, e.g.

 char sbuf[20];
while(1) {
     if kbhit() {
        int c = getch();
        putchar(c);
        // or perhaps:
        // sprintf (sbuf, "%c", (char)c);
        // Serial.print(sbuf);
     }
     delay(10);   
  }

Hi all,

This post is just to anounce that I have developed a library for the DUE which takes advantage of several features of the Timer Counter (TC) modules available in Atmel's ATSAM3X8E.

The name of the library is tc_lib and it is openly available at:

In its initial operative version the library provides two kind of objects:

  • Capture objects. With these objects you can measure the period and pulse (duty) of a typical digital signal, like a PWM signal. In fact, the example provided measure the signal generated with analogWrite().
  • Action objects. These objects allow to associate a callback function to any of the TC channels (you have nine in total), such that the function its called with the period you establish. The resolution of the period is in microseconds.

You have available examples using both types of objects, I hope the examples are self-explaining.

More info about tc_lib in GitHub - antodom/tc_lib: This is a library to take advantage of different functionalities available on Timer Counter (TC) modules in Arduino Due's Atmel ATSAM3X8E microcontrollers.

Drop me a line if you have any question or interest.