Skip to content

Commit 0ce902f

Browse files
authored
Merge pull request #13 from simplefoc/dev
Dev
2 parents 03cdb2d + ea5dcf0 commit 0ce902f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+201
-168
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
_site
55
Gemfile.lock
66
node_modules
7-
.jekyll-cache
7+
.jekyll-cache
8+
bin/just-the-docs
9+
assets/images/.DS_Store

.jekyll-metadata

-52.6 KB
Binary file not shown.

docs/simplefoc_library/cheatsheet/build_flags.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Build flags control the way the compiler generates the code for <span class="sim
2121
Flag | Architecture | Description
2222
--- | --- | ---
2323
`SIMPLEFOC_DISABLE_DEBUG` | All | set this to disable the entire debugging code
24+
`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
25+
`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.
26+
`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.
2427
`SIMPLEFOC_STM32_DEBUG` | STM32 | set to enable extra debug output for STM32 MCUs.
2528
`SIMPLEFOC_STM32_MAX_PINTIMERSUSED` | STM32 | maximum number of PWM pins configurable, default is 12 (up to 2x 6PWM, normally that's plenty)
2629
`SIMPLEFOC_SAMD_DEBUG` | SAMD21 / SAMD51 | set to enable extra debug output for SAMD MCUs.

docs/simplefoc_library/code/communication/commander/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ has_toc: false
1212

1313
# Commander interface
1414

15-
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.
15+
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.
1616

1717
<img src="extras/Images/cmd_motor.gif" class="img100">
1818
<img src="extras/Images/cmd_motor_get.gif" class="img100">
@@ -166,7 +166,6 @@ void loop(){
166166
}
167167
```
168168
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:
169-
something like this:
170169
```cpp
171170
BLDCMotor motor = .....
172171
Commander commander = ....

docs/simplefoc_library/code/communication/commander/motion.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Motion control interface in the `Commander` can be integrated in user's applicat
2525

2626

2727
## Target setting in one line
28-
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:
28+
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:
2929

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

docs/simplefoc_library/code/communication/commander/scalar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void loop(){
3434
}
3535
```
3636
37-
You will be able to configure (set and get) itfrom serial monitor:
37+
You will be able to configure (set and get) it from serial monitor:
3838
```sh
3939
$ ? # list available commands
4040
A: my variable

docs/simplefoc_library/code/communication/step_dir.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ step_dir.attach(&my_value);
6363
```
6464

6565
<blockquote class="warning"><p class="heading">⚠️ BEWARE: Suboptimal performance</p>
66-
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.
66+
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.
6767
</blockquote>
6868

6969

docs/simplefoc_library/code/current_sense/high_side.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</sp
99
---
1010

1111
# High-side current sensing
12+
1213
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.
1314

14-
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.
15+
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.
16+
17+
1518
<img src="extras/Images/high-side.png" class="width50">
1619
<img src="extras/Images/high_side_sync.png" class="width40">

docs/simplefoc_library/code/current_sense/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> ha
2020

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

23-
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).
23+
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).
2424

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

3636
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`.
3737
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.
@@ -63,4 +63,5 @@ Portenta H7 | ✔️ | ❌ | ❌
6363
nRF52 | ✔️ | ❌ | ❌
6464

6565
## Digging deeper
66+
6667
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).

docs/simplefoc_library/code/current_sense/inline.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,26 @@ grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</sp
1010

1111
# In-line current sensing
1212

13-
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.
13+
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.
1414

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

1717

1818
## Current sensing support per MCU architecture
1919

20-
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.
20+
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.
2121

2222
MCU | In-line Current sensing
2323
--- | ---
2424
Arduino (8-bit) | ✔️
2525
Arduino DUE | ✔️
26-
stm32 | ✔️
27-
stm32 B_G431B_ESC1 | ❌
28-
esp32/esp32s3 |✔️
29-
esp32s2/esp32c3 |❌
30-
esp8266 | ❌
31-
samd21 | ✔️
32-
samd51 | ✔️
33-
teensy | ✔️
26+
STM32 | ✔️
27+
STM32 B_G431B_ESC1 | ✔️
28+
ESP32 | ✔️
29+
ESP8266 | ❌
30+
SAMD21 | ✔️
31+
SAMD51 | ✔️
32+
Teensy | ✔️
3433
Raspberry Pi Pico | ✔️
3534
Portenta H7 | ✔️
3635

@@ -45,7 +44,7 @@ Portenta H7 | ✔️
4544
// - phC - C phase adc pin (optional)
4645
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 20, A0, A1, A2);
4746
```
48-
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.
47+
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.
4948

5049
### Measuring 2 out of 3 currents
5150
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.

0 commit comments

Comments
 (0)