Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
Add PWM_StepperControl example
Browse files Browse the repository at this point in the history
Credits of `Paul van Dinther`
  • Loading branch information
khoih-prog authored Jan 22, 2023
1 parent 25fc807 commit 5feec22
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 38 deletions.
11 changes: 8 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,33 @@ 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
* Anything that might be relevant in your opinion, such as:
* 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
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Portenta_H7_PWM
version=2.0.2
version=2.0.3
author=Khoi Hoang <[email protected]>
maintainer=Khoi Hoang <[email protected]>
sentence=This library enables you to use Hardware Timers on an STM32H7-based Portenta_H7 board to create and output PWM to pins.
Expand Down
25 changes: 23 additions & 2 deletions platformio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

; ============================================================
; ============================================================
[platformio]
; ============================================================
; chose environment:
Expand All @@ -27,6 +29,8 @@
default_envs = portenta_h7_m7
;default_envs = portenta_h7_m4

; ============================================================
; ============================================================
[env]
; ============================================================
; Serial configuration
Expand All @@ -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
Expand All @@ -71,6 +83,8 @@ board = pico
framework = arduino
upload_protocol = picotool

; ============================================================
; ============================================================
[env:ESP8266]
platform = espressif8266
framework = arduino
Expand Down Expand Up @@ -116,6 +130,8 @@ board = nodemcuv2
;board = xinabox_cw01
;board = esp32doit-devkit-v1

; ============================================================
; ============================================================
[env:ESP32]
platform = espressif32
framework = arduino
Expand Down Expand Up @@ -157,6 +173,8 @@ board = esp32doit-devkit-v1
;board = iotbusproteus
;board = nina_w10

; ============================================================
; ============================================================
[env:SAMD]
platform = atmelsam
framework = arduino
Expand Down Expand Up @@ -230,7 +248,8 @@ board = adafruit_itsybitsy_m4
;board = rolawan
;board = seeed_grove_ui_wireless


; ============================================================
; ============================================================
[env:NRF52]
platform = nordicnrf52
framework = arduino
Expand All @@ -251,6 +270,8 @@ board = feather52840
;board = ninab302
;board = ninab112

; ============================================================
; ============================================================
[env:STM32]
platform = ststm32
framework = arduino
Expand Down
9 changes: 2 additions & 7 deletions src/PWM_Generic_Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
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
------- ----------- ---------- -----------
1.0.0 K.Hoang 21/09/2021 Initial coding for Portenta_H7 using ArduinoCore-mbed mbed_portenta core
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
Expand Down
9 changes: 2 additions & 7 deletions src/Portenta_H7_PWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
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
------- ----------- ---------- -----------
1.0.0 K.Hoang 21/09/2021 Initial coding for Portenta_H7 using ArduinoCore-mbed mbed_portenta core
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
Expand Down
15 changes: 5 additions & 10 deletions src/Portenta_H7_PWM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
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
------- ----------- ---------- -----------
1.0.0 K.Hoang 21/09/2021 Initial coding for Portenta_H7 using ArduinoCore-mbed mbed_portenta core
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
Expand All @@ -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


Expand Down
9 changes: 2 additions & 7 deletions src/Portenta_H7_PWM_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
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
------- ----------- ---------- -----------
1.0.0 K.Hoang 21/09/2021 Initial coding for Portenta_H7 using ArduinoCore-mbed mbed_portenta core
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
Expand Down

0 comments on commit 5feec22

Please sign in to comment.