Portenta_H7_PWM 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_PWM Library

Post by khoih-prog »

Portenta_H7_PWM Library

How To Install Using Arduino Library Manager

This library enables you to use Hardware Timers on an STM32H747XI-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.

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.


Releases v1.0.0

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


Supported Boards

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


Examples:

1. PWM_Multi
2. PWM_Multi_Args
3. PWMs_Array_Complex


Debug Terminal Output Sample

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.

Code: Select all

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
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: Portenta_H7_PWM Library

Post by khoih-prog »

Releases v2.0.0

1. Completely new code to fix no PWM output issue. Check No PWM-Output signals #1
2. To permit start, stop, change and restore the settings of any PWM channel on-the-fly

Debug Terminal Output Sample

The following is the sample terminal output when running example PWM_Multi on Portenta_H7 to demonstrate how to start multiple PWM channels, then stop, change, restore the PWM settings on-the-fly.

Code: Select all

Starting PWM_Multi on PORTENTA_H7_M7
Portenta_H7_PWM v2.0.0
[PWM] Freq = 1000.00, 	DutyCycle % = 50.00, 	DutyCycle = 0.50, 	Pin = 0
[PWM] Freq = 2500.00, 	DutyCycle % = 50.00, 	DutyCycle = 0.50, 	Pin = 1
[PWM] Freq = 4000.00, 	DutyCycle % = 50.00, 	DutyCycle = 0.50, 	Pin = 3
[PWM] Freq = 5000.00, 	DutyCycle % = 50.00, 	DutyCycle = 0.50, 	Pin = 5
[PWM] Freq = 50000.00, 	DutyCycle % = 50.00, 	DutyCycle = 0.50, 	Pin = 6

==========================================================================================================
PW (us) 0	PW (us) 1	PW (us) 2	PW (us) 3	PW (us) 4	
==========================================================================================================
500.00		200.00		125.00		100.00		10.00		
Stop all PWM
0.00		0.00		0.00		0.00		0.00		
0.00		0.00		0.00		0.00		0.00		
Change all PWM
125.00		50.00		31.25		25.00		2.50		
125.00		50.00		31.25		25.00		2.50		
Restore all PWM
500.00		200.00		125.00		100.00		10.00		
500.00		200.00		125.00		100.00		10.00		
Stop all PWM
0.00		0.00		0.00		0.00		0.00		
0.00		0.00		0.00		0.00		0.00		
Change all PWM
125.00		50.00		31.25		25.00		2.50		
125.00		50.00		31.25		25.00		2.50		
Restore all PWM
500.00		200.00		125.00		100.00		10.00		
500.00		200.00		125.00		100.00		10.00		
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: Portenta_H7_PWM Library

Post by khoih-prog »

Releases v2.0.1

1. Fix PWM_Multi example by not using HRTIM pinD3 and pinD6 at the same time
2. Temporary fix polarity for HRTIM PWM for core v2.6.1-. Check Portenta: PWM on HRTIM has inverted corner case values #352 To be modified when the issue is fixed.
Post Reply

Return to “Libraries & Hardware”