Skip to content

Commit 2fee18e

Browse files
committed
Version 2.0
1 parent 35b2e29 commit 2fee18e

Some content is hidden

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

55 files changed

+2155
-872
lines changed

_includes/js/custom.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ var defines =[
3939
var classNames = [
4040
"BLDCMotor",
4141
"StepperMotor",
42+
"BLDCDriver3PWM",
43+
"BLDCDriver6PWM",
44+
"StepperDriver4PWM",
4245
"Encoder",
4346
"MagneticSensor",
4447
"MagneticSensorSPI",
@@ -48,7 +51,9 @@ var classNames = [
4851
"PciListenerImp",
4952
"PciManager",
5053
"Serial",
51-
"MySensor"
54+
"MySensor",
55+
"Wire",
56+
"SPIClass"
5257
];
5358

5459
var classProps = [
@@ -79,6 +84,7 @@ var funcNames = [
7984
"handleC",
8085
"registerListener",
8186
"linkSensor",
87+
"linkDriver",
8288
"useMonitoring",
8389
"monitor",
8490
"print",
@@ -137,7 +143,9 @@ var structProps = [
137143
"velocity_openloop",
138144
"voltage",
139145
"SpaceVectorPWM",
140-
"SinePWM"
146+
"SinePWM",
147+
"Trapesoid_120",
148+
"Trapesoid_150"
141149
];
142150
jtd.onReady(function(){
143151
document.querySelectorAll('.n').forEach(function(e) {

_includes/nav.html

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,48 @@
44
{%- for node in pages_list -%}
55
{%- unless node.nav_exclude -%}
66
{%- if node.parent == nil -%}
7-
<li class="navigation-list-item{% if page.url == node.url or page.parent == node.title or page.grand_parent == node.title or page.grand_grand_parent == node.title %} active{% endif %}">
8-
{%- if page.parent == node.title or page.grand_parent == node.title -%}
7+
<li class="navigation-list-item{% if page.url == node.url or page.parent == node.title or page.grand_parent == node.title or page.grand_grand_parent == node.title or page.grand_grand_grand_parent == node.title %} active{% endif %}">
8+
{%- if page.parent == node.title or page.grand_parent == node.title or page.grand_grand_parent == node.title or page.grand_grand_grand_parent == node.title -%}
99
{%- assign first_level_url = node.url | absolute_url -%}
1010
{%- endif -%}
1111
<a href="{{ node.url | absolute_url }}" class="navigation-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a>
1212
{%- if node.has_children -%}
1313
{%- assign children_list = site.html_pages | where: "parent", node.title | sort:"nav_order" -%}
1414
<ul class="navigation-list-child-list " style="list-style-type: none;">
1515
{%- for child in children_list -%}
16-
<li class="navigation-list-item child-list {% if page.url == child.url or page.parent == child.title or page.grand_parent == child.title %} active{% endif %}">
17-
{%- if page.url == child.url or page.parent == child.title -%}
16+
<li class="navigation-list-item child-list {% if page.url == child.url or page.parent == child.title or page.grand_parent == child.title or page.grand_grand_parent == child.title %} active{% endif %}">
17+
{%- if page.url == child.url or page.parent == child.title or page.grand_parent == child.title or page.grand_grand_parent == child.title -%}
1818
{%- assign second_level_url = child.url | absolute_url -%}
1919
{%- endif -%}
2020
<a href="{{ child.url | absolute_url }}" class="navigation-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a>
2121
{%- if child.has_children -%}
2222
{%- assign grand_children_list = site.html_pages | where: "parent", child.title | sort:"nav_order" -%}
2323
<ul class="navigation-list-child-list " style="list-style-type: none;" >
2424
{%- for grand_child in grand_children_list -%}
25-
<li class="navigation-list-item grand-child-list {% if page.url == grand_child.url or page.parent == grand_child.title%} active{% endif %}">
26-
{%- if page.url == grand_child.url or page.parent == grand_child.title -%}
27-
{%- assign second_level_url = grand_child.url | absolute_url -%}
25+
<li class="navigation-list-item grand-child-list {% if page.url == grand_child.url or page.parent == grand_child.title or page.grand_parent == grand_child.title%} active{% endif %}">
26+
{%- if page.url == grand_child.url or page.parent == grand_child.title or page.grand_parent == grand_child.title or page.grand_grand_parent == grand_child.title-%}
27+
{%- assign third_level_url = grand_child.url | absolute_url -%}
2828
{%- endif -%}
2929
<a href="{{ grand_child.url | absolute_url }}" class="navigation-list-link{% if page.url == grand_child.url %} active{% endif %}">{{ grand_child.title }}</a>
3030
{%- if grand_child.has_children -%}
3131
{%- assign grand_grand_children_list = site.html_pages | where: "parent", grand_child.title | sort:"nav_order" -%}
3232
<ul class="navigation-list-child-list " style="list-style-type: none;" >
3333
{%- for grand_grand_child in grand_grand_children_list -%}
34-
<li class="navigation-list-item grand-grand-child-list {% if page.url == grand_grand_child.url %} active{% endif %}">
34+
<li class="navigation-list-item grand-grand-child-list {% if page.url == grand_grand_child.url or page.parent == grand_grand_child.title%} active{% endif %}">
35+
{%- if page.url == grand_grand_child.url or page.parent == grand_grand_child.title -%}
36+
{%- assign fourth_level_url = grand_grand_child.url | absolute_url -%}
37+
{%- endif -%}
3538
<a href="{{ grand_grand_child.url | absolute_url }}" class="navigation-list-link{% if page.url == grand_grand_child.url %} active{% endif %}">{{ grand_grand_child.title }}</a>
39+
{%- if grand_grand_child.has_children -%}
40+
{%- assign grand_grand_grand_children_list = site.html_pages | where: "parent", grand_grand_child.title | sort:"nav_order" -%}
41+
<ul class="navigation-list-child-list " style="list-style-type: none;" >
42+
{%- for grand_grand_grand_child in grand_grand_grand_children_list -%}
43+
<li class="navigation-list-item grand-grand-grand-child-list {% if page.url == grand_grand_grand_child.url %} active{% endif %}">
44+
<a href="{{ grand_grand_grand_child.url | absolute_url }}" class="navigation-list-link{% if page.url == grand_grand_grand_child.url %} active{% endif %}">{{ grand_grand_grand_child.title }}</a>
45+
</li>
46+
{%- endfor -%}
47+
</ul>
48+
{%- endif -%}
3649
</li>
3750
{%- endfor -%}
3851
</ul>

_sass/navigation.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
display: none;
5757
@include fs-3;
5858
}
59+
.grand-grand-grand-child-list {
60+
display: none;
61+
@include fs-3;
62+
}
5963
.child-list {
6064
display: bock;
6165
@include fs-4;
@@ -73,6 +77,12 @@
7377
&.active{
7478
.grand-grand-child-list{
7579
display: block;
80+
81+
&.active{
82+
.grand-grand-grand-child-list{
83+
display: block;
84+
}
85+
}
7686
}
7787
}
7888
}

docs/simplefoc_library/code/communication.md

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

146146
// motor instance
147-
StepperMotor motor = StepperMotor(9, 10, 5, 6, 50);
147+
StepperMotor motor = StepperMotor(50);
148+
// driver instance
149+
StepperDriver4PWM driver = StepperDriver4PWM(9, 10, 5, 6);
148150

149151
void setup() {
150152

@@ -154,7 +156,9 @@ void setup() {
154156
motor.linkSensor(&AS5x4x);
155157

156158
// power supply voltage [V]
157-
motor.voltage_power_supply = 12;
159+
driver.voltage_power_supply = 12;
160+
driver.init();
161+
motor.linkDriver(&driver);
158162

159163
// set control loop type to be used
160164
motor.controller = ControlType::voltage;
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
layout: default
3+
title: BLDCDriver 3PWM
4+
nav_order: 1
5+
permalink: /bldcdriver3pwm
6+
parent: BLDCDriver
7+
grand_parent: Driver code
8+
grand_grand_parent: Writing the Code
9+
grand_grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
10+
---
11+
12+
# BLDC driver 3PWM - `BLDCDriver3PWM`
13+
14+
This is the class which provides an abstraction layer of most of the common 3PWM bldc drivers out there. Basically any BLDC driver board that can be run using 3PWM signals can be represented with this class.
15+
Examples:
16+
- Arduino <span class="simple">Simple<span class="foc">FOC</span>Shield</span>
17+
- L6234 breakout board
18+
- HMBGC v2.2
19+
- DRV830x ( can be run in 3pwm or 6pwm mode )
20+
- X-NUCLEO-IHM07M1
21+
- etc.
22+
23+
24+
<img src="extras/Images/3pwm_driver.png" class="width40">
25+
26+
## Step 1. Hardware setup
27+
To create the interface to the BLDC driver you need to specify the 3 `pwm` pin numbers for each motor phase and optionally `enable` pin.
28+
```cpp
29+
// BLDCDriver3PWM( int phA, int phB, int phC, int en)
30+
// - phA, phB, phC - A,B,C phase pwm pins
31+
// - enable pin - (optional input)
32+
BLDCDriver3PWM motor = BLDCDriver3PWM(9, 10, 11, 8);
33+
```
34+
35+
## Step 2.1 PWM Configuration
36+
```cpp
37+
// pwm frequency to be used [Hz]
38+
// for atmega328 fixed to 32kHz
39+
// esp32/stm32/teensy configurable
40+
driver.pwm_frequency = 50000;
41+
```
42+
<blockquote class="warning">
43+
⚠️ Arduino devices based on ATMega328 chips have fixed pwm frequency of 32kHz.
44+
</blockquote>
45+
46+
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>.
47+
48+
MCU | default frequency | MAX frequency | PWM resolution | Center-aligned | Configurable freq
49+
--- | --- | --- | --- | ---
50+
Arduino UNO(Atmega328) | 32 kHz | 32 kHz | 8bit | yes | no
51+
STM32 | 50kHz | 100kHz | 14bit | yes | yes
52+
ESP32 | 40kHz | 100kHz | 10bit | yes | yes
53+
Teensy | 50kHz | 100kHz | 8bit | yes | yes
54+
55+
All of these settings are defined in the `drivers/hardware_specific/x_mcu.cpp/h` of the library source.
56+
57+
58+
## Step 2.2 Voltages
59+
Driver class is the one that handles setting the pwm duty cycles to the driver output pins and it is needs to know the DC power supply voltage it is plugged to.
60+
Additionally driver class enables the user to set the absolute DC voltage limit the driver will be set to the output pins.
61+
```cpp
62+
// power supply voltage [V]
63+
driver.voltage_power_supply = 12;
64+
// Max DC voltage allowed - default voltage_power_supply
65+
driver.voltage_limit = 12;
66+
```
67+
68+
<img src="extras/Images/limits.png" class="width60">
69+
70+
This parameter is used by the `BLDCMotor` class as well. As shown on the figure above the once the voltage limit `driver.voltage_limit` is set, it will be communicated to the FOC algorithm in `BLDCMotor` class and the phase voltages will be centered around the `driver.voltage_limit/2`.
71+
72+
Therefore this parameter is very important if there is concern of too high currents generated by the motor. In those cases this parameter can be used as a security feature.
73+
74+
## Step 2.3 Initialisation
75+
Once when all the necessary configuration parameters are set the driver function `init()` is called. This function uses the configuration parameters and configures all the necessary hardware and software for driver code execution.
76+
```cpp
77+
// driver init
78+
driver.init();
79+
```
80+
81+
## Step 3. Using encoder in real-time
82+
83+
BLDC driver class was developed to be used with the <span class="simple">Simple<span class="foc">FOC</span>library</span> and to provide the abstraction layer for FOC algorithm implemented in the `BLDCMotor` class. But the `BLDCDriver3PWM` class can used as a standalone class as well and once can choose to implement any other type of control algorithm using the bldc driver.
84+
85+
## FOC algorithm support
86+
In the context of the FOC control all the driver usage is done internally by the motion control algorithm and all that is needed to enable is is just link the driver to the `BLDCMotor` class.
87+
```cpp
88+
// linking the driver to the motor
89+
motor.linkDriver(&driver)
90+
```
91+
92+
## Standalone driver
93+
If you wish to use the bldc driver as a standalone device and implement your-own logic around it this can be easily done. Here is an example code of a very simple standalone application.
94+
```cpp
95+
// BLDC driver standalone example
96+
#include <SimpleFOC.h>
97+
98+
// BLDC driver instance
99+
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
100+
101+
void setup() {
102+
103+
// pwm frequency to be used [Hz]
104+
driver.pwm_frequency = 50000;
105+
// power supply voltage [V]
106+
driver.voltage_power_supply = 12;
107+
// Max DC voltage allowed - default voltage_power_supply
108+
driver.voltage_limit = 12;
109+
110+
// driver init
111+
driver.init();
112+
113+
// enable driver
114+
driver.enable();
115+
116+
_delay(1000);
117+
}
118+
119+
void loop() {
120+
// setting pwm
121+
// phase A: 3V, phase B: 6V, phase C: 5V
122+
driver.setPwm(3,6,5);
123+
}
124+
```

0 commit comments

Comments
 (0)