🛠 Timers matériels, interruptions imbriquées et FASTRUN : la vitesse Cortex-M4

Teensy 3.2 · intermediaire · Schéma : IMG-teensy-32-intermediaire-6-teensy32-timers-dma-vitesse.svg — Teensy 3.2 en coupe conceptuelle : au centre le Cortex-M4 à 72 MHz avec ses deux bus 32 bits, autour les périphériques timing étiquetés PDB, CMT, LPTMR, 4x PIT, FTM (PWM) ; flèches vers 16 canaux DMA et le contrôleur d'interruptions imbriquées ; la LED 13 clignote pilotée par un timer.

Objectives

Move away from delay and polling: the Teensy 3.2 hides a true real-time powerhouse — a Nested Vectored Interrupt Controller (NVIC) with priorities, 16 general-purpose DMA channels, a suite of timers (PDB, CMT, LPTMR, 4 PIT counters, PWM FTM timers), the FASTRUN keyword for executing functions from RAM, and a dual 32-bit bus (simultaneous instruction fetch + data). This tutorial blinks LED 13 using a hardware IntervalTimer and measures the gains of a tight toggle loop.

Hardware

Complete Code

digitalToggle and the IntervalTimer class are documented on the PJRC shop page (sections Digital Output Pins / Timing):

#include <IntervalTimer.h>

IntervalTimer t1;
volatile bool flashing = false;

void flash {           // execute depuis un timer materiel, pas la boucle
  digitalToggle(13);     // broche 13 = LED orange integrée
}

void setup {
  pinMode(13, OUTPUT);
  t1.priority(0);        // attention : sur Teensy, 0 = priorite LA PLUS haute
  t1.begin(flash, 500000); // appelle flash toutes les 500 ms (en us)
}

void loop {
  // Pour la vitesse brute, digitalToggle en boucle serrée bat les paires
  // digitalWrite ; pour une forme d'onde précise, pilotez une broche PWM.
}

Speeding Up the Code

Expected Verification

LED 13 blinks at exactly 1 Hz, even if loop is busy with a calculation loop — proof that the hardware timer works independently. Comment out flash in the code: the LED stays fixed, and your main code continues. On an oscilloscope connected to a freely toggling pin, measure the maximum frequency, then compare it with digitalToggle driven by an IntervalTimer at 1 µs.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials