Skip to content
Merged

Dev #13

Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
_site
Gemfile.lock
node_modules
.jekyll-cache
.jekyll-cache
bin/just-the-docs
assets/images/.DS_Store
Binary file removed .jekyll-metadata
Binary file not shown.
3 changes: 3 additions & 0 deletions docs/simplefoc_library/cheatsheet/build_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Build flags control the way the compiler generates the code for <span class="sim
Flag | Architecture | Description
--- | --- | ---
`SIMPLEFOC_DISABLE_DEBUG` | All | set this to disable the entire debugging code
`SIMPLEFOC_PWM_ACTIVE_HIGH` | STM32, RP2040 | sets PWM polarity on phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects both high and low side in 6-PWM mode
`SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH` | STM32, RP2040 | sets PWM polarity on low side phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects only low side FETs in 6-PWM mode. No effect in other modes.
`SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH` | STM32, RP2040 | sets PWM polarity on high side phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects only high side FETs in 6-PWM mode. No effect in other modes.
`SIMPLEFOC_STM32_DEBUG` | STM32 | set to enable extra debug output for STM32 MCUs.
`SIMPLEFOC_STM32_MAX_PINTIMERSUSED` | STM32 | maximum number of PWM pins configurable, default is 12 (up to 2x 6PWM, normally that's plenty)
`SIMPLEFOC_SAMD_DEBUG` | SAMD21 / SAMD51 | set to enable extra debug output for SAMD MCUs.
Expand Down
3 changes: 1 addition & 2 deletions docs/simplefoc_library/code/communication/commander/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ has_toc: false

# Commander interface

Commander is a simple and flexible interface monitoring, supervision, configuration and control using the G-code like communication protocol. The communication is based on `ASCII` character command ids which makes simple and efficient to parse on any mcu. After the command id has been received the function attached to this command is called and provided the remaining string of characters received which follows the command character.
Commander is a simple and flexible interface monitoring, supervision, configuration and control using the G-code like communication protocol. The communication is based on `ASCII` character command ids which makes simple and efficient to parse on any MCU. After the command id has been received the function attached to this command is called and provided the remaining string of characters received which follows the command character.

<img src="extras/Images/cmd_motor.gif" class="img100">
<img src="extras/Images/cmd_motor_get.gif" class="img100">
Expand Down Expand Up @@ -166,7 +166,6 @@ void loop(){
}
```
Or maybe you wish to tune the velocity PID and you and change the target value of the motor and you wish to remove unnecessary memory overhead due to the other functionalities you do nto necessarily need, then your code could look something like:
something like this:
```cpp
BLDCMotor motor = .....
Commander commander = ....
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Motion control interface in the `Commander` can be integrated in user's applicat


## Target setting in one line
Commander interface enables the user to set the target value for the motion control as well as the limits at once. However different motion control strategies have different numbers of limits (angle, velocity, torque) so depending of the motion control mode used the behavior of the command will change:
Commander interface enables the user to set the target value for the motion control as well as the limits at once. However different motion control strategies have different numbers of limits (angle, velocity, torque) so depending of the motion control mode used the behaviour of the command will change:

This feature is available to the user if any one of the three interfaces is added to the `Commander`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void loop(){
}
```

You will be able to configure (set and get) itfrom serial monitor:
You will be able to configure (set and get) it from serial monitor:
```sh
$ ? # list available commands
A: my variable
Expand Down
2 changes: 1 addition & 1 deletion docs/simplefoc_library/code/communication/step_dir.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ step_dir.attach(&my_value);
```

<blockquote class="warning"><p class="heading">⚠️ BEWARE: Suboptimal performance</p>
The simplest forms of communication such as step/dir are designed to be handled in hardware and software, interrupt based, implementation of these communication interfaces is usually not the optimal solution. It will provide the user a good base for testing purposes, but it is hard guarantee long-term robustness.
The simplest forms of communication such as step/dir are designed to be handled in hardware and software, interrupt based, implementation of these communication interfaces is usually not the optimal solution. It will provide the user a good base for testing purposes, but it is hard to guarantee long-term robustness.
</blockquote>


Expand Down
5 changes: 4 additions & 1 deletion docs/simplefoc_library/code/current_sense/high_side.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</sp
---

# High-side current sensing

High-side current sensing is probably the least common current sensing technique form the three discussed in this library. The main reason why is because it requires high-voltage supporting amplifiers. The shunt resistors are placed in between high-side mosfets and the DC power supply voltage, making the amplifiers always have high voltages on their terminals. The other drawback of this approach is that since the current passing through the shunt resistors is phase current only if the corresponding high side mosfet is on we can only measure it in those moments. The PWM frequency is usually 20 to 50 kHz, which means that the high-side mosfets turns on and off 20,000 to 50,000 times per second, therefore the synchronization in between PWM setting and ADC acquisition is very very important.

High-side current sensing will be implemented later in the process, once when inline and low-side sensing is supported. The main issue at the moment is very hardware specific synchronisation procedure of the PWM generation and ADC triggering. Therefore it is possible that this implantation will be done one MCU architecture at the time.
High-side current sensing will be implemented later in the process, once when inline and low-side sensing is supported. The main issue at the moment is very hardware specific synchronisation procedure of the PWM generation and ADC triggering. Therefore it is possible that this implementation will be done one MCU architecture at a time.


<img src="extras/Images/high-side.png" class="width50">
<img src="extras/Images/high_side_sync.png" class="width40">
5 changes: 3 additions & 2 deletions docs/simplefoc_library/code/current_sense/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> ha

<img src="extras/Images/comparison_cs.png" class="width40">

up to this moment ( [check the releases <i class="fa fa-tag"></i>](https://github.com/simplefoc/Arduino-FOC/releases) ), Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> supports in-line current sensing for almost all platforms and low-side current sensing on ESP32 boards, stm32 (f1, f4 and g4 families - one motor), samd21 (one motor) and on the stm32 based B_G431B_ESC1 boards (one motor).
up to this moment ( [check the releases <i class="fa fa-tag"></i>](https://github.com/simplefoc/Arduino-FOC/releases) ), Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> supports in-line current sensing for almost all platforms and low-side current sensing on ESP32 boards, stm32 (f1, f4 and g4 families - one motor), SAMD21 (one motor) and on the STM32 based B-G431B-ESC1 boards (one motor).

Each one of the current sensing classes will implement all the necessary functionalities for simple and robust implementation of FOC algorithm:
- Hardware config
Expand All @@ -31,7 +31,7 @@ Each one of the current sensing classes will implement all the necessary functio
- Adaptive alignment with driver phases
- Reading the phase currents
- Calculation of the current vector magnitude
- Calculation of the FOC d and q currents
- Calculation of the FOC D and Q currents

Each of the implemented classes can be used as stand-alone classes and they can be used to read current values on BLDC driver outputs out of scope of the Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>, see example codes in `utils > current_sense_test`.
In order for FOC algorithm to work the current sense classes are linked to a `BLDCMotor` class which uses the driver to read the FOC currents.
Expand Down Expand Up @@ -63,4 +63,5 @@ Portenta H7 | ✔️ | ❌ | ❌
nRF52 | ✔️ | ❌ | ❌

## Digging deeper

For more theoretical explanations and source code implementations of the current sensing and its integration into the FOC and motion check out the [digging deeper section](digging_deeper).
21 changes: 10 additions & 11 deletions docs/simplefoc_library/code/current_sense/inline.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@ grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</sp

# In-line current sensing

Inline current sensing technique is the simplest one to use and the most precise one. The shunt resistors are placed in-line with motor phases and the current measured on these shunt resistors will be motor phase current regardless of the state of the PWM duty cycle. This implementation is therefore very suitable for Arduino devices due to the fact that adc can be sampled at any time to read the current and the adc acquisition duration is as important as for the other current sensing approaches. The downside of this approach is the hardware, this current sensing architecture requirers high-precision bidirectional amplifiers with much better PWM rejection than the regular low-side or high-side amplifiers.
Inline current sensing technique is the simplest one to use and the most precise one. The shunt resistors are placed in-line with motor phases and the current measured on these shunt resistors will be motor phase current regardless of the state of the PWM duty cycle. This implementation is therefore very suitable for Arduino devices due to the fact that adc can be sampled at any time to read the current and the adc acquisition duration is not as important as for the other current sensing approaches. The downside of this approach is the hardware, this current sensing architecture requires high-precision bidirectional amplifiers with much better PWM rejection than the regular low-side or high-side amplifiers.

<img src="extras/Images/in-line.png" class="width60"><img src="extras/Images/comparison_cs.png" class="width30">


## Current sensing support per MCU architecture

In-line current sensing is currently supported for almost all MCU architectures supported by the <span class="simple">Simple<span class="foc">FOC</span>library</span>. Only not supported architecture is teh ESP8266 which does not have 2 ADC pins, making it unable to run FOC.
In-line current sensing is currently supported for almost all MCU architectures supported by the <span class="simple">Simple<span class="foc">FOC</span>library</span>. The only not supported architecture is the ESP8266 which does not have 2 ADC pins, making it unable to run FOC.

MCU | In-line Current sensing
--- | ---
Arduino (8-bit) | ✔️
Arduino DUE | ✔️
stm32 | ✔️
stm32 B_G431B_ESC1 | ❌
esp32/esp32s3 |✔️
esp32s2/esp32c3 |❌
esp8266 | ❌
samd21 | ✔️
samd51 | ✔️
teensy | ✔️
STM32 | ✔️
STM32 B_G431B_ESC1 | ✔️
ESP32 | ✔️
ESP8266 | ❌
SAMD21 | ✔️
SAMD51 | ✔️
Teensy | ✔️
Raspberry Pi Pico | ✔️
Portenta H7 | ✔️

Expand All @@ -45,7 +44,7 @@ Portenta H7 | ✔️
// - phC - C phase adc pin (optional)
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 20, A0, A1, A2);
```
To instantiate the inline current sensor using the <span class="simple">Simple<span class="foc">FOC</span>library</span> just create an instance of the class `InlineCurrentSense`. This class takes as a parameter shunt resistance value `shunt_resistor`, amplification gain `gain` and two or three ADC channel pins depending on the available measuring hardware that you might have. It is important to specify right adc channels for right driver/motor phase. So if your pin `A0` measures the phase current `A` and pin `A1` measures the phase current `B` make sure to put provide them to the constructor in that order.
To instantiate the inline current sensor using the <span class="simple">Simple<span class="foc">FOC</span>library</span> just create an instance of the class `InlineCurrentSense`. This class takes as a parameter shunt resistance value `shunt_resistor`, amplification gain `gain` and two or three ADC channel pins depending on the available measuring hardware that you might have. It is important to specify right adc channels for right driver/motor phase. So if your pin `A0` measures the phase current `A` and pin `A1` measures the phase current `B` make sure to provide them to the constructor in that order.

### Measuring 2 out of 3 currents
Field Oriented Control algorithm can run with both 2 or 3 phase current measurements. If measuring 2 out of 3 currents, when defining your `InlineCurrentSense` class put the flag `_NC` (not connected) to the phase value you are not using.
Expand Down
34 changes: 16 additions & 18 deletions docs/simplefoc_library/code/current_sense/low_side.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@ Low side current sensing for all the architectures is on our road-map and we are

## Current sensing support per MCU architecture

Low side current sensing is currently supported for several MCU architectures supported by the <span class="simple">Simple<span class="foc">FOC</span>library</span>. ESP32 architecture has the most generic support, supporting multiple motors per chip. Stm32 families f1, f4 and g4 are initially supported and support low-side sensing for only one motor. A special case of the stm32 board is the BG431_ESC1 development kit which has very specific low-side implementation for its hardware configuration, and it is fully supported by the library. Samd21 architecture is under development, it has an initial support for only one motor, but for now as it has not been extensively tested, we suggest not to rely on our implementation.
Low side current sensing is currently supported for several MCU architectures supported by the <span class="simple">Simple<span class="foc">FOC</span>library</span>. ESP32 architecture has the most generic support, supporting multiple motors per chip. Stm32 families f1, f4 and g4 are initially supported and support low-side sensing for only one motor. A special case of the STM32 board is the B-G431-ESC1 development kit which has very specific low-side implementation for its hardware configuration, and it is fully supported by the library. Samd21 architecture is under development, it has an initial support for only one motor, but for now as it has not been extensively tested, we suggest not to rely on our implementation.

MCU | Low-side Current sensing
--- | ---
Arduino (8-bit) | ❌
Arduino DUE | ❌
stm32 (in general) |❌
stm32f1 family | ✔️ (one motor)
stm32f4 family | ✔️ (one motor)
stm32g4 family | ✔️ (one motor)
stm32 B_G431B_ESC1 | ✔️ (one motor)
esp32/esp32s3 |✔️
esp32s2/esp32c3 |❌
esp8266 | ❌
samd21 | ✔️/❌ (one motor, poorly tested)
samd51 | ❌
teensy | ❌
STM32 (in general) |❌
STM32f1 family | ✔️ (one motor)
STM32f4 family | ✔️ (one motor)
STM32g4 family | ✔️ (one motor)
STM32 B_G431B_ESC1 | ✔️
ESP32 |✔️
ESP8266 | ❌
SAMD21 | ✔️/❌ (one motor, poorly tested)
SAMD51 | ❌
Teensy | ❌
Raspberry Pi Pico | ❌
Portenta H7 | ❌

Expand Down Expand Up @@ -68,7 +67,7 @@ driver.pwm_frequency = 20000;

####  2. PWM pin considerations

As ADC conversion has to be synchronised with the PWM generated on ALL the phases, it is important that all the PWM generated for all the phases have aligned PWM. Since the microcontrollers usually have more than one timer for PWM generation on its pins, different architectures of microcontrollers have different degrees of alinement in between the PWM generated from different timers.
As ADC conversion has to be synchronised with the PWM generated on ALL the phases, it is important that all the PWM generated for all the phases have aligned PWM. Since the microcontrollers usually have more than one timer for PWM generation on its pins, different architectures of microcontrollers have different degrees of alignment in between the PWM generated from different timers.


<blockquote class="info">
Expand Down Expand Up @@ -172,10 +171,10 @@ else{
}
```

Once when your current sense has been intialised and calibrated you can start measuring the currents!
When your current sense has been intialised and calibrated you can start measuring the currents!

## Using the current sense with FOC algorithm
To use the `LowsideCurrentSense` with the FOC algorithm all you need to do is to add it to link it with the `BLDCMotor` you wish to use it with:
To use the `LowsideCurrentSense` with the FOC algorithm all you need to do is link it with the `BLDCMotor` you wish to use it with:
```cpp
// link motor and current sense
motor.linkCurrentSense(&current_sense);
Expand Down Expand Up @@ -234,8 +233,7 @@ If you are sure in your configuration and if you wish to skip the alignment proc
current_sense.skip_align = true;
```

For example [AliExpress DRV8302 board](https://fr.aliexpress.com/wholesale?catId=0&initiative_id=SB_20211003032006&SearchText=bldc+drv8302) , you would have a code similar to this:
For example, Arduino <span class="simple">Simple<span class="foc">FOC</span>Shield</span> v2, you would have a code similar to this:
For example for the [AliExpress DRV8302 board](https://fr.aliexpress.com/wholesale?catId=0&initiative_id=SB_20211003032006&SearchText=bldc+drv8302), you would have code similar to this:
```cpp
// one possible combination of current sensing pins for SimpleFOCShield v2
// shunt - 5milliOhm
Expand Down Expand Up @@ -273,7 +271,7 @@ See the full example for the Aliexpress DRB8302 based board in the library examp
## Standalone current sense

Since the low-side current sense has to be synchornised with PWM of a driver of interest it does not make sense to use it as a stand-alone sensor.
But once when you linked the current sense with the `BLDCMotor` you can use it to read your phase currents, overall current magnitude and DQ currents.
But once you have linked the current sense with the `BLDCMotor` you can use it to read your phase currents, overall current magnitude and DQ currents.

Reading the phase currents can be done by calling:
```cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ grand_grand_parent: Writing the Code
grand_grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
---

# BLDC driver 3PWM - `BLDCDriver3PWM`
# BLDC driver 3 PWM - `BLDCDriver3PWM`

This is the class which provides an abstraction layer of most of the common 3PWM bldc drivers out there. Basically any BLDC driver board that can be run using 3PWM signals can be represented with this class.
Examples:
- Arduino <span class="simple">Simple<span class="foc">FOC</span>Shield</span>
- Arduino <span class="simple">Simple<span class="foc">FOC</span> <span class="power">Power</span>Shield</span>
- L6234 breakout board
- HMBGC v2.2
- DRV830x ( can be run in 3pwm or 6pwm mode )
- DRV830x ( can be run in 3 PWM or 6 PWM mode )
- X-NUCLEO-IHM07M1
- etc.

Expand Down Expand Up @@ -180,7 +180,7 @@ void loop() {
}
```

An example code of the BLDC driver with three enable pins, one for each phase. This code will put one phase at the time to the high-impedance mode and pun 3 and 6 Volts on the remaining two.
An example code of the BLDC driver with three enable pins, one for each phase. This code will put one phase at the time to the high-impedance mode and put 3 and 6 Volts on the remaining two.
```cpp
// BLDC driver standalone example
#include <SimpleFOC.h>
Expand Down
Loading