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/code/motors/bldc_motors.md
+85-1Lines changed: 85 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ You can also use the provided libray examples `examples/utils/calibration/find_K
51
51
</blockquote>
52
52
53
53
54
-
### Motor phase resistance and KV rating
54
+
### Motor phase resistance, inductance and KV rating
55
55
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).
56
56
57
57
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
65
65
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 <ahref="open_loop_motion_control">open-loop motion control docs</a>.
66
66
</blockquote>
67
67
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, <spanclass="simple">Simple<spanclass="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
+
<blockquoteclass="info">
78
+
79
+
<detailsmarkdown="1">
80
+
<summarystyle="cursor: pointer;"> <iclass="fa fa-code"></i> Example code for motor phase characterisation </summary>
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 <spanclass="simple">Simple<spanclass="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
+
68
152
## Step 2. Linking the sensor
69
153
Once when you have the `motor` defined and the sensor initialized you need to link the `motor` and the `sensor` by executing:
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`.
Copy file name to clipboardExpand all lines: docs/simplefoc_library/practical/real_time_loop.md
+24-12Lines changed: 24 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,12 @@ void loop() {
82
82
83
83
```
84
84
85
+
<blockquoteclass="info">
86
+
<pclass="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
+
85
91
## ESP32
86
92
87
93
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
93
99
// instatiate the motor, dirver, sensor and other components
94
100
...
95
101
102
+
hw_timer_t *timer = NULL;
103
+
96
104
void IRAM_ATTR foc_loop() {
97
105
// call the loopFOC and move functions
98
106
motor.loopFOC();
@@ -103,16 +111,14 @@ void setup() {
103
111
104
112
// iniitalise all the components
105
113
106
-
107
114
// 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);
110
117
// 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
+
116
122
117
123
_delay(1000);
118
124
}
@@ -125,6 +131,16 @@ void loop() {
125
131
command.run();
126
132
}
127
133
```
134
+
135
+
<blockquoteclass="info">
136
+
See more info in the <ahref="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
+
<blockquoteclass="warning"markdown="1">
140
+
<pclass="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
+
128
144
## Other microcontrollers
129
145
130
146
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:
139
155
140
156
141
157
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
-
146
158
### Monitoring and user communication no longer working (or any other functionality)
147
159
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.
@@ -28,24 +28,25 @@ Therefore this is an attempt to:
28
28
- Many many more boards developed by the community members, see [<spanclass="simple">Simple<spanclass="foc">FOC</span> Community</span>](https://community.simplefoc.com/)
-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)
0 commit comments