SAMD51/Feather M4 timer interrupts

i'm looking for info on how to use the SAMD51 timers, to generate interrupts. i'm reasonably experienced and can read the datasheets though (1) i'd rather not and (2) it won't tell me about Arduino API and library stuff. any suggestions or hints anyone?

all i need is to set timer X to N ticks and have it generate an interrupt when the count reaches zero. two or more independent timers.

the project is a high-performance automotive ignition system. it derives crankshaft position via reluctor that generates a hardware interrupt. that ISR calculates timing for charging and firing coils, charge and fire each require a high-res counter timer. 32 bit timers at the fastest (CPU) clock rate is best.

i've got it all working on a TI chip (TM4C123GXL, lots of timers) but TI decided to make that chip hard to use (...), the SAMD51 is "better" and i'd rather give my money to Adafruit anyway.

I’m not aware of any “abstracted” timer library for Arduino (ie one that works across multiple chip architectures.)

The tm4c123 will run Arduino code, you know. Via “energia”

i guess i was misleading with my TM4C* statement. all i meant by that was that i'm comfortable with that level of hardware programming. i realize there's no portability or abstraction across processors (or even within, D21 is different than D51). and yeah i was using Energia. TI did dumb stuff with some library code (licensing USB, etc) that killed it for me. also Adafruit stuff is great, and the atmel ARMs seem likely to be around for a while.

it may be that Adafruit ZeroTimer does what i want. the SAMD51 has complex peripherals; i was hoping just to minimize my learning curve about untangling it all, and not breaking millis()/micros(), PWM stuff, etc.

i need precision mainly for low jitter in my hardware handling.

i've found Adafruit_ZeroTimer, and trying to modify it to support one-shot timers, which is what i need. i've got a thread on the Adafruit forum, which may be more appropriate; also i get hours and hours of 500 BAD GATEWAY trying to read this forum, so it's hard to check in.

once i get the thing working i'll submit it on github. it ought to be a fairly minor change.

if anyone here is in the position to test it i'll upload the files here.

I was struggling with setting up an interrupt service routine (ISR) timer on a SAMD51 as well on an Adafruit M4 Feather Express board. I have made a library which can be used for this. The method names are identical to the ZeroTimer library for M0 boards (SAMD21) such that it is easy to port from SAMD21 to SAMD51.

See GitHub: GitHub - Dennis-van-Gils/SAMD51_InterruptTimer: SAMD51 Interrupt Timer library for e.g. Adafruit M4 Metro/Feather/ItsyBitsy Express

Usage:

#include <Arduino.h>
#include "SAMD51_InterruptTimer.h"

void myISR() {
  // Your code
}

void setup() {
  TC.startTimer(50, myISR); // Call myISR() every 50 usec
}

Have fun,
Dennis van Gils