Skip to content

Commit e89b15d

Browse files
committed
FEAT added stepper and pwm freq docs
1 parent f1b2225 commit e89b15d

26 files changed

+268
-59
lines changed

_includes/js/custom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var libraires =[
55
"Encoder.h",
66
"FOCutils.h",
77
"BLDCMotor.h",
8+
"StepperMotor.h",
89
"HallSensor.h",
910
"MagneticSensor.h",
1011
"MagneticSensorSPI.h",
@@ -36,6 +37,7 @@ var defines =[
3637

3738
var classNames = [
3839
"BLDCMotor",
40+
"StepperMotor",
3941
"Encoder",
4042
"MagneticSensor",
4143
"MagneticSensorSPI",

docs/simplefoc_library/code/communication.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ motor.command(serialReceiveUserCommand());
144144
MagneticSensorSPI AS5x4x = MagneticSensorSPI(10, 14, 0x3FFF);
145145

146146
// motor instance
147-
BLDCMotor motor = BLDCMotor(9, 5, 6, 11, 8);
147+
StepperMotor motor = StepperMotor(9, 10, 5, 6, 50);
148148

149149
void setup() {
150150

@@ -153,9 +153,6 @@ void setup() {
153153
// link the motor to the sensor
154154
motor.linkSensor(&AS5x4x);
155155

156-
// choose FOC modulation
157-
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
158-
159156
// power supply voltage [V]
160157
motor.voltage_power_supply = 12;
161158

docs/simplefoc_library/code/index.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,19 @@ Sensor is initialized hardware pins by running `sensor.init()`.
101101
For full documentation of the setup and all configuration parameters please visit the <a href="sensors"> position sensors docs</a>.
102102

103103

104-
## Step 2. <a href="motor_initialization" class="remove_dec"> BLDC motor setup</a>
105-
After the position sensor we proceed to initializing and configuring the BLDC motor handled by `BLDCMotor` class and it is defined by setting:
106-
- phase `A`, `B` and `C` pin number: `9`,`5` and `6`
107-
- `pole_pairs` number of the motor: `11`
108-
- `enable` pin number *(optional)*: `8`
109-
110-
Here is a how it looks in code:
104+
## Step 2. <a href="motor_initialization" class="remove_dec"> Motor setup</a>
105+
After the position sensor we proceed to initializing and configuring the motor. The library supports BLDC motors handled by `BLDCMotor` class and stepper motors handled by `StepperMotor` class. `BLDCMotor` class instantiated by providing:
106+
- phase `A`, `B` and `C` pin number
107+
- `pole_pairs` number of the motor
108+
- `enable` pin number *(optional)*
109+
110+
And `StepperMotor` it is defined by setting:
111+
- phase `1A`, `1B` pin number
112+
- phase `2A`, `2B` pin number
113+
- `pole_pairs` number of the motor
114+
- `enable1` and `enable2` pin numbers *(optional)*
115+
116+
In this example we will use BLDC motor:
111117
```cpp
112118
#include <SimpleFOC.h>
113119

@@ -189,7 +195,7 @@ For full documentation of the setup and all configuration parameters please visi
189195

190196
## Step 4. <a href="monitoring" class="remove_dec"> Monitoring</a>
191197

192-
`BLDCMotor` class enables optional monitoring functionality. For enabling the monitoring feature make sure you call `motor.useMonitoring()` with the `Serial` port instance you want to output to. It uses `Serial` class to output motor initialization status during the `motor.init()` function, as well as in `motor.initFOC()` function.
198+
`BLDCMotor` and `StepperMotor` classes provide monitoring functionality. For enabling the monitoring feature make sure you call `motor.useMonitoring()` with the `Serial` port instance you want to output to. It uses `Serial` class to output motor initialization status during the `motor.init()` function, as well as in `motor.initFOC()` function.
193199

194200
If you are interested to output motors state variables in real-time (even though it will impact the performance - writing the Serial port is slow!) add the `motor.monitor()` function call to the Arduino `loop()` function.
195201

@@ -249,7 +255,7 @@ void setup() {
249255
// link motor and sensor
250256
// configure motor
251257

252-
// use monitoring with the BLDCMotor
258+
// use monitoring
253259
Serial.begin(115200);
254260
// monitoring port
255261
motor.useMonitoring(Serial);

docs/simplefoc_library/code/monitoring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>lib
1010

1111
# Monitoring functionality
1212

13-
`BLDCMotor` class supports monitoring using `Serial` port which is enabled by:
13+
Both `BLDCMotor` and `StepperMotor` classes support monitoring using `Serial` port which is enabled by:
1414
```cpp
1515
motor.useMonitoring(Serial);
1616
```

docs/simplefoc_library/code/motor.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
11
---
22
layout: default
3-
title: BLDC Motor
3+
title: Motor & Driver
44
nav_order: 2
55
parent: Using the Code
66
permalink: /motor_initialization
77
grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
88
---
99

10-
# Motor setup
10+
# Motor & Driver configuration
1111

1212
<div class="width60">
13-
<img src="extras/Images/mot2.jpg" style="width:24%;display:inline"><img src="extras/Images/bigger.jpg" style="width:24%;display:inline"><img src="extras/Images/big.jpg" style="width:24%;display:inline"><img src="extras/Images/mot.jpg" style="width:24%;display:inline">
13+
<img src="extras/Images/mot2.jpg" style="width:20%;display:inline"><img src="extras/Images/bigger.jpg" style="width:20%;display:inline"><img src="extras/Images/mot.jpg" style="width:20%;display:inline"><img src="extras/Images/nema17_2.jpg" style="width:20%;display:inline"><img src="extras/Images/nema17_1.jpg" style="width:20%;display:inline">
1414
</div>
1515

16-
All BLDC motors are handled with the `BLDCMotor` class. This class is the heart ❤️ of the Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>. <br>
17-
It implements:
18-
- BLDC motor & BLDC driver hardware support
16+
All BLDC motors are handled with the `BLDCMotor` class and stepper motor are handled by `StepperMotor` class. These classes are the heart ❤️ of the Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>. <br>
17+
They implement:
18+
- BLDC/Stepper motor configuration
19+
- BLDC/Stepper driver hardware support
1920
- FOC algorithm
2021
- Motion control loops
2122
- Monitoring
2223
- User communication interface
2324

2425
## Step 1. Hardware setup
25-
To initialize the hardware of the BLDC motor and BLDC driver you need to specify the `pwm` pin numbers, number of `pole pairs` of the motor and optionally `enable` pin.
26+
To configure the BLDC motor and define the interface to the BLDC driver you need to specify the 3 `pwm` pin numbers for each motor phase, number of `pole pairs` of the motor and optionally `enable` pin.
2627
```cpp
2728
// BLDCMotor( int phA, int phB, int phC, int pp, int en)
2829
// - phA, phB, phC - motor A,B,C phase pwm pins
2930
// - pp - pole pair number
3031
// - enable pin - (optional input)
3132
BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
3233
```
34+
35+
For the stepper motor and stepper driver you need to specify the 4 `pwm` pin numbers (2 for each phase), number of `pole pairs` of the motor and optionally `enable1` and `enable2` pin numbers.
36+
```cpp
37+
// StepperMotor( int phA, int phB, int phC, int pp, int cpr, int en)
38+
// - ph1A, ph1B - motor phase 1 pwm pins
39+
// - ph2A, ph2B - motor phase 2 pwm pins
40+
// - pp - pole pair number
41+
// - enable1 pin - (optional input)
42+
// - enable2 pin - (optional input)
43+
StepperMotor motor = StepperMotor(5,6, 9,10, 50, 7, 8);
44+
```
3345
<blockquote class="info"><p class="heading">Pole pair number </p>
34-
If you are not sure what your `pole_paris` number is I included an example code to estimate your <code class="highlighter-rouge">pole_paris</code> number in the examples <code class="highlighter-rouge">find_pole_pairs_number.ino</code>.
46+
If you are not sure what your <code class="highlighter-rouge">pole_paris</code> number is I included an example code to estimate your <code class="highlighter-rouge">pole_paris</code> number in the examples <code class="highlighter-rouge">find_pole_pairs_number.ino</code>.
3547
</blockquote>
3648

37-
When you have your `motor` defined you can start the configuration.
49+
The important thing to note is that the rest of the configuration explained in the following text does not depend which motor you are using. Therefore, once when you have your `motor` defined you can start the configuration.
3850

3951
## Step 2. Linking the sensor
4052
Once when you have the `motor` defined and the sensor initialized you need to link the `motor` and the `sensor` by executing:
@@ -138,6 +150,29 @@ Finally the configuration is terminated by running `init()` function which prepa
138150
motor.init();
139151
```
140152

153+
### Step 3.3 PWM frequency configuration (optional)
154+
If you wish to change the PWM frequency provide the value in hertz to the `init()` function. For example, to set the pwm frequency of 30khz the code will look like:
155+
```cpp
156+
// Motor hardware init function
157+
motor.init(30000);
158+
```
159+
<blockquote class="warning">
160+
⚠️ Arduino devices based on ATMega328 and ATMega2560 chips have fixed pwm frequency of 32kHz.
161+
</blockquote>
162+
163+
Here is a list of different microcontrollers and their PWM frequency and resolution used with the Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>.
164+
165+
MCU | default frequency | MAX frequency | PWM resolution | configurable
166+
--- | --- | --- | --- | ---
167+
Arduino UNO(Atmega328) | 32 kHz | 32 kHz | 8bit | no
168+
Arduino MEGA | 32kHz | 32kHz | 8bit | no
169+
STM32 | 50kHz | 50kHz | 14bit | yes
170+
ESP32 | 20kHz | 30kHz | 10bit | yes
171+
Teensy | 50kHz | 50kHz | 8bit | yes
172+
173+
All of these settings are defined in the `hardware_utils.cpp/h` of the library source.
174+
175+
141176
## Step 4. Field Oriented Control initialization
142177

143178
After the motor and sensor are initialized and configured, and before we can start the motion control we need to initialize the FOC algorithm.
@@ -186,7 +221,7 @@ The faster you can run this function the better!
186221
Finally, when we can set the phase voltages to the motor using the FOC algorithm we can proceed to the motion control. And this is done with `motor.move()` function.
187222

188223
```cpp
189-
// Function executing the control loops configured by the motor.controller parameter of the BLDCMotor.
224+
// Function executing the control loops configured by the motor.controller parameter of the motor.
190225
// - This function doesn't need to be run upon each loop execution - depends of the use case
191226
//
192227
// target Either voltage, angle or velocity based on the motor.controller

docs/simplefoc_library/hardware/BLDC_drivers.md renamed to docs/simplefoc_library/hardware/drivers/BLDC_drivers.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
22
layout: default
33
title: BLDC drivers
4-
parent: Supported Hardware
5-
nav_order: 2
4+
nav_order: 1
65
description: "Arduino Simple Field Oriented Control (FOC) library ."
76
permalink: /bldc_drivers
8-
grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
7+
parent: Drivers
8+
grand_parent: Supported Hardware
9+
grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
910
---
1011

1112
# BLDC motor drivers
12-
This library will be compatible with the most of the 3 phase BLDC motor drivers. Such as [<i class="fa fa-file"></i> L6234](https://www.st.com/en/motor-drivers/l6234.html), [<i class="fa fa-file"></i> DRV8305](https://www.ti.com/product/DRV8305), [<i class="fa fa-file"></i> DRV8313](https://www.ti.com/product/DRV8313) or even [<i class="fa fa-file"></i> L293](http://www.ti.com/lit/ds/symlink/l293.pdf).
13+
This library will be compatible with the most of 3 phase BLDC motor drivers. Such as [<i class="fa fa-file"></i> L6234](https://www.st.com/en/motor-drivers/l6234.html), [<i class="fa fa-file"></i> DRV8305](https://www.ti.com/product/DRV8305), [<i class="fa fa-file"></i> DRV8313](https://www.ti.com/product/DRV8313) or even [<i class="fa fa-file"></i> L293](http://www.ti.com/lit/ds/symlink/l293.pdf). **In order for BLDC driver board to work with the library it needs to be controllable using 3 pwm signals.**
1314

1415
At this moment, a low-cost BLDC driver board is still reasonably hard to find making our choice of hardware is quiet restricted. This is the one of the motivations to develop the <span class="simple">Simple<span class="foc">FOC</span>Shield</span>, a versatile and simple BLDC driver. Fortunately, the community is starting to gain momentum in this direction and it is probably a matter of time before BLDC motors become a standard in the hobby community as well, what is really exciting! 😃
1516

@@ -22,7 +23,7 @@ Here are some BLDC driver boards that are designed for gimbal motors and work wi
2223

2324
Examples | Description | Specifications | Link | Price
2425
---- | ---- | ---- | ---
25-
[<img src="extras/Images/hor_cad_shield.jpg" style="height:100px">](https://simplefoc.com/simplefoc_shield_product)| Arduino<br> <span class="simple">Simple<span class="foc">FOC</span>Shield</span>| - L6234 chip <br> - 1 motor <br>- Arduino Shield <br> - Encoder Pullups | [More info](https://simplefoc.com/simplefoc_shield_product) | 15€
26+
[<img src="https://raw.githubusercontent.com/simplefoc/Arduino-SimpleFOCShield/master/images/top.png" style="height:100px">](https://simplefoc.com/simplefoc_shield_product)| Arduino<br> <span class="simple">Simple<span class="foc">FOC</span>Shield</span>| - L6234 chip <br> - 1 motor <br>- Arduino Shield <br> - Encoder Pullups | [More info](https://simplefoc.com/simplefoc_shield_product) | 15€
2627
[<img src="extras/Images/l6234.jpg" style="height:100px">](https://www.ebay.com/itm/L6234-Breakout-Board/153204519965?hash=item23abb3741d:g:LE4AAOSwe35bctgg) | Drotek L6234<br> breakout board | - L6234 chip <br> - 1 motor <br> - 25x25mm | [Drotek](https://store-drotek.com/212-brushless-gimbal-controller-l6234.html)<br> [Ebay](https://www.ebay.fr/itm/L6234-Breakout-Board-/153204519965) | 30€
2728

2829
Alternatively, you can find gimbal controller boards with integrated BLDC drivers and microcontroller chips such as HMBGC V2.2 and BGC 3.0 similar boards.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
layout: default
3+
title: Drivers
4+
parent: Supported Hardware
5+
nav_order: 2
6+
description: "Arduino Simple Field Oriented Control (FOC) library ."
7+
permalink: /drivers
8+
grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
9+
has_children: true
10+
has_toc: false
11+
---
12+
13+
# Supported driver boards
14+
15+
Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> has a goal to support as many BLDC and stepper motor drivers as possible. Till this moment there are two kinds of motor drivers supported by this library:
16+
17+
- [BLDC motor driver <i class="fa fa-external-link"></i>](bldc_drivers)
18+
- **3 PWM signals** ( 3 phase )
19+
- gimbal motor drivers or high-performance boards
20+
- [Stepper drivers <i class="fa fa-external-link"></i>](stepper_drivers)
21+
- **4 PWM signals** ( 2 phase )
22+
- Stepper drivers or double DC motor drivers
23+
24+
## 📢 Make sure to read this before settling for a driver!
25+
Before running any BLDC motor with the <span class="simple">Simple<span class="foc">FOC</span>library</span> please make sure your hardware can handle the currents your motor requires.
26+
27+
The simplest way to do it is by checking the motor phase resistance `R`. Either check the datasheet of your motor and search for the resistance value or measure it yourself using a multimeter. Then check the value of your power supply voltage `V_dc` and once when you have the values you can find the maximum current `I_max` value by calculating:
28+
```cpp
29+
I_max = V_dc/R
30+
```
31+
Finally check the value of the maximum current `I_max` with the datasheet of your driver board. If the `I_max` is too high you can lower the power supply voltage `V_dc` in order prevent too high peaks of the current. If you are not able to change your power supply voltage you can limit the voltage set to motor in software.
32+
<blockquote class="warning">
33+
<p class="heading">NOTE</p>
34+
The equation above calculates the worst case maximum current <code class="highlighter-rouge">I_max</code> and in most cases calculated <code class="highlighter-rouge">I_max</code> is higher than the actual value. Maximum current depends both of the motor hardware such as winding configuration and the control algorithm.
35+
</blockquote>

0 commit comments

Comments
 (0)