Portenta_H7_Slow_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_Slow_PWM Library

Post by khoih-prog »

Portenta_H7_Slow_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. Because this library doesn't use the powerful hardware-controlled PWM with channel / pin limitations, the maximum PWM frequency is currently limited at 1000Hz, which is suitable for many real-life applications.

It now supports 16 ISR-based synchronized PWM channels, while consuming only 1 Hardware Timer. PWM interval can be very long (uint32_t millisecs). The most important feature is they're ISR-based PWM channels. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware PWM channels, 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 PWM using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.


Releases v1.0.0

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 ISR-based PWM-channels, with frequency up to 1000Hz

Supported Boards

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


Examples:

1. ISR_16_PWMs_Array
2. ISR_16_PWMs_Array_Complex
3. ISR_16_PWMs_Array_Simple


Debug Terminal Output Sample

The following is the sample terminal output when running example ISR_16_PWMs_Array_Complex on Portenta_H7 to demonstrate how to use multiple PWM channels with complex callback functions, the accuracy of ISR Hardware PWM-channels, especially when system is very busy. The ISR PWM-channels is running exactly according to corresponding programmed periods and duty-cycles

Code: Select all

Starting ISR_16_PWMs_Array_Complex on PORTENTA_H7_M7
PORTENTA_H7_SLOW_PWM v1.0.0
[PWM] Portenta_H7_TimerInterrupt: Timer Input Freq (Hz) = 200000000
[PWM] Frequency = 1000000.00 , _count = 20
Starting ITimer OK, micros() = 3391815
Channel : 0	Period : 1000000		OnTime : 50000	Start_Time : 3392013
Channel : 1	Period : 500000		OnTime : 50000	Start_Time : 3392013
Channel : 2	Period : 333333		OnTime : 66666	Start_Time : 3392013
Channel : 3	Period : 250000		OnTime : 75000	Start_Time : 3392013
Channel : 4	Period : 200000		OnTime : 80000	Start_Time : 3392013
Channel : 5	Period : 166667		OnTime : 75000	Start_Time : 3392013
Channel : 6	Period : 142857		OnTime : 71428	Start_Time : 3392013
Channel : 7	Period : 125000		OnTime : 68750	Start_Time : 3392013
Channel : 8	Period : 111111		OnTime : 66666	Start_Time : 3392013
Channel : 9	Period : 100000		OnTime : 65000	Start_Time : 3392013
Channel : 10	Period : 66667		OnTime : 46666	Start_Time : 3392013
Channel : 11	Period : 50000		OnTime : 37500	Start_Time : 3392013
Channel : 12	Period : 40000		OnTime : 32000	Start_Time : 3392013
Channel : 13	Period : 33333		OnTime : 28333	Start_Time : 3392013
Channel : 14	Period : 25000		OnTime : 22500	Start_Time : 3392013
Channel : 15	Period : 20000		OnTime : 19000	Start_Time : 3392013
SimpleTimer (ms): 2000, us : 13335232, Dus : 9943221
PWM Channel : 0, programmed Period (us): 1000000, actual : 1000000, programmed DutyCycle : 5, actual : 5.00
PWM Channel : 1, programmed Period (us): 500000, actual : 500000, programmed DutyCycle : 10, actual : 10.00
PWM Channel : 2, programmed Period (us): 333333, actual : 333340, programmed DutyCycle : 20, actual : 20.00
PWM Channel : 3, programmed Period (us): 250000, actual : 250000, programmed DutyCycle : 30, actual : 30.00
PWM Channel : 4, programmed Period (us): 200000, actual : 200000, programmed DutyCycle : 40, actual : 39.99
PWM Channel : 5, programmed Period (us): 166667, actual : 166680, programmed DutyCycle : 45, actual : 44.99
PWM Channel : 6, programmed Period (us): 142857, actual : 142860, programmed DutyCycle : 50, actual : 49.99
PWM Channel : 7, programmed Period (us): 125000, actual : 124998, programmed DutyCycle : 55, actual : 55.00
PWM Channel : 8, programmed Period (us): 111111, actual : 111120, programmed DutyCycle : 60, actual : 59.99
PWM Channel : 9, programmed Period (us): 100000, actual : 100000, programmed DutyCycle : 65, actual : 65.00
PWM Channel : 10, programmed Period (us): 66667, actual : 66680, programmed DutyCycle : 70, actual : 69.98
PWM Channel : 11, programmed Period (us): 50000, actual : 50001, programmed DutyCycle : 75, actual : 75.00
PWM Channel : 12, programmed Period (us): 40000, actual : 40001, programmed DutyCycle : 80, actual : 80.00
PWM Channel : 13, programmed Period (us): 33333, actual : 33341, programmed DutyCycle : 85, actual : 84.94
PWM Channel : 14, programmed Period (us): 25000, actual : 25000, programmed DutyCycle : 90, actual : 89.91
PWM Channel : 15, programmed Period (us): 20000, actual : 20000, programmed DutyCycle : 95, actual : 95.00
SimpleTimer (ms): 2000, us : 23279451, Dus : 9944219
PWM Channel : 0, programmed Period (us): 1000000, actual : 1000000, programmed DutyCycle : 5, actual : 5.00
PWM Channel : 1, programmed Period (us): 500000, actual : 499999, programmed DutyCycle : 10, actual : 10.00
PWM Channel : 2, programmed Period (us): 333333, actual : 333340, programmed DutyCycle : 20, actual : 20.00
PWM Channel : 3, programmed Period (us): 250000, actual : 250000, programmed DutyCycle : 30, actual : 30.00
PWM Channel : 4, programmed Period (us): 200000, actual : 200000, programmed DutyCycle : 40, actual : 40.00
PWM Channel : 5, programmed Period (us): 166667, actual : 166680, programmed DutyCycle : 45, actual : 45.00
PWM Channel : 6, programmed Period (us): 142857, actual : 142860, programmed DutyCycle : 50, actual : 49.99
PWM Channel : 7, programmed Period (us): 125000, actual : 125000, programmed DutyCycle : 55, actual : 54.99
PWM Channel : 8, programmed Period (us): 111111, actual : 111135, programmed DutyCycle : 60, actual : 59.98
PWM Channel : 9, programmed Period (us): 100000, actual : 100000, programmed DutyCycle : 65, actual : 65.00
PWM Channel : 10, programmed Period (us): 66667, actual : 66680, programmed DutyCycle : 70, actual : 69.98
PWM Channel : 11, programmed Period (us): 50000, actual : 50000, programmed DutyCycle : 75, actual : 74.96
PWM Channel : 12, programmed Period (us): 40000, actual : 40000, programmed DutyCycle : 80, actual : 80.00
PWM Channel : 13, programmed Period (us): 33333, actual : 33340, programmed DutyCycle : 85, actual : 84.94
PWM Channel : 14, programmed Period (us): 25000, actual : 25000, programmed DutyCycle : 90, actual : 90.00
PWM Channel : 15, programmed Period (us): 20000, actual : 20000, programmed DutyCycle : 95, actual : 95.00
Post Reply

Return to “Libraries & Hardware”