From 5feec228d068702edb8fe20557e13bb02f9cbc3e Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Sat, 21 Jan 2023 23:08:57 -0500 Subject: [PATCH] Add `PWM_StepperControl` example Credits of `Paul van Dinther` --- CONTRIBUTING.md | 11 ++++++++--- changelog.md | 5 +++++ library.json | 2 +- library.properties | 2 +- platformio/platformio.ini | 25 +++++++++++++++++++++++-- src/PWM_Generic_Debug.h | 9 ++------- src/Portenta_H7_PWM.h | 9 ++------- src/Portenta_H7_PWM.hpp | 15 +++++---------- src/Portenta_H7_PWM_Impl.h | 9 ++------- 9 files changed, 49 insertions(+), 38 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cab2af4..3ddb43c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,12 +10,14 @@ However, before reporting a bug please check through the following: If you don't find anything, please [open a new issue](https://github.com/khoih-prog/Portenta_H7_PWM/issues/new). +--- + ### How to submit a bug report Please ensure to specify the following: * Arduino IDE version (e.g. 1.8.19) or Platform.io version -* `ArduinoCore-mbed` Core Version (e.g. `ArduinoCore-mbed` mbed_portenta core v3.4.1) +* `ArduinoCore-mbed` Core Version (e.g. `ArduinoCore-mbed` mbed_portenta core v3.5.4) * `Portenta_H7` Board type (e.g. Portenta_H7 Rev2 ABX00042, etc.) * Contextual information (e.g. what you were trying to achieve) * Simplest possible steps to reproduce @@ -23,15 +25,18 @@ Please ensure to specify the following: * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` * Network configuration +Please be educated, civilized and constructive as you've always been. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted. + +--- ### Example ``` Arduino IDE version: 1.8.19 -`ArduinoCore-mbed` mbed_portenta core v3.4.1 +`ArduinoCore-mbed` mbed_portenta core v3.5.4 Portenta_H7 Rev2 ABX00042 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Context: I encountered a crash while using this library diff --git a/changelog.md b/changelog.md index 2bb19d7..2c86980 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Releases v2.0.3](#Releases-v203) * [Releases v2.0.2](#Releases-v202) * [Releases v2.0.1](#Releases-v201) * [Releases v2.0.0](#Releases-v200) @@ -26,6 +27,10 @@ ## Changelog +### Releases v2.0.3 + +1. Add example [PWM_StepperControl](https://github.com/khoih-prog/Portenta_H7_PWM/examples/PWM_StepperControl) to demo how to control Stepper Motor using PWM. Check [Using PWM to step a stepper driver #16](https://github.com/khoih-prog/RP2040_PWM/issues/16) + ### Releases v2.0.2 1. Convert to `h-only` code diff --git a/library.json b/library.json index c4ae78a..0f4fc2a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Portenta_H7_PWM", - "version": "2.0.2", + "version": "2.0.3", "keywords": "timing, device, control, timer, pwm, interrupt, isr, isr-based, hardware-timer, mission-critical, accuracy, non-blocking, mbed, mbed-portenta, portenta-h7, portentah7, portenta-h7-m7, portenta-h7-m4, portentah7-m7, portentah7-m4, stm32h7, stm32, precise, hardware", "description": "This library enables you to use Hardware Timers on an STM32H7-based Portenta_H7 board to create and output PWM to pins. These PWM channels, using Portenta_H7 Hardware Timers, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software ir ISR-based PWM, using millis(), micros() or Timer Interrupt. This important feature is absolutely necessary for mission-critical tasks. You can start, stop, change and restore the settings of any PWM channel on-the-fly.", "authors": diff --git a/library.properties b/library.properties index 7fc3890..bd70ca7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Portenta_H7_PWM -version=2.0.2 +version=2.0.3 author=Khoi Hoang maintainer=Khoi Hoang sentence=This library enables you to use Hardware Timers on an STM32H7-based Portenta_H7 board to create and output PWM to pins. diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 219a2c9..eb2afea 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -8,6 +8,8 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +; ============================================================ +; ============================================================ [platformio] ; ============================================================ ; chose environment: @@ -27,6 +29,8 @@ default_envs = portenta_h7_m7 ;default_envs = portenta_h7_m4 +; ============================================================ +; ============================================================ [env] ; ============================================================ ; Serial configuration @@ -37,30 +41,38 @@ upload_speed = 921600 ;monitor_speed = 9600 ;monitor_port = COM11 +; ============================================================ ; Checks for the compatibility with frameworks and dev/platforms lib_compat_mode = strict lib_ldf_mode = chain+ ;lib_ldf_mode = deep+ +; ============================================================ lib_deps = - +; ============================================================ build_flags = ; set your debug output (default=Serial) ; -D DEBUG_ESP_PORT=Serial ; comment the following line to enable WiFi debugging ; -D NDEBUG +; ============================================================ +; ============================================================ [env:portenta_h7_m7] platform = ststm32 board = portenta_h7_m7 framework = arduino +; ============================================================ +; ============================================================ [env:portenta_h7_m4] platform = ststm32 board = portenta_h7_m4 framework = arduino +; ============================================================ +; ============================================================ [env:pico] ; ============================================================ ; Just a sample @@ -71,6 +83,8 @@ board = pico framework = arduino upload_protocol = picotool +; ============================================================ +; ============================================================ [env:ESP8266] platform = espressif8266 framework = arduino @@ -116,6 +130,8 @@ board = nodemcuv2 ;board = xinabox_cw01 ;board = esp32doit-devkit-v1 +; ============================================================ +; ============================================================ [env:ESP32] platform = espressif32 framework = arduino @@ -157,6 +173,8 @@ board = esp32doit-devkit-v1 ;board = iotbusproteus ;board = nina_w10 +; ============================================================ +; ============================================================ [env:SAMD] platform = atmelsam framework = arduino @@ -230,7 +248,8 @@ board = adafruit_itsybitsy_m4 ;board = rolawan ;board = seeed_grove_ui_wireless - +; ============================================================ +; ============================================================ [env:NRF52] platform = nordicnrf52 framework = arduino @@ -251,6 +270,8 @@ board = feather52840 ;board = ninab302 ;board = ninab112 +; ============================================================ +; ============================================================ [env:STM32] platform = ststm32 framework = arduino diff --git a/src/PWM_Generic_Debug.h b/src/PWM_Generic_Debug.h index f0019c0..56facd5 100644 --- a/src/PWM_Generic_Debug.h +++ b/src/PWM_Generic_Debug.h @@ -6,13 +6,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_PWM Licensed under MIT license - Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by - unsigned long miliseconds), you just consume only one Portenta_H7 STM32 timer and avoid conflicting with other cores' tasks. - The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers - Therefore, their executions are not blocked by bad-behaving functions / tasks. - This important feature is absolutely necessary for mission-critical tasks. - - Version: 2.0.2 + Version: 2.0.3 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +14,7 @@ 2.0.0 K.Hoang 10/12/2021 Use new library code and examples 2.0.1 K.Hoang 11/12/2021 Fix PWM_Multi example. Temporary fix polarity for HRTIM PWM 2.0.2 K.Hoang 07/02/2022 Convert to h-only. Optimize code. + 2.0.3 K.Hoang 21/01/2023 Add `PWM_StepperControl` example *****************************************************************************************************************************/ #pragma once diff --git a/src/Portenta_H7_PWM.h b/src/Portenta_H7_PWM.h index 035f9b9..39b296d 100644 --- a/src/Portenta_H7_PWM.h +++ b/src/Portenta_H7_PWM.h @@ -6,13 +6,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_PWM Licensed under MIT license - Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by - unsigned long miliseconds), you just consume only one Portenta_H7 STM32 timer and avoid conflicting with other cores' tasks. - The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers - Therefore, their executions are not blocked by bad-behaving functions / tasks. - This important feature is absolutely necessary for mission-critical tasks. - - Version: 2.0.2 + Version: 2.0.3 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +14,7 @@ 2.0.0 K.Hoang 10/12/2021 Use new library code and examples 2.0.1 K.Hoang 11/12/2021 Fix PWM_Multi example. Temporary fix polarity for HRTIM PWM 2.0.2 K.Hoang 07/02/2022 Convert to h-only. Optimize code. + 2.0.3 K.Hoang 21/01/2023 Add `PWM_StepperControl` example *****************************************************************************************************************************/ #pragma once diff --git a/src/Portenta_H7_PWM.hpp b/src/Portenta_H7_PWM.hpp index 7ba746d..c0df0b8 100644 --- a/src/Portenta_H7_PWM.hpp +++ b/src/Portenta_H7_PWM.hpp @@ -6,13 +6,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_PWM Licensed under MIT license - Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by - unsigned long miliseconds), you just consume only one Portenta_H7 STM32 timer and avoid conflicting with other cores' tasks. - The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers - Therefore, their executions are not blocked by bad-behaving functions / tasks. - This important feature is absolutely necessary for mission-critical tasks. - - Version: 2.0.2 + Version: 2.0.3 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +14,7 @@ 2.0.0 K.Hoang 10/12/2021 Use new library code and examples 2.0.1 K.Hoang 11/12/2021 Fix PWM_Multi example. Temporary fix polarity for HRTIM PWM 2.0.2 K.Hoang 07/02/2022 Convert to h-only. Optimize code. + 2.0.3 K.Hoang 21/01/2023 Add `PWM_StepperControl` example *****************************************************************************************************************************/ #pragma once @@ -34,13 +29,13 @@ #endif #ifndef PORTENTA_H7_PWM_VERSION - #define PORTENTA_H7_PWM_VERSION "Portenta_H7_PWM v2.0.2" + #define PORTENTA_H7_PWM_VERSION "Portenta_H7_PWM v2.0.3" #define PORTENTA_H7_PWM_VERSION_MAJOR 2 #define PORTENTA_H7_PWM_VERSION_MINOR 0 - #define PORTENTA_H7_PWM_VERSION_PATCH 2 + #define PORTENTA_H7_PWM_VERSION_PATCH 3 - #define PORTENTA_H7_PWM_VERSION_INT 2000002 + #define PORTENTA_H7_PWM_VERSION_INT 2000003 #endif diff --git a/src/Portenta_H7_PWM_Impl.h b/src/Portenta_H7_PWM_Impl.h index 7921677..611bc78 100644 --- a/src/Portenta_H7_PWM_Impl.h +++ b/src/Portenta_H7_PWM_Impl.h @@ -6,13 +6,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_PWM Licensed under MIT license - Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by - unsigned long miliseconds), you just consume only one Portenta_H7 STM32 timer and avoid conflicting with other cores' tasks. - The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers - Therefore, their executions are not blocked by bad-behaving functions / tasks. - This important feature is absolutely necessary for mission-critical tasks. - - Version: 2.0.2 + Version: 2.0.3 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +14,7 @@ 2.0.0 K.Hoang 10/12/2021 Use new library code and examples 2.0.1 K.Hoang 11/12/2021 Fix PWM_Multi example. Temporary fix polarity for HRTIM PWM 2.0.2 K.Hoang 07/02/2022 Convert to h-only. Optimize code. + 2.0.3 K.Hoang 21/01/2023 Add `PWM_StepperControl` example *****************************************************************************************************************************/ #ifndef Portenta_H7_PWM_IMPL_H