Portenta_H7_PWM Library

Portenta_H7_PWM library GitHub release
How To Install Using Arduino Library Manager


Features

This library enables you to use Hardware Timers on an STM32H7-based Portenta_H7 board to create and output PWM to pins.

The most important feature is they're purely hardware-based PWM channels. Therefore, the frequency can be higher than hybrid or software-based PWM, and their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks.

This important feature is absolutely necessary for mission-critical tasks. 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.

The PWMs_Array_Complex example will demonstrate the nearly perfect accuracy, compared to software-based PWM, by printing the actual period / duty-cycle in microsecs of each of PWM-channels.

The PWM_Multi_Args will demonstrate the usage of multichannel PWM using multiple Hardware Timers. The 4 independent Hardware Timers are used to control 4 different PWM outputs, with totally independent frequencies and dutycycles.


Currently Supported Boards

This Portenta_H7_PWM library currently supports the following boards:

  1. Portenta_H7 boards, using ArduinoCore-mbed mbed_portenta core


Changelog

Initial Releases v1.0.0

  1. Initial coding to support Portenta_H7 boards such as Portenta_H7 Rev2 ABX00042, etc., using ArduinoCore-mbed mbed_portenta core

Examples

  1. PWM_Multi
  2. PWM_Multi_Args
  3. PWMs_Array_Complex

Debug Terminal Output Sample

1. PWMs_Array_Complex on PORTENTA_H7_M7

The following is the sample terminal output when running example PWMs_Array_Complex on Portenta_H7 to demonstrate the accuracy of Hardware-based PWM, especially when system is very busy.

Starting PWMs_Array_Complex on PORTENTA_H7_M7
Portenta_H7_PWM v1.0.0
Index = 0, Instance = 0x40010000, channel = 3, TimerIndex = 0
Index = 1, Instance = 0x40000800, channel = 1, TimerIndex = 3
Index = 2, Instance = 0x40010400, channel = 2, TimerIndex = 7
Index = 3, Instance = 0x40001800, channel = 2, TimerIndex = 8
SimpleTimer (ms): 2000, us : 12659505, Dus : 9933701
PWM Channel : 0, programmed Period (us): 500000, actual : 499994, programmed DutyCycle : 20, actual : 20.00
PWM Channel : 1, programmed Period (us): 200000, actual : 199999, programmed DutyCycle : 30, actual : 30.00
PWM Channel : 2, programmed Period (us): 100000, actual : 100000, programmed DutyCycle : 50, actual : 50.00
PWM Channel : 3, programmed Period (us): 10000, actual : 10000, programmed DutyCycle : 70, actual : 70.00
SimpleTimer (ms): 2000, us : 22594086, Dus : 9934581
PWM Channel : 0, programmed Period (us): 500000, actual : 499994, programmed DutyCycle : 20, actual : 20.00
PWM Channel : 1, programmed Period (us): 200000, actual : 199998, programmed DutyCycle : 30, actual : 30.00
PWM Channel : 2, programmed Period (us): 100000, actual : 99999, programmed DutyCycle : 50, actual : 50.00
PWM Channel : 3, programmed Period (us): 10000, actual : 10000, programmed DutyCycle : 70, actual : 70.00
SimpleTimer (ms): 2000, us : 32528951, Dus : 9934865
PWM Channel : 0, programmed Period (us): 500000, actual : 499994, programmed DutyCycle : 20, actual : 20.00
PWM Channel : 1, programmed Period (us): 200000, actual : 199999, programmed DutyCycle : 30, actual : 30.00
PWM Channel : 2, programmed Period (us): 100000, actual : 100000, programmed DutyCycle : 50, actual : 50.00
PWM Channel : 3, programmed Period (us): 10000, actual : 10001, programmed DutyCycle : 70, actual : 69.99
SimpleTimer (ms): 2000, us : 42463635, Dus : 9934684
PWM Channel : 0, programmed Period (us): 500000, actual : 499994, programmed DutyCycle : 20, actual : 20.00
PWM Channel : 1, programmed Period (us): 200000, actual : 199999, programmed DutyCycle : 30, actual : 30.00
PWM Channel : 2, programmed Period (us): 100000, actual : 99999, programmed DutyCycle : 50, actual : 50.00
PWM Channel : 3, programmed Period (us): 10000, actual : 10000, programmed DutyCycle : 70, actual : 69.99
SimpleTimer (ms): 2000, us : 52398502, Dus : 9934867
PWM Channel : 0, programmed Period (us): 500000, actual : 499994, programmed DutyCycle : 20, actual : 20.00
PWM Channel : 1, programmed Period (us): 200000, actual : 199998, programmed DutyCycle : 30, actual : 30.00
PWM Channel : 2, programmed Period (us): 100000, actual : 99999, programmed DutyCycle : 50, actual : 50.00
PWM Channel : 3, programmed Period (us): 10000, actual : 10000, programmed DutyCycle : 70, actual : 70.00