Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/simplefoc_library/code/current_sense/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ teensy | ✔️ | ❌ | ❌
Raspberry Pi Pico | ✔️ | ❌ | ❌
Portenta H7 | ✔️ | ❌ | ❌
nRF52 | ✔️ | ❌ | ❌
Renesas (UNO R4) | ❌ | ❌ | ❌

Note: current sensing on Renesas MCUs will be added in a future release.

## Digging deeper

Expand Down
1 change: 1 addition & 0 deletions docs/simplefoc_library/code/current_sense/inline.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SAMD51 | ✔️
Teensy | ✔️
Raspberry Pi Pico | ✔️
Portenta H7 | ✔️
Renesas (UNO R4) | ❌ (TBD)

## Hardware configuration
To instantiate the inline current sensor using the <span class="simple">Simple<span class="foc">FOC</span>library</span> just create an instance of the class `InlineCurrentSense`.
Expand Down
4 changes: 3 additions & 1 deletion docs/simplefoc_library/code/current_sense/low_side.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SAMD51 | ❌
Teensy | ❌
Raspberry Pi Pico | ❌
Portenta H7 | ❌
Renesas (UNO R4) | ❌ (TBD)


### Important hardware considerations
Expand Down Expand Up @@ -182,7 +183,7 @@ motor.linkCurrentSense(&current_sense);

### Where to place the `current_sense` configuration in your FOC code?

It is very important that the the current sensing `init` function is called after the `BLDCMotor` and `BLDCDriver` init functions are called. Which will make sure that the driver is enabled when current sense calibration is taking place. Also, it is important that the current sense `init` function is called before starting the foc algorithm with the `initFOC` function.
It is very important that the the current sensing `init` function is called after the `BLDCDriver` init function is called. This will make sure that the driver is enabled when current sense calibration is taking place. Also, it is important that the current sense `init` function is called before initializing the motor and starting the foc algorithm with the `initFOC` function.

So the suggested code structure would be:

Expand All @@ -207,6 +208,7 @@ void setup(){
}
```
Function `initFOC()` will make sure that the `BLDCDriver` and `LowsideCurrentSense` classes are both well aligned, it is very important that the phase `A` of the current sense is exactly the phase `A` of the driver, phase `B` of the current sense exactly pahse `B` of the driver and the same for the phase `C`. To verify this, the `initFOC` will be calling the current sense's function `current_sense.driverAlign(...)`.

### Alignment with the motor phases `driverAlign(...)`

The current sense and the driver alignment inside `initFOC` is done by calling the function:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To create the interface to the BLDC driver you need to specify the 6 `PWM` pin n
// - phB_h, phB_l - B phase pwm pin high/low pair
// - phB_h, phC_l - C phase pwm pin high/low pair
// - enable pin - (optional input)
BLDCDriver6PWM motor = BLDCDriver6PWM(5,6, 9,10, 3,11, 8);
BLDCDriver6PWM driver = BLDCDriver6PWM(5,6, 9,10, 3,11, 8);
```
<blockquote class="warning">
⚠️ 6 PWM configuration is very hardware specific and please make sure to respect certain guidelines in order for it to work properly!
Expand Down Expand Up @@ -65,15 +65,15 @@ In hardware 6 PWM mode the user uses only one timer, usually Timer 1 for all the
Where `T1Cx` are the Timer 1 channels and `T1CxN` are their complementary channels (inverted channels). Each pair of `T1Cx` and `T1CxN` is used for one pair of the high/low PWM pins. The library will configure the necessary timers and registers if you provide these pins to the constrictor of the `BLDCDriver6PWM` class. For example:
```cpp
// BLDCDriver6PWM( int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en)
BLDCDriver6PWM motor = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB15);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB15);
```

#### Software 6 PWM mode
If it is not possible to use the hardware 6 PWM mode with your board <span class="simple">Simple<span class="foc">FOC</span>library</span> enables you to use any two channels of any of the timers as your high/low side PWM pair. Basically, the library will automatically configure the complementary channels on the provided low side pins. The only requirement for this code to work properly is exatcly the same as for the Arudino UNO, each phase high/low PWM pair needs to belong to the same timer.
For example, if we take STM32 Nucleo F401RE board we can take for example:
```cpp
// BLDCDriver6PWM( int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en)
BLDCDriver6PWM motor = BLDCDriver6PWM(7, 2, 6, 3, 5, 4);
BLDCDriver6PWM driver = BLDCDriver6PWM(7, 2, 6, 3, 5, 4);
```
Where

Expand All @@ -84,7 +84,7 @@ Where
On Bluepill we could use:
```cpp
// BLDCDriver6PWM( int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en)
BLDCDriver6PWM motor = BLDCDriver6PWM(PA8, PA9, PB6, PB7, PB8, PB9);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PA9, PB6, PB7, PB8, PB9);
```
Where

Expand Down Expand Up @@ -247,4 +247,4 @@ void loop() {
// phase A: 3V, phase B: 6V, phase C: 5V
driver.setPwm(3,6,5);
}
```
```
1 change: 1 addition & 0 deletions docs/simplefoc_library/code/drivers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ samd21/51 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
teensy | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
Raspberry Pi Pico | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
Portenta H7 | ✔️ | ✔️ | ✔️ | ❌ | ✔️
Renesas (UNO R4 Minima) | ✔️ | ✔️ | ✔️ | ✔️ | ✔️

<sup>*</sup> For ESP32, the support for 6 PWM depends on the model of ESP32. The models that have a MCPWM peripheral support 6 PWM, the ones that do not only support the other PWM modes.
16 changes: 7 additions & 9 deletions docs/simplefoc_library/code/motors/bldc_motors.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,20 @@ The alignment procedure will have to move your motor several times and might not

### Step 6.1 Skip alignment - position sensor

If you are using absolute sensors such as magnetic sensors or hall sensors, once you have done the alignment procedure and once you have the motor's zero electrical offset sensor direction you no longer need the full calibration sequence. Therefore, to the `motor.initFOC()` you can provide the sensor offset `zero_electric_offset` and sensor direction `sensor_direction` to avoid alignment procedure:
```cpp
// align sensor and start FOC
//motor.initFOC(zero_electric_offset, sensor_direction);
motor.initFOC(2.15, Direction::CW);
```
The same can be done by using the motor parameters:
If you are using absolute sensors such as magnetic sensors or hall sensors, once you have done the alignment procedure and once you have the motor's zero electrical offset sensor direction you no longer need the full calibration sequence.

In this case you can set the sensor offset `zero_electric_offset` and sensor direction `sensor_direction` in the motor parameters to avoid the alignment procedure:
```cpp
// align sensor and start FOC
// set calibration values
motor.zero_electric_offset = 2.15; // rad
motor.sensor_direction = Direction::CW; // CW or CCW
// then call initFOC()
motor.initFOC();
```
You can find these values by running the `find_sensor_offset_and_direction.ino` example.

More generally, if you know any of these two values make sure to provide and the `iniFOC` will skip that part of the calibration. For example, for encoder sensors the zero electrical offset changes all the time but the sensor direction will stay the same so you can provide it and skip a large part of the calibration sequence.
If you set either of these two values the `initFOC` will skip that part of the calibration. For example, for encoder sensors the zero electrical offset changes all the time but the sensor direction will stay the same so you can provide it and skip a large part of the calibration sequence.

### Step 6.2 Skip alignment - current sense

For the current sensors it is as well possible to avoid the calibration procedure an that is done by specifying the curren sense flag called `skip_align`:
Expand Down
6 changes: 4 additions & 2 deletions docs/simplefoc_library/work_roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ For more info about the features of library releases visit the [github releases
## MCU support
- [ ] ESP8266 - initial
- [ ] Portenta H7 - initial
- [ ] Renesas support - initial
- [x] Arduino leonardo
- [x] Raspberry pi Pico - [PR #78](https://github.com/simplefoc/Arduino-FOC/pull/78)
- [x] SAM - Arduino DUE
- [x] SAMD21/51
- [x] Teensy support
- [x] ESP32 support
- [x] STM32 Nucleo support
- [x] STM32 BLuepill support
- [x] STM32 Bluepill support
- [x] nRF52 support
- [x] Hardware specific code separation : easier porting in between devices `hardware_utils.cpp/.h`

## Driver support
- [ ] Driver support: Disable the pahses in 6PWM mode
- [x] Driver support: Disable the phases in 6PWM mode
- [x] Driver support: Implement support for MOSFET control low and high pairs
- [x] Driver support: DRV8302 borads

Expand Down
43 changes: 14 additions & 29 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,21 @@ Therefore this is an attempt to:
- *Medium-power* BLDC driver (<30Amps): [Arduino <span class="simple">Simple<b>FOC</b>PowerShield</span> ](https://github.com/simplefoc/Arduino-SimpleFOC-PowerShield).

<blockquote class="info" markdown="1">
<p class="heading">NEW RELEASE 📢: <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.0 <a href="https://github.com/simplefoc/Arduino-FOC/releases/tag/v2.3.0">see release</a></p>
- Arduino Mega 6pwm more timers supported
- Arduino boards - frequency change support either 32kHz or 4kHz
- Arduino Uno - synched timers in 3pwm and 6pwm mode [#71](https://github.com/simplefoc/Arduino-FOC/issues/71)
- Teensy 3.x initial support for 6pwm
- Teensy 4.x initial support for 6pwm
- Example for v3.1 SimpleFOCShield
- RP2040 compatibility for earlehillpower core [#234](https://github.com/simplefoc/Arduino-FOC/pull/234) [#236](https://github.com/simplefoc/Arduino-FOC/pull/236)
- More flexible monitoring API
- start, end and separator characters
- decimal places (settable through commander)
- Added machine readable verbose mode in `Commander` [#233](https://github.com/simplefoc/Arduino-FOC/pull/233)
- *Simple**FOC**WebController* - Web based user interface for SimpleFOC by [@geekuillaume](https://github.com/geekuillaume) - [webcontroller.simplefoc.com](https://webcontroller.simplefoc.com)
- bugfix - `MagneticSensorPWM` multiple occasions - [#258](https://github.com/simplefoc/Arduino-FOC/pull/258)
- bugfix - current sense align - added offset exchange when exchanging pins
- bugfix - trapezoid 150 fixed
- bugfix - 4pwm on ESP8266 [#224](https://github.com/simplefoc/Arduino-FOC/pull/224)
- Additional `InlineCurrentSense` and `LowsideCurrentSense` constructor using milliVolts per Amp [#253](https://github.com/simplefoc/Arduino-FOC/pull/253)
- STM32L4xx current sense support by [@Triple6](https://github.com/Triple6) (discord) [#257](https://github.com/simplefoc/Arduino-FOC/pull/257)
- phase disable in 6pwm mode
- stm32 - software and hardware 6pwm
- atmega328
- atmega2560
- Lag compensation using motor inductance [#246](https://github.com/simplefoc/Arduino-FOC/issues/246)
- current control through voltage torque mode enhancement
- extended `BLDCMotor` and `StepperMotor` constructors to receive the inductance paramerer
- can also be set using `motor.phase_inductance` or through `Commander`
<p class="heading">NEW RELEASE 📢: <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.1 <a href="https://github.com/simplefoc/Arduino-FOC/releases/tag/v2.3.1">see release</a></p>
- Support for Arduino UNO R4 Minima (Renesas R7FA4M1 MCU - note UNO R4 WiFi is not yet supported)
- Support setting PWM polarity on ESP32 (thanks to [@mcells](https://github.com/mcells))
- Expose I2C errors in MagneticSensorI2C (thanks to [@padok](https://github.com/padok))
- Improved default trig functions (sine, cosine) - faster, smaller
- Overridable trig functions - plug in your own optimized versions
- Bugfix: microseconds overflow in velocity mode [#287](https://github.com/simplefoc/Arduino-FOC/issues/287)
- Bugfix: KV initialization ([5fc3128](https://github.com/simplefoc/Arduino-FOC/commit/5fc3128d282b65c141ca486327c6235089999627))
- And more bugfixes - see the [complete list of 2.3.1 fixes here](https://github.com/simplefoc/Arduino-FOC/issues?q=is%3Aissue+milestone%3A2.3.1_Release)
- Change: simplify initFOC() API ([d57d32d](https://github.com/simplefoc/Arduino-FOC/commit/d57d32dd8715dbed4e476469bc3de0c052f1d531). [5231e5e](https://github.com/simplefoc/Arduino-FOC/commit/5231e5e1d044b0cc33ede67664b6ef2f9d0a8cdf), [10c5b87](https://github.com/simplefoc/Arduino-FOC/commit/10c5b872672cab72df16ddd738bbf09bcce95d28))
- Change: check for linked driver in currentsense and exit gracefully ([5ef4d9d](https://github.com/simplefoc/Arduino-FOC/commit/5ef4d9d5a92e03da0dd5af7f624243ab30f1b688))
- Compatibility with newest versions of Arduino framework for STM32, Renesas, ESP32, Atmel SAM, Atmel AVR, nRF52 and RP2040
</blockquote>

## Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> <i><small>v2.3.0</small></i>
## Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> <i><small>v2.3.1</small></i>
<iframe class="youtube" src="https://www.youtube.com/embed/Y5kLeqTc6Zk" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
This video demonstrates the Simple FOC library basic usage, electronic connections and shows its capabilities.

Expand All @@ -79,7 +64,7 @@ This video demonstrates the Simple FOC library basic usage, electronic connectio
- **Cross-platform**:
- Seamless code transfer from one microcontroller family to another
- Supports multiple [MCU architectures](microcontrollers):
- Arduino: UNO, MEGA, DUE, Leonardo ....
- Arduino: UNO, MEGA, DUE, Leonardo, Nano, UNO R4, MKR ....
- STM32
- ESP32
- Teensy
Expand Down