Skip to content

Commit 6c7a9a8

Browse files
committed
index updated + added more info about characterisatioN
1 parent 92fd0a6 commit 6c7a9a8

File tree

5 files changed

+137
-34
lines changed

5 files changed

+137
-34
lines changed

docs/simplefoc_library/code/motors/bldc_motors.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ You can also use the provided libray examples `examples/utils/calibration/find_K
5151
</blockquote>
5252

5353

54-
### Motor phase resistance and KV rating
54+
### Motor phase resistance, inductance and KV rating
5555
Providing the KV rating in combination with the phase resistance (not very used for current based torque modes `foc_current` and `dc_current`) will enable the user to control the motor's current without measuring it. The user will be able to control (and limit) the estimated current of the motor using the voltage control mode. Read more in the [torque control docs](voltage_torque_mode).
5656

5757
Working with currents instead of voltages is better in may ways, since the torque of the BLDC motor is proportional to the current and not voltages and especially since the same voltage value will produce very different currents for different motors (due to the different phase resistance). Once when the phase resistance is provided the user will be able to set current limit for its BLDC motor instead of voltage limit which is much easier to understand.
@@ -65,6 +65,90 @@ Finally, this parameter is suggested to be used if one whats to switch in real t
6565
KV rating and the pahse resitance values will be used in te open loop contol as well to let the user to limit the current drawn by the motor instead of limitting the volatge. Read more in the <a href="open_loop_motion_control">open-loop motion control docs</a>.
6666
</blockquote>
6767

68+
### How can I measure the phase resistance and inductance?
69+
70+
The phase resistance is relatively easy to measure, you can use a multimeter to measure the resistance of the motor phases. Here is a [short guide ](phase_resistance) on how to measure the phase resistance and inductance of a BLDC motor. The phase inductance is a bit more complicated to measure as not many multimeters can measure inductance directly.
71+
72+
However, <span class="simple">Simple<span class="foc">FOC</span>library</span> provides the tools to measure the motor phase resistance and inductance. In order to measure them you will need to be able to measure the current.
73+
74+
Once you have the current sensor set up, you can use the `motor.characteriseMotor()` function to measure the phase resistance and inductance. This function will run a series of tests to determine these parameters and will print them to the serial monitor.
75+
76+
77+
<blockquote class="info">
78+
79+
<details markdown="1">
80+
<summary style="cursor: pointer;"> <i class="fa fa-code"></i> Example code for motor phase characterisation </summary>
81+
82+
```cpp
83+
84+
#include <SimpleFOC.h>
85+
86+
// Stepper motor & BLDC driver instance
87+
BLDCMotor motor = BLDCMotor(11);
88+
// SimpleFOCShield
89+
BLDCDriver3PWM driver = BLDCDriver3PWM(6, 10, 5, 8);
90+
91+
// inline current sensor instance
92+
// ACS712-05B has the resolution of 0.185mV per Amp
93+
LowsideCurrentSense current_sense = LowsideCurrentSense(185.0f, A0, A2);
94+
95+
void setup() {
96+
97+
// use monitoring with serial
98+
Serial.begin(115200);
99+
// enable more verbose output for debugging
100+
// comment out if not needed
101+
SimpleFOCDebug::enable(&Serial);
102+
103+
// driver config
104+
// power supply voltage [V]
105+
driver.voltage_power_supply = 20;
106+
driver.init();
107+
// link driver
108+
motor.linkDriver(&driver);
109+
// link current sense and the driver
110+
current_sense.linkDriver(&driver);
111+
112+
// current sense init and linking
113+
current_sense.init();
114+
motor.linkCurrentSense(&current_sense);
115+
116+
// initialise motor
117+
motor.init();
118+
119+
// find the motor parameters
120+
motor.characteriseMotor(3.5f);
121+
122+
123+
_delay(1000);
124+
}
125+
126+
127+
void loop() {
128+
// do nothing
129+
_delay(1000);
130+
}
131+
```
132+
133+
The output of the `characteriseMotor` function will be printed to the serial monitor and will look like this:
134+
135+
```
136+
MOT: Init
137+
MOT: Enable driver.
138+
MOT: Measuring phase to phase resistance, keep motor still...
139+
MOT: Estimated phase to phase resistance: 5.94
140+
MOT: Measuring inductance, keep motor still...
141+
MOT: Inductance measurement complete!
142+
MOT: Measured D-inductance in mH: 0.50
143+
MOT: Measured Q-inductance in mH: 0.59
144+
```
145+
146+
For the moment <span class="simple">Simple<span class="foc">FOC</span>library</span> considers the inductance value to be the same for q and d axis. So once the example is executed use the q axis inductance value for `motor.phase_inductance`.
147+
148+
</details>
149+
</blockquote>
150+
151+
68152
## Step 2. Linking the sensor
69153
Once when you have the `motor` defined and the sensor initialized you need to link the `motor` and the `sensor` by executing:
70154
```cpp

docs/simplefoc_library/practical/choosing_pins.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ stm32 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
3232
esp32 MCPWM | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
3333
esp32 LEDC | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌
3434
esp8266 | ✔️ | ✔️ | ✔️ | ❌ | ✔️ | ❌ | ❌
35-
samd21/51 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ (2/3/4PWM) <br> ✔️ (6PWM) |
35+
samd21/51 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ (2/3/4PWM) <br> ✔️ (6PWM) | ✔️ (samd21 only - Synced with the 1st Timer ) <br> ❌(samd51)
3636
teensy3 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ (2/3/4PWM) <br> ✔️ (6PWM) | ❌
3737
teensy4 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌(2/3/4PWM)<br>✔️ (6PWM)<br> ✔️(3PWM forced) | ❌(2/3/4PWM)<br>✔️(6PWM)<br> ✔️(3PWM aligned)
3838
Raspberry Pi Pico | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ (2/3/4PWM) <br> ✔️ (6PWM) | ❌
@@ -122,12 +122,14 @@ So when using esp32 boards that have `MCPWM` module (ex. `esp32` and `esp32s3`)
122122
This association of the appropriate timer and chanel for your applications will be done automatically by the SimpleFOC.
123123

124124

125-
ESP32 SoC | has `MCPWM`
125+
ESP32 SoC | has `MCPWM`
126126
--- | ---
127127
ESP32 | ✔️
128128
ESP32-S2| ❌
129+
ESP32-C2 | ❌
129130
ESP32-S3| ✔️
130131
ESP32-C3 | ❌
132+
ESP32-C6 | ✔️
131133

132134
<!-- ESP32-C6 | ?
133135
ESP32-H2 | ?
@@ -145,7 +147,9 @@ ESP32 SoC | Number of LEDC channels
145147
ESP32 | 16
146148
ESP32-S2|8
147149
ESP32-S3|8
150+
ESP32-C2|6
148151
ESP32-C3|6
152+
ESP32-C6|6
149153

150154
<!-- ESP32-C6|6 (no arduino support yet)
151155
ESP32-H2|6 (no arduino support yet)

docs/simplefoc_library/practical/choosing_pins_adc.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ ESP32 SoC |`ADC1` pins | `ADC2` pins
7979
ESP32 | GPIO32 - GPIO39 | GPIO0, GPIO2, GPIO4, GPIO12 - GPIO15, GOIO25 - GPIO27
8080
ESP32-S2| GPIO1 - GPIO10 | GPIO11 - GPIO20
8181
ESP32-S3| GPIO1 - GPIO10 | GPIO11 - GPIO20
82+
ESP32-C2 | GPIO0 - GPIO4 | -
8283
ESP32-C3 | GPIO0 - GPIO4 | GPIO5
83-
84+
ESP32-C6 | GPIO0 - GPIO6 | -
85+
8486
<blockquote class="info" markdown="1"><p class="heading">Important</p>
8587
Esp32 has a very flexible ADC configuration, so you can use any of the pins listed above for the low-side current sensing. However, it is recommended to use the pins that belong to the same `ADC`.
8688
</blockquote>

docs/simplefoc_library/practical/real_time_loop.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ void loop() {
8282

8383
```
8484

85+
<blockquote class="info">
86+
<p class="heading">ℹ️ Which timer to use?</p>
87+
You can use any timer that is available on the microcontroller, but make sure not to use the timers that are used by the motor driver or the position sensor. For the STM32 family, the timers used with the PWM will be displayed in the serial monitor when you run the `motor.init()` function. You can aslo see the timers used by the pins in the docs (find your mcufamily and pins) [see here](https://docs.simplefoc.com/stm32pinouts/)
88+
</blockquote>
89+
90+
8591
## ESP32
8692

8793
Esp32 microcontrollers have a similar approach to the STM32 family, but the implementation is a bit different. You can use the `hw_timer` library to create a timer that will call the `motor.loopFOC()` and `motor.move()` functions at a fixed frequency. Here is an example of how to do this:
@@ -93,6 +99,8 @@ Esp32 microcontrollers have a similar approach to the STM32 family, but the impl
9399
// instatiate the motor, dirver, sensor and other components
94100
...
95101

102+
hw_timer_t *timer = NULL;
103+
96104
void IRAM_ATTR foc_loop() {
97105
// call the loopFOC and move functions
98106
motor.loopFOC();
@@ -103,16 +111,14 @@ void setup() {
103111

104112
// iniitalise all the components
105113

106-
107114
// create a hardware timer
108-
// For example, we will use the timer 0 that runs at 10kHz
109-
hw_timer_t * timer = timerBegin(0, 80, true);
115+
// 1mhz timer
116+
timer = timerBegin(1000000);
110117
// attach the interrupt
111-
timerAttachInterrupt(timer, &foc_loop, true);
112-
// set the timer frequency to 10kHz
113-
timerAlarmWrite(timer, 10000, true);
114-
// start the timer
115-
timerAlarmEnable(timer);
118+
timerAttachInterrupt(timer, &foc_loop);
119+
// Set alarm to call foc_loop every 100us (10kHz)
120+
timerAlarm(timer, 100, true, 0);
121+
116122

117123
_delay(1000);
118124
}
@@ -125,6 +131,16 @@ void loop() {
125131
command.run();
126132
}
127133
```
134+
135+
<blockquote class="info">
136+
See more info in the <a href="https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/api/timer.html#example-applications">ESP32 Espressif API documentation</a>.
137+
</blockquote>
138+
139+
<blockquote class="warning" markdown="1">
140+
<p class="heading">⚠️ Warning:</p>
141+
Make sure not to set the timer frequency too high. If the `motor.loopFOC()` and `motor.move()` functions take longer to execute than the timer interval, the timer may miss calls or overload the microcontroller. This can cause the motor to malfunction or even crash the microcontroller.
142+
</blockquote>
143+
128144
## Other microcontrollers
129145

130146
Most of the other microcontrollers have similar approaches to the STM32 and ESP32 families, but the implementation might be different. You can check the documentation of the specific microcontroller you are using to see how to create a timer that will call the `motor.loopFOC()` and `motor.move()` functions at a fixed frequency.
@@ -139,9 +155,5 @@ Examples:
139155

140156

141157

142-
### Which timer to use?
143-
You can use any timer that is available on the microcontroller, but make sure not to use the timers that are used by the motor driver or the position sensor. For the STM32 family, the timers used with the PWM will be displayed in the serial monitor when you run the `motor.init()` function. For the ESP32 family, you can use any of the available timers, but make sure to check the documentation for the specific timer you are using.
144-
145-
146158
### Monitoring and user communication no longer working (or any other functionality)
147159
If you notice that the motor monitoring and user communication are no longer working properly, it is likely that the timer frequency is too high and the `motor.loopFOC()` and `motor.move()` functions are taking too long to execute. In this case, you can try to reduce the timer frequency or increase the execution time of the `motor.loopFOC()` and `motor.move()` functions by adding a delay in the timer interrupt.

index.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permalink: /
88
# Arduino Simple Field Oriented Control (FOC) project
99

1010
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
11-
![arduino-library-badge](https://ardubadge.simplefoc.com?lib=Simple%20FOC)
11+
![arduino-library-badge](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
1212
![PlatformIO Registry](https://badges.registry.platformio.org/packages/askuric/library/Simple%20FOC.svg)
1313
[![status](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d/status.svg)](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d)
1414

@@ -28,24 +28,25 @@ Therefore this is an attempt to:
2828
- Many many more boards developed by the community members, see [<span class="simple">Simple<span class="foc">FOC</span> Community</span>](https://community.simplefoc.com/)
2929

3030
<blockquote class="info" markdown="1">
31-
<p class="heading">NEW RELEASE 📢: <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.4 <a href="https://github.com/simplefoc/Arduino-FOC/releases/tag/v2.3.4">see release</a></p>
32-
- ESP32 MCUs extended support [#414](https://github.com/simplefoc/Arduino-FOC/pull/414)
33-
- Transition to the arduino-esp32 version v3.x (ESP-IDF v5.x) [#387](https://github.com/espressif/arduino-esp32/releases)
34-
- New support for MCPWM driver
35-
- New support for LEDC drivers - center-aligned PWM and 6PWM available
36-
- Rewritten and simplified the fast ADC driver code (`adcRead`) - for low-side and inline current sensing.
37-
- Stepper motors current sensing support [#421](https://github.com/simplefoc/Arduino-FOC/pull/421)
38-
- Support for current sensing (low-side and inline) - [see in docs](current_sense)
39-
- Support for true FOC control - `foc_current` torque control - [see in docs](motion_control)
40-
- New current sense alignment procedure [#422](https://github.com/simplefoc/Arduino-FOC/pull/422) - [see in docs](current_sense_align)
41-
- Support for steppers
42-
- Much more robust and reliable
43-
- More verbose and informative
44-
- Support for HallSensors without interrupts [#4224](https://github.com/simplefoc/Arduino-FOC/pull/424) - [see in docs](hall_sensors)
31+
<p class="heading">NEW RELEASE 📢: <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.5 <a href="https://github.com/simplefoc/Arduino-FOC/releases/tag/v2.3.5">see release</a></p>
32+
33+
- ESP32 bugfix
34+
- after the low-level API changes in the Arduino-ESP32 core [PR447](https://github.com/simplefoc/Arduino-FOC/pull/447)
35+
- Pin is not configured [PR458](https://github.com/simplefoc/Arduino-FOC/pull/458)
36+
- C6 MCPWM bugfix [PR440](https://github.com/simplefoc/Arduino-FOC/pull/440)
37+
- New fuctionality
38+
- HybridStepperMotor added to the main library [PR457](https://github.com/simplefoc/Arduino-FOC/pull/457) - [see in docs](steppermotor)
39+
- Motor characterisation (phase resistance and inductance) [PR436](https://github.com/simplefoc/Arduino-FOC/pull/436) - [see in docs](bldcmotor#how-can-i-measure-the-phase-resistance-and-inductance)
40+
- SAMD21 support for low-side current sensing [PR479](https://github.com/simplefoc/Arduino-FOC/pull/479)
41+
- RP2350 support [PR435](https://github.com/simplefoc/Arduino-FOC/pull/435) [PR468](https://github.com/simplefoc/Arduino-FOC/pull/468)
42+
- STM32
43+
- New driver code [PR442](https://github.com/simplefoc/Arduino-FOC/pull/442)
44+
- Low-side current sensing support for H7 family [PR460](https://github.com/simplefoc/Arduino-FOC/pull/460)
4545
- Docs
46-
- A short guide to debugging of common issues - [see in docs](example_from_scratch)
47-
- A short guide to the units in the library - [see in docs](library_units)
48-
- See the complete list of bugfixes and new features of v2.3.4 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/11)
46+
- Hybrid stepper motor example [see in docs](stepper_control_shield)
47+
- Sensorless FOC example [see in docs](sensorless_foc_nucleo_example)
48+
- A short guide to synchronous loop - [see in docs](real_time_loop)
49+
- See the complete list of bugfixes and new features of v2.3.5 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/12)
4950
</blockquote>
5051

5152
# Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> <small>- [Read more ...](arduino_simplefoc_library_showcase)</small>

0 commit comments

Comments
 (0)