You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/simplefoc_library/cheatsheet/build_flags.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,9 @@ Build flags control the way the compiler generates the code for <span class="sim
21
21
Flag | Architecture | Description
22
22
--- | --- | ---
23
23
`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.
24
27
`SIMPLEFOC_STM32_DEBUG` | STM32 | set to enable extra debug output for STM32 MCUs.
25
28
`SIMPLEFOC_STM32_MAX_PINTIMERSUSED` | STM32 | maximum number of PWM pins configurable, default is 12 (up to 2x 6PWM, normally that's plenty)
26
29
`SIMPLEFOC_SAMD_DEBUG` | SAMD21 / SAMD51 | set to enable extra debug output for SAMD MCUs.
Copy file name to clipboardExpand all lines: docs/simplefoc_library/code/communication/commander/index.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ has_toc: false
12
12
13
13
# Commander interface
14
14
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.
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:
Copy file name to clipboardExpand all lines: docs/simplefoc_library/code/communication/commander/motion.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Motion control interface in the `Commander` can be integrated in user's applicat
25
25
26
26
27
27
## 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:
29
29
30
30
This feature is available to the user if any one of the three interfaces is added to the `Commander`.
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.
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.
13
14
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.
up to this moment ( [check the releases <iclass="fa fa-tag"></i>](https://github.com/simplefoc/Arduino-FOC/releases) ), Arduino <spanclass="simple">Simple<spanclass="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 <iclass="fa fa-tag"></i>](https://github.com/simplefoc/Arduino-FOC/releases) ), Arduino <spanclass="simple">Simple<spanclass="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).
24
24
25
25
Each one of the current sensing classes will implement all the necessary functionalities for simple and robust implementation of FOC algorithm:
26
26
- Hardware config
@@ -31,7 +31,7 @@ Each one of the current sensing classes will implement all the necessary functio
31
31
- Adaptive alignment with driver phases
32
32
- Reading the phase currents
33
33
- Calculation of the current vector magnitude
34
-
- Calculation of the FOC d and q currents
34
+
- Calculation of the FOC D and Q currents
35
35
36
36
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 <spanclass="simple">Simple<spanclass="foc">FOC</span>library</span>, see example codes in `utils > current_sense_test`.
37
37
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 | ✔️ | ❌ | ❌
63
63
nRF52 | ✔️ | ❌ | ❌
64
64
65
65
## Digging deeper
66
+
66
67
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).
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.
In-line current sensing is currently supported for almost all MCU architectures supported by the <spanclass="simple">Simple<spanclass="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 <spanclass="simple">Simple<spanclass="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.
To instantiate the inline current sensor using the <spanclass="simple">Simple<spanclass="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 <spanclass="simple">Simple<spanclass="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.
49
48
50
49
### Measuring 2 out of 3 currents
51
50
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