The Long Path to SAMD21 Input Capture

With the AVR-based Arduino boards, doing an input capture in a timer/counter (to time stamp a signal edge) was very simple, although not supported in the Arduino library. It’s just three instructions to completely configure.

With the SAMD21 it becomes a major programming effort to get an external signal to the timer/counter.

  • Configure pin to connect to External Interrupt Controller (EIC). 2 instructions.
  • Configure EIC: turn on EIC module, configure input (from pin) to sense a high level, enable this interrupt to cause an event. 5 instructions.
  • Configure the event system: power it up (Power Manager), connect the Generic Clock 0 (48MHz) to power the Event System channel 0. Configure channel 0 to source from the external interrupt event to the timer/counter event input. 5 instructions.
  • Configure the timer/counter. Part of this is to enable event capture. This takes 2 instructions.

So 14 instructions. And the timer/counter still needs additional configuration to use, in my case another 12 instructions, or 26 total. It may be a versatile part but it sure is involved to use! And you have no choice other than directly configure since it’s not supported in the Arduino library.