Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions docs/simplefoc_library/practical/choosing_pins.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ toc: true

# A short guide to choosing PWM pins for your application

When it comes to choosing pins for your application, there are a few things to consider. The most important thing is to make sure that the pins you choose are compatible with the hardware you are using.
When choosing pins for your application, there are a few things to consider. The most important thing is to make sure that the pins you choose are compatible with the hardware you are using.
Make sure to check that your microcontroller family and SimpleFOC supports the necessary PWM generation, position sensor and current sensing technique. You can find this info in our docs [here](microcontrollers).

Once you are sure that you microcontroller is apt to the application, it is time to consider which pins to use. There are three main questions:
After choosing an appropriate microcontroller, it is time to consider which pins to use. There are three main questions:
1. Which pins to use for PWM generation?
2. Which pins to use for the position sensor?
3. Which pins to use for current sensing?

In this guide we will focus on the first question: **Which pins to use for PWM generation?**
In this guide, we will focus on the first question: **Which pins to use for PWM generation?**

The answer to these questions depends on the microcontroller you are using and the hardware you have. Here is the list of microcontroller families supported by SimpleFOC and the PWM generation modes supported by each of them:

Expand All @@ -40,17 +40,17 @@ Portenta H7 | ✔️ | ✔️ | ✔️ | ❌ | ✔️ | ❌ | ❌
nRF52 |✔️ | ✔️ | ✔️ | ✔️ | ✔️| ❌ (2/3/4PWM) <br> ✔️ (6PWM) |❌
Renesas (UNO R4 Minima) | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ (2/3/4PWM) <br> ✔️ (6PWM) | ❌

What is important to see is that all the supported families can be used with 2/3/4PWM modes. However, not all the architectures support 6PWM mode. Additionally, the PWM frequency can be configured for all the supported architectures, but for Arduino AVR boards, the frequency can be set to either 4kHz or 32kHz.
Importantly, all supported families can be used with 2/3/4PWM modes. However, not all architectures support 6PWM mode. Additionally, the PWM frequency can be configured for all supported architectures, except Arduino AVR boards - the frequency can be set to either 4kHz or 32kHz.

Another important factor when it comes to choosing the PWM pins is to try to use the PWM pins that belong to the same timer. This is important because the PWM signals generated by the pins that belong to the same timer will have the same frequency and phase. This is important for the FOC algorithm to work properly.
Another important factor when choosing PWM pins is to attempt to use PWM pins that all belong to the same timer. This is important because the PWM signals generated by pins belonging to the same timer will have the same frequency and phase. This is important for the FOC algorithm to work properly.
The rule of thumb:
- For 2PWM mode, try using only one timer.
- For 3PWM mode, try using only one timer.
- For 4PWM mode, try using only one timer if possible, if not use one timer per phase (so two timers).
- For 6PWM mode, try using only one timer if possible, if not use one timer per phase (so three timers).
- For 4PWM mode, try using only one timer if possible, else, use one timer per phase (so two timers).
- For 6PWM mode, try using only one timer if possible, else, use one timer per phase (so three timers).

<blockquote class="info" markdown="1"><p class="heading">BEWARE: PWM center alignment</p>
SimpleFOC does synchronise (center-align) the PWM signals generated by different timers in some cases (as shown on the table above), but it is always better to use the pins that belong to the same timer.
SimpleFOC does synchronise (center-align) the PWM signals generated by different timers in some cases (as shown in the table above), but it is always better to use pins belonging to the same timer.
</blockquote>

<blockquote class="info" markdown="1"> <p class="heading">BEWARE: Timer-ADC sync - low-side current sensing</p>
Expand Down Expand Up @@ -155,7 +155,7 @@ ESP32-C6|6
ESP32-H2|6 (no arduino support yet)
ESP32-P4|8 (no arduino support yet) -->

If the user wants to force using the `LEDC` driver for the boards that support `MCPRM` he has to set the `SIMPLEFOC_ESP32_USELEDC`.
If the user wants to force using the `LEDC` driver for the boards that support `MCPRM`, they must set `SIMPLEFOC_ESP32_USELEDC`.

## STM32 boards

Expand All @@ -167,9 +167,9 @@ Stm32 is the most powerful family of microcontrollers supported by SimpleFOC, at

When it comes to 6PWM mode, the user has two choices:
1. Use the pins that belong to the same timer.
This is the recommended as all stm32 boards have timers typically `TIM1` and `TIM8` that are desigened for this applications and allow for the best performance.
This is the recommended solution, as all stm32 boards have timers, typically `TIM1` and `TIM8`, that are designed for these applications and allow for the best performance.
2. Use one timer per phase.
This is also a goof solution, especially if the pins necessary to use the advanced timers are not available. However, in this case the application uses 2 or 3 timers instead of 1 which might reduce the capacity of the microcontroller to do other tasks in parallel.
This is also a good solution, especially if the pins necessary to use the advanced timers are not available. However, in this case, the application uses 2 or 3 timers instead of 1, which might reduce the microcontroller's capacity to perform other tasks in parallel.

Once you provide the SimpleFOC driver object with a set of pins, the library will automatically associate the pins with the appropriate timers and channels and find the best combination for motor control. If the pins are not compatible with the motor control mode you are trying to use, the library will throw as error.

Expand Down