Skip to content

Commit 8377f63

Browse files
committed
Merge branch 'dev'
2 parents a1b6a69 + 8981dc9 commit 8377f63

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

README.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66
[![arduino-library-badge](https://www.ardu-badge.com/badge/Simple%20FOC.svg?)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
77

8-
Proper low-cost and low-power FOC supporting boards are very hard to find today and even may not exist. Even harder to find is a stable and simple FOC algorithm code for BLDC and Stepper motors capable of running on Arduino devices.
8+
We live in very exciting times 😃! BLDC motors are entering the hobby community more and more and many great projects have already emerged leveraging their far superior dynamics and power capabilities. BLDC motors have numerous advantages over regular DC motors but they have one big disadvantage, the complexity of control. Even though it has become relatively easy to design and manufacture PCBs and create our own hardware solutions for driving BLDC motors the proper low-cost solutions are yet to come. One of the reasons for this is the apparent complexity of writing the BLDC driving algorithms, Field oriented control (FOC) being an example of one of the most efficient ones.
9+
The solutions that can be found on-line are almost exclusively very specific for certain hardware configuration and the microcontroller architecture used.
10+
Additionally, most of the efforts at this moment are still channeled towards the high-power applications of the BLDC motors and proper low-cost and low-power FOC supporting boards are very hard to find today and even may not exist. <br>
911
Therefore this is an attempt to:
10-
- Demystify FOC algorithm and make a robust but simple Arduino library: [Arduino *SimpleFOClibrary*](https://docs.simplefoc.com/arduino_simplefoc_library_showcase)
11-
- Develop a modular BLDC driver board: [Arduino *SimpleFOCShield*](https://docs.simplefoc.com/arduino_simplefoc_shield_showcase).
12-
- ***New 📢:** Develop a modular Stepper motor board for FOC control:* <b>Arduino <span class="simple">Stepper<span class="foc">FOC</span>Shield</span></b>
12+
- 🎯 Demystify FOC algorithm and make a robust but simple Arduino library: [Arduino *SimpleFOClibrary*](https://docs.simplefoc.com/arduino_simplefoc_library_showcase)
13+
- <i>Support as many <b>motor + sensor + driver + mcu</b> combinations out there</i>
14+
- 🎯 Develop a modular low-power BLDC driver board: [Arduino *SimpleFOCShield*](https://docs.simplefoc.com/arduino_simplefoc_shield_showcase).
1315

14-
15-
> <b>NEW RELEASE 📢:</b> <i>Simple<b>FOC</b>library v2.0.2
16+
> <b> RELEASE 📢:</b> <i>Simple<b>FOC</b>library v2.0.2
1617
> - Arduino MEGA 2560 support
1718
> - OSC example project by [@runger1101001](https://github.com/runger1101001)
1819
> - floating point bug - open loop velocity by [@ATILIUS-REGULUS](https://github.com/ATILIUS-REGULUS)
1920
20-
> <i>Simple<b>FOC</b>library v2.0.1
21-
> - ESP32 bugfix
22-
> - frequency setting
23-
> - pwm resolution
24-
> - 2PWM stepper class added `StepperMotor2PWM`
25-
> - some refactoring of examples
2621

27-
## Arduino *SimpleFOCShield*
22+
## Arduino *SimpleFOCShield* v2.0.2
2823

2924
<p align="">
3025
<a href="https://youtu.be/G5pbo0C6ujE">
@@ -33,23 +28,25 @@ Therefore this is an attempt to:
3328
</p>
3429

3530
### Features
36-
- **Plug & play**: In combination with Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
37-
- **Low-cost**: Price of €15 - [Check the pricing](https://www.simplefoc.com/simplefoc_shield_product)
38-
- **Max power 100W** - max current 5A, power-supply 12-24V
39-
- Designed for Gimbal motors with the internal resistance >10 Ω.
31+
- **Plug & play**: In combination with Arduino *Simple**FOC**library* - [github](https://github.com/simplefoc/Arduino-FOC)
32+
- **Low-cost**: Price of €15 - [Check the pricing](https://www.simplefoc.com/shop)
33+
- **In-line current sensing**: Up to 3Amps/5Amps bidirectional
34+
- configurable: 3.3Amps - 3.3V adc, 5Amps - 5V adc
35+
- **Integrated 8V regulator**:
36+
- Enable/disable by soldering pads
37+
- **Max power 120W** - max current 5A, power-supply 12-24V
38+
- Designed for Gimbal motors with the internal resistance >10 Ωs.
4039
- **Stackable**: running 2 motors in the same time
41-
- **Encoder/Hall sensor interface**: Integrated 3.3kΩ pullups (configurable)
40+
- **Encoder/Hall sensors interface**: Integrated 3.3kΩ pullups (configurable)
4241
- **I2C interface**: Integrated 4.7kΩ pullups (configurable)
4342
- **Configurable pinout**: Hardware configuration - soldering connections
4443
- **Arduino headers**: Arduino UNO, Arduino MEGA, STM32 Nucleo boards...
45-
- **Open Source**: Fully available fabrication files - [how to make it yourself](https://www.simplefoc.com/arduino_simplefoc_shield_fabrication),
46-
47-
##### If you are interested in this board, order your version on this link: [Shop](https://www.simplefoc.com/simplefoc_shield_product)
44+
- **Open Source**: Fully available fabrication files - [how to make it yourself](https://docs.simplefoc.com/arduino_simplefoc_shield_fabrication)
4845

49-
<p align=""><img src="https://docs.simplefoc.com/extras/Images/shield_to_v13.jpg" height="180px"> <img src="https://docs.simplefoc.com/extras/Images/shield_bo_v13.jpg" height="180px"> <img src="https://docs.simplefoc.com/extras/Images/simple_foc_shield_v13_small.gif" height="180x"></p>
46+
<p align=""><img src="https://simplefoc.com/assets/img/v2.jpg" height="180px"> <img src="https://simplefoc.com/assets/img/v1.jpg" height="180px"> <img src="https://docs.simplefoc.com/extras/Images/simple_foc_shield_v13_small.gif" height="180x"></p>
5047

5148

52-
## Arduino *SimpleFOClibrary*
49+
## Arduino *SimpleFOClibrary* v2.0.2
5350

5451
<p align="">
5552
<a href="https://youtu.be/Y5kLeqTc6Zk">

src/sensors/HallSensor.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,31 @@ void HallSensor::handleC() {
4343
*/
4444
void HallSensor::updateState() {
4545
long new_pulse_timestamp = _micros();
46-
hall_state = C_active + (B_active << 1) + (A_active << 2);
46+
47+
int8_t new_hall_state = C_active + (B_active << 1) + (A_active << 2);
48+
49+
// glitch avoidance #1 - sometimes we get an interrupt but pins haven't changed
50+
if (new_hall_state == hall_state) {
51+
return;
52+
}
53+
hall_state = new_hall_state;
54+
4755
int8_t new_electric_sector = ELECTRIC_SECTORS[hall_state];
4856
static Direction old_direction;
4957
if (new_electric_sector - electric_sector > 3) {
5058
//underflow
51-
direction = static_cast<Direction>(natural_direction * -1);
59+
direction = Direction::CCW;
5260
electric_rotations += direction;
5361
} else if (new_electric_sector - electric_sector < (-3)) {
5462
//overflow
55-
direction = static_cast<Direction>(natural_direction);
63+
direction = Direction::CW;
5664
electric_rotations += direction;
5765
} else {
58-
direction = (new_electric_sector > electric_sector)? static_cast<Direction>(natural_direction) : static_cast<Direction>(natural_direction * (-1));
66+
direction = (new_electric_sector > electric_sector)? Direction::CW : Direction::CCW;
5967
}
6068
electric_sector = new_electric_sector;
69+
70+
// glitch avoidance #2 changes in direction can cause velocity spikes. Possible improvements needed in this area
6171
if (direction == old_direction) {
6272
// not oscilating or just changed direction
6373
pulse_diff = new_pulse_timestamp - pulse_timestamp;
@@ -97,7 +107,7 @@ float HallSensor::getVelocity(){
97107
if (pulse_diff == 0 || ((_micros() - pulse_timestamp) > pulse_diff) ) { // last velocity isn't accurate if too old
98108
return 0;
99109
} else {
100-
return direction * (_2PI / cpr) / (pulse_diff / 1000000.0);
110+
return natural_direction * direction * (_2PI / cpr) / (pulse_diff / 1000000.0);
101111
}
102112

103113
}

src/sensors/HallSensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class HallSensor: public Sensor{
8080
*/
8181
int needsAbsoluteZeroSearch() override;
8282

83-
// whether last step was CW (+1) or CCW (-1) direction
83+
// whether last step was CW (+1) or CCW (-1). Note - this is a raw direction (i.e. doesn't include natural_direction reversal)
8484
Direction direction;
8585

8686
void attachSectorCallback(void (*onSectorChange)(int a) = nullptr);

0 commit comments

Comments
 (0)