Portenta_H7_TimerInterrupt Library

Working libraries, libraries being ported and related hardware
Post Reply
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Portenta_H7_TimerInterrupt Library

Post by khoih-prog »

Portenta_H7_TimerInterrupt Library

How To Install Using Arduino Library Manager


This library enables you to use Interrupt from Hardware Timers on an STM32H747XI-based Portenta_H7 board.
It now enables you to use up to 16 different ISR-based timers, while actually consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks.

Why do we need this Portenta_H7_TimerInterrupt Library

Imagine you have a system with a mission-critical function, measuring water level and control the sump pump or doing something much more important. You normally use asoftware timer to poll, or even place the function in loop(). But what if another function is blocking the loop() or setup().

So your function might not be executed, and the result would be disastrous.

You'd prefer to have your function called, no matter what happening with other functions (busy loop, bug, etc.).

The correct choice is to use a Hardware Timer with Interrupt to call your function.

These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.

Functions using normal software timers, relying on loop() and calling millis(), won't work if the loop() or setup() is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.

The catch is your function is now part of an ISR (Interrupt Service Routine), must be lean and mean, and follow certain rules. More to read on:

HOWTO Attach Interrupt


Important Notes:

1. Inside the ISR function, delay() won’t work and the value returned by millis() will not increment. Serial data received while in the ISR function may be lost. You should declare as volatile any variables that you modify within the attached function.

2. Typically global variables are used to pass data between an ISR and the main program. To make sure variables shared between an ISR and the main program are updated correctly, declare them as volatile.


Releases v1.2.1

1. Initial coding to support Portenta_H7 boards such as Portenta_H7 Rev2 ABX00042, etc., using ArduinoCore-mbed mbed_portenta
2. Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
3. Using cpp code besides Impl.h code to use if Multiple-Definition linker error.

Supported Boards

1. STM32H747XI-based Portenta_H7 using using ArduinoCore-mbed mbed_portenta


Examples:

1. Argument_None
2. Change_Interval
3. ISR_16_Timers_Array
4. ISR_16_Timers_Array_Complex
5. SwitchDebounce
6. TimerInterruptTest
7. TimerInterruptLEDDemo
Post Reply

Return to “Libraries & Hardware”