Skip to content

Commit 74a8464

Browse files
Merge pull request #304 from runger1101001/dev
Fixes before release 2.3.1
2 parents 5029fc7 + e543cd2 commit 74a8464

File tree

12 files changed

+47
-10
lines changed

12 files changed

+47
-10
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ Therefore this is an attempt to:
3030
> - Expose I2C errors in MagneticSensorI2C (thanks to [@padok](https://github.com/padok))
3131
> - Improved default trig functions (sine, cosine) - faster, smaller
3232
> - Overridable trig functions - plug in your own optimized versions
33-
> - bugfix: microseconds overflow in velocity mode
34-
> - bugfix: KV initialization
33+
> - Bugfix: microseconds overflow in velocity mode
34+
> - Bugfix: KV initialization
35+
> - Compatibility with newest versions of Arduino framework for STM32, Renesas, ESP32, Atmel SAM, Atmel AVR, nRF52 and RP2040
3536
3637
## Arduino *SimpleFOClibrary* v2.3.1
3738

examples/motion_control/open_loop_motor_control/open_loop_position_example/open_loop_position_example.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void setup() {
6262
void loop() {
6363
// open loop angle movements
6464
// using motor.voltage_limit and motor.velocity_limit
65+
// angles can be positive or negative, negative angles correspond to opposite motor direction
6566
motor.move(target_position);
6667

6768
// user communication

examples/motion_control/open_loop_motor_control/open_loop_velocity_example/open_loop_velocity_example.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void loop() {
6060

6161
// open loop velocity movement
6262
// using motor.voltage_limit and motor.velocity_limit
63+
// to turn the motor "backwards", just set a negative target_velocity
6364
motor.move(target_velocity);
6465

6566
// user communication

src/common/foc_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define _sqrt(a) (_sqrtApprox(a))
1313
#define _isset(a) ( (a) != (NOT_SET) )
1414
#define _UNUSED(v) (void) (v)
15+
#define _powtwo(x) (1 << (x))
1516

1617
// utility defines
1718
#define _2_SQRT3 1.15470053838f

src/current_sense/GenericCurrentSense.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ int GenericCurrentSense::driverAlign(float voltage){
6262
int exit_flag = 1;
6363
if(skip_align) return exit_flag;
6464

65+
if (!initialized) return 0;
66+
6567
// // set phase A active and phases B and C down
6668
// driver->setPwm(voltage, 0, 0);
6769
// _delay(200);

src/current_sense/InlineCurrentSense.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "InlineCurrentSense.h"
2+
#include "communication/SimpleFOCDebug.h"
23
// InlineCurrentSensor constructor
34
// - shunt_resistor - shunt resistor value
45
// - gain - current-sense op-amp gain
@@ -93,6 +94,13 @@ int InlineCurrentSense::driverAlign(float voltage){
9394
int exit_flag = 1;
9495
if(skip_align) return exit_flag;
9596

97+
if (driver==nullptr) {
98+
SIMPLEFOC_DEBUG("CUR: No driver linked!");
99+
return 0;
100+
}
101+
102+
if (!initialized) return 0;
103+
96104
if(_isset(pinA)){
97105
// set phase A active and phases B and C down
98106
driver->setPwm(voltage, 0, 0);

src/current_sense/LowsideCurrentSense.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "LowsideCurrentSense.h"
2+
#include "communication/SimpleFOCDebug.h"
23
// LowsideCurrentSensor constructor
34
// - shunt_resistor - shunt resistor value
45
// - gain - current-sense op-amp gain
@@ -35,6 +36,12 @@ LowsideCurrentSense::LowsideCurrentSense(float _mVpA, int _pinA, int _pinB, int
3536

3637
// Lowside sensor init function
3738
int LowsideCurrentSense::init(){
39+
40+
if (driver==nullptr) {
41+
SIMPLEFOC_DEBUG("CUR: Driver not linked!");
42+
return 0;
43+
}
44+
3845
// configure ADC variables
3946
params = _configureADCLowSide(driver->params,pinA,pinB,pinC);
4047
// if init failed return fail
@@ -89,10 +96,12 @@ PhaseCurrent_s LowsideCurrentSense::getPhaseCurrents(){
8996
// 3 - success but gains inverted
9097
// 4 - success but pins reconfigured and gains inverted
9198
int LowsideCurrentSense::driverAlign(float voltage){
92-
99+
93100
int exit_flag = 1;
94101
if(skip_align) return exit_flag;
95102

103+
if (!initialized) return 0;
104+
96105
if(_isset(pinA)){
97106
// set phase A active and phases B and C down
98107
driver->setPwm(voltage, 0, 0);

src/current_sense/hardware_specific/rp2040/rp2040_mcu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ float _readADCVoltageInline(const int pinA, const void* cs_params) {
2525
// return readings from the same ADC conversion run. The ADC on RP2040 is anyway in round robin mode :-(
2626
// like this we either have to block interrupts, or of course have the chance of reading across
2727
// new ADC conversions, which probably won't improve the accuracy.
28+
_UNUSED(cs_params);
2829

2930
if (pinA>=26 && pinA<=29 && engine.channelsEnabled[pinA-26]) {
3031
return engine.lastResults.raw[pinA-26]*engine.adc_conv;
@@ -36,6 +37,8 @@ float _readADCVoltageInline(const int pinA, const void* cs_params) {
3637

3738

3839
void* _configureADCInline(const void *driver_params, const int pinA, const int pinB, const int pinC) {
40+
_UNUSED(driver_params);
41+
3942
if( _isset(pinA) )
4043
engine.addPin(pinA);
4144
if( _isset(pinB) )

src/drivers/hardware_specific/renesas/renesas.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "communication/SimpleFOCDebug.h"
1414
#include "FspTimer.h"
1515

16+
#define GPT_OPEN (0x00475054ULL)
17+
1618
/*
1719
We use the GPT timers, there are 2 channels (32 bit) + 6 channels (16 bit)
1820
Each channel has 2 outputs (GTIOCAx and GTIOCBx) which can be complimentary.
@@ -202,6 +204,7 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index, bool
202204
t->timer_cfg.p_context = nullptr;
203205
t->timer_cfg.p_extend = &(t->ext_cfg);
204206
t->timer_cfg.cycle_end_ipl = BSP_IRQ_DISABLED;
207+
t->timer_cfg.cycle_end_irq = FSP_INVALID_VECTOR;
205208

206209
t->ext_cfg.p_pwm_cfg = &(t->pwm_cfg);
207210
t->pwm_cfg.trough_ipl = BSP_IRQ_DISABLED;
@@ -256,6 +259,14 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index, bool
256259
t->ext_cfg.gtior_setting.gtior_b.obdflt = active_high ? 0x00 : 0x01;
257260
}
258261

262+
// lets stop the timer in case its running
263+
if (GPT_OPEN == t->ctrl.open) {
264+
if (R_GPT_Stop(&(t->ctrl)) != FSP_SUCCESS) {
265+
SIMPLEFOC_DEBUG("DRV: timer stop failed");
266+
return false;
267+
}
268+
}
269+
259270
memset(&(t->ctrl), 0, sizeof(gpt_instance_ctrl_t));
260271
err = R_GPT_Open(&(t->ctrl),&(t->timer_cfg));
261272
if ((err != FSP_ERR_ALREADY_OPEN) && (err != FSP_SUCCESS)) {
@@ -294,7 +305,7 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index, bool
294305
bool startTimerChannels(RenesasHardwareDriverParams* params, int num_channels) {
295306
uint32_t mask = 0;
296307
for (int i = 0; i < num_channels; i++) {
297-
RenesasTimerConfig* t = params->timer_config[i];
308+
// RenesasTimerConfig* t = params->timer_config[i];
298309
// if (R_GPT_Start(&(t->ctrl)) != FSP_SUCCESS) {
299310
// SIMPLEFOC_DEBUG("DRV: timer start failed");
300311
// return false;

src/sensors/MagneticSensorI2C.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ MagneticSensorI2C::MagneticSensorI2C(uint8_t _chip_address, int _bit_resolution,
2828
// angle read register of the magnetic sensor
2929
angle_register_msb = _angle_register_msb;
3030
// register maximum value (counts per revolution)
31-
cpr = pow(2, _bit_resolution);
31+
cpr = _powtwo(_bit_resolution);
3232

3333
// depending on the sensor architecture there are different combinations of
3434
// LSB and MSB register used bits
@@ -48,7 +48,7 @@ MagneticSensorI2C::MagneticSensorI2C(MagneticSensorI2CConfig_s config){
4848
// angle read register of the magnetic sensor
4949
angle_register_msb = config.angle_register;
5050
// register maximum value (counts per revolution)
51-
cpr = pow(2, config.bit_resolution);
51+
cpr = _powtwo(config.bit_resolution);
5252

5353
int bits_used_msb = config.data_start_bit - 7;
5454
lsb_used = config.bit_resolution - bits_used_msb;

0 commit comments

Comments
 (0)