Skip to content

Commit b040f7d

Browse files
committed
merge with dev
2 parents d518987 + 1d3e44c commit b040f7d

File tree

12 files changed

+38
-37
lines changed

12 files changed

+38
-37
lines changed

src/BLDCMotor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
485485
center = driver->voltage_limit/2;
486486
// Clarke transform
487487
Ua = Ualpha + center;
488-
Ub = -0.5 * Ualpha + _SQRT3_2 * Ubeta + center;
489-
Uc = -0.5 * Ualpha - _SQRT3_2 * Ubeta + center;
488+
Ub = -0.5f * Ualpha + _SQRT3_2 * Ubeta + center;
489+
Uc = -0.5f * Ualpha - _SQRT3_2 * Ubeta + center;
490490

491491
if (!modulation_centered) {
492492
float Umin = min(Ua, min(Ub, Uc));
@@ -529,7 +529,7 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
529529
sector = floor(angle_el / _PI_3) + 1;
530530
// calculate the duty cycles
531531
float T1 = _SQRT3*_sin(sector*_PI_3 - angle_el) * Uout;
532-
float T2 = _SQRT3*_sin(angle_el - (sector-1.0)*_PI_3) * Uout;
532+
float T2 = _SQRT3*_sin(angle_el - (sector-1.0f)*_PI_3) * Uout;
533533
// two versions possible
534534
float T0 = 0; // pulled to 0 - better for low power supply voltage
535535
if (modulation_centered) {

src/common/foc_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ float _sin(float a){
2323
}else if(a < _3PI_2){
2424
// return -sine_array[(int)(199.0f*((a - _PI) / (_PI/2.0)))];
2525
//return -sine_array[-398 + (int)(126.6873f*a)]; // float array optimized
26-
return -0.0001*sine_array[-398 + _round(126.6873f*a)]; // int array optimized
26+
return -0.0001f*sine_array[-398 + _round(126.6873f*a)]; // int array optimized
2727
} else {
2828
// return -sine_array[(int)(199.0f*(1.0f - (a - 3*_PI/2) / (_PI/2.0)))];
2929
//return -sine_array[796 - (int)(126.6873f*a)]; // float array optimized
30-
return -0.0001*sine_array[796 - _round(126.6873f*a)]; // int array optimized
30+
return -0.0001f*sine_array[796 - _round(126.6873f*a)]; // int array optimized
3131
}
3232
}
3333

src/common/foc_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// sign function
77
#define _sign(a) ( ( (a) < 0 ) ? -1 : ( (a) > 0 ) )
8-
#define _round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
8+
#define _round(x) ((x)>=0?(long)((x)+0.5f):(long)((x)-0.5f))
99
#define _constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
1010
#define _sqrt(a) (_sqrtApprox(a))
1111
#define _isset(a) ( (a) != (NOT_SET) )
@@ -25,7 +25,7 @@
2525
#define _3PI_2 4.71238898038f
2626
#define _PI_6 0.52359877559f
2727

28-
#define NOT_SET -12345.0
28+
#define NOT_SET -12345.0f
2929
#define _HIGH_IMPEDANCE 0
3030
#define _HIGH_Z _HIGH_IMPEDANCE
3131
#define _ACTIVE 1

src/common/pid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ float PIDController::operator() (float error){
2828
float proportional = P * error;
2929
// Tustin transform of the integral part
3030
// u_ik = u_ik_1 + I*Ts/2*(ek + ek_1)
31-
float integral = integral_prev + I*Ts*0.5*(error + error_prev);
31+
float integral = integral_prev + I*Ts*0.5f*(error + error_prev);
3232
// antiwindup - limit the output
3333
integral = _constrain(integral, -limit, limit);
3434
// Discrete derivation

src/current_sense/InlineCurrentSense.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ int InlineCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
8080
// read the current 100 times ( arbitrary number )
8181
for (int i = 0; i < 100; i++) {
8282
PhaseCurrent_s c1 = getPhaseCurrents();
83-
c.a = c.a*0.6 + 0.4f*c1.a;
84-
c.b = c.b*0.6 + 0.4f*c1.b;
85-
c.c = c.c*0.6 + 0.4f*c1.c;
83+
c.a = c.a*0.6f + 0.4f*c1.a;
84+
c.b = c.b*0.6f + 0.4f*c1.b;
85+
c.c = c.c*0.6f + 0.4f*c1.c;
8686
_delay(3);
8787
}
8888
driver->setPwm(0, 0, 0);
@@ -117,9 +117,9 @@ int InlineCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
117117
// read the current 50 times
118118
for (int i = 0; i < 100; i++) {
119119
PhaseCurrent_s c1 = getPhaseCurrents();
120-
c.a = c.a*0.6 + 0.4f*c1.a;
121-
c.b = c.b*0.6 + 0.4f*c1.b;
122-
c.c = c.c*0.6 + 0.4f*c1.c;
120+
c.a = c.a*0.6f + 0.4f*c1.a;
121+
c.b = c.b*0.6f + 0.4f*c1.b;
122+
c.c = c.c*0.6f + 0.4f*c1.c;
123123
_delay(3);
124124
}
125125
driver->setPwm(0, 0, 0);
@@ -155,7 +155,7 @@ int InlineCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
155155
// read the adc voltage 500 times ( arbitrary number )
156156
for (int i = 0; i < 50; i++) {
157157
PhaseCurrent_s c1 = getPhaseCurrents();
158-
c.c = (c.c+c1.c)/50.0;
158+
c.c = (c.c+c1.c)/50.0f;
159159
}
160160
driver->setPwm(0, 0, 0);
161161
gain_c *= _sign(c.c);

src/current_sense/InlineCurrentSense.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ class InlineCurrentSense: public CurrentSense{
4848
int pinC; //!< pin C analog pin for current measurement
4949

5050
// gain variables
51-
double shunt_resistor; //!< Shunt resistor value
52-
double amp_gain; //!< amp gain value
53-
double volts_to_amps_ratio; //!< Volts to amps ratio
51+
float shunt_resistor; //!< Shunt resistor value
52+
float amp_gain; //!< amp gain value
53+
float volts_to_amps_ratio; //!< Volts to amps ratio
5454

5555
/**
5656
* Function finding zero offsets of the ADC
5757
*/
5858
void calibrateOffsets();
59-
double offset_ia; //!< zero current A voltage value (center of the adc reading)
60-
double offset_ib; //!< zero current B voltage value (center of the adc reading)
61-
double offset_ic; //!< zero current C voltage value (center of the adc reading)
59+
float offset_ia; //!< zero current A voltage value (center of the adc reading)
60+
float offset_ib; //!< zero current B voltage value (center of the adc reading)
61+
float offset_ic; //!< zero current C voltage value (center of the adc reading)
6262

6363
};
6464

src/current_sense/LowsideCurrentSense.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ class LowsideCurrentSense: public CurrentSense{
4949
int pinC; //!< pin C analog pin for current measurement
5050

5151
// gain variables
52-
double shunt_resistor; //!< Shunt resistor value
53-
double amp_gain; //!< amp gain value
54-
double volts_to_amps_ratio; //!< Volts to amps ratio
52+
float shunt_resistor; //!< Shunt resistor value
53+
float amp_gain; //!< amp gain value
54+
float volts_to_amps_ratio; //!< Volts to amps ratio
5555

5656
/**
5757
* Function finding zero offsets of the ADC
5858
*/
5959
void calibrateOffsets();
60-
double offset_ia; //!< zero current A voltage value (center of the adc reading)
61-
double offset_ib; //!< zero current B voltage value (center of the adc reading)
62-
double offset_ic; //!< zero current C voltage value (center of the adc reading)
60+
float offset_ia; //!< zero current A voltage value (center of the adc reading)
61+
float offset_ib; //!< zero current B voltage value (center of the adc reading)
62+
float offset_ic; //!< zero current C voltage value (center of the adc reading)
6363

6464
};
6565

src/drivers/BLDCDriver3PWM.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ void BLDCDriver3PWM::setPhaseState(int sa, int sb, int sc) {
7575
void BLDCDriver3PWM::setPwm(float Ua, float Ub, float Uc) {
7676

7777
// limit the voltage in driver
78-
Ua = _constrain(Ua, 0.0, voltage_limit);
79-
Ub = _constrain(Ub, 0.0, voltage_limit);
80-
Uc = _constrain(Uc, 0.0, voltage_limit);
78+
Ua = _constrain(Ua, 0.0f, voltage_limit);
79+
Ub = _constrain(Ub, 0.0f, voltage_limit);
80+
Uc = _constrain(Uc, 0.0f, voltage_limit);
8181
// calculate duty cycle
8282
// limited in [0,1]
8383
dc_a = _constrain(Ua / voltage_power_supply, 0.0f , 1.0f );

src/drivers/StepperDriver2PWM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ void StepperDriver2PWM::setPwm(float Ua, float Ub) {
9090
Ua = _constrain(Ua, -voltage_limit, voltage_limit);
9191
Ub = _constrain(Ub, -voltage_limit, voltage_limit);
9292
// hardware specific writing
93-
duty_cycle1 = _constrain(abs(Ua)/voltage_power_supply,0.0,1.0);
94-
duty_cycle2 = _constrain(abs(Ub)/voltage_power_supply,0.0,1.0);
93+
duty_cycle1 = _constrain(abs(Ua)/voltage_power_supply,0.0f,1.0f);
94+
duty_cycle2 = _constrain(abs(Ub)/voltage_power_supply,0.0f,1.0f);
9595

9696
// phase 1 direction
9797
digitalWrite(dir1a, Ua >= 0 ? LOW : HIGH);

src/drivers/StepperDriver4PWM.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ void StepperDriver4PWM::setPwm(float Ualpha, float Ubeta) {
6767
Ubeta = _constrain(Ubeta, -voltage_limit, voltage_limit);
6868
// hardware specific writing
6969
if( Ualpha > 0 )
70-
duty_cycle1B = _constrain(abs(Ualpha)/voltage_power_supply,0.0,1.0);
70+
duty_cycle1B = _constrain(abs(Ualpha)/voltage_power_supply,0.0f,1.0f);
7171
else
72-
duty_cycle1A = _constrain(abs(Ualpha)/voltage_power_supply,0.0,1.0);
72+
duty_cycle1A = _constrain(abs(Ualpha)/voltage_power_supply,0.0f,1.0f);
7373

7474
if( Ubeta > 0 )
75-
duty_cycle2B = _constrain(abs(Ubeta)/voltage_power_supply,0.0,1.0);
75+
duty_cycle2B = _constrain(abs(Ubeta)/voltage_power_supply,0.0f,1.0f);
7676
else
77-
duty_cycle2A = _constrain(abs(Ubeta)/voltage_power_supply,0.0,1.0);
77+
duty_cycle2A = _constrain(abs(Ubeta)/voltage_power_supply,0.0f,1.0f);
7878
// write to hardware
7979
_writeDutyCycle4PWM(duty_cycle1A, duty_cycle1B, duty_cycle2A, duty_cycle2B, pwm1A, pwm1B, pwm2A, pwm2B);
8080
}

src/drivers/hardware_specific/atmega32u4_mcu.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ void _writeDutyCycle4PWM(float dc_1a, float dc_1b, float dc_2a, float dc_2b, in
9393

9494

9595

96+
9697
// function configuring pair of high-low side pwm channels, 32khz frequency and center aligned pwm
9798
int _configureComplementaryPair(int pinH, int pinL) {
9899
if( (pinH == 3 && pinL == 11 ) || (pinH == 11 && pinL == 3 ) ){
@@ -143,7 +144,7 @@ int _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, const
143144
ret_flag += _configureComplementaryPair(pinB_h, pinB_l);
144145
ret_flag += _configureComplementaryPair(pinC_h, pinC_l);
145146
return ret_flag; // returns -1 if not well configured
146-
}
147+
147148

148149
// function setting the
149150
void _setPwmPair(int pinH, int pinL, float val, int dead_time)

0 commit comments

Comments
 (0)