Skip to content
Draft
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
2 changes: 2 additions & 0 deletions src/common/base_classes/StepperDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class StepperDriver: public FOCDriver{
public:
float Ua; //!< currently set phase A voltage
float Ub; //!< currently set phase B voltage

/**
* Set phase voltages to the hardware
Expand Down
7 changes: 7 additions & 0 deletions src/current_sense/LowsideCurrentSense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,12 @@ PhaseCurrent_s LowsideCurrentSense::getPhaseCurrents(){
current.a = (!_isset(pinA)) ? 0 : (_readADCVoltageLowSide(pinA, params) - offset_ia)*gain_a;// amps
current.b = (!_isset(pinB)) ? 0 : (_readADCVoltageLowSide(pinB, params) - offset_ib)*gain_b;// amps
current.c = (!_isset(pinC)) ? 0 : (_readADCVoltageLowSide(pinC, params) - offset_ic)*gain_c; // amps

if (driver_type == DriverType::Stepper){
static StepperDriver* stepper_driver = static_cast<StepperDriver*>(driver);
current.a *= _sign(stepper_driver->Ua);
current.b *= _sign(stepper_driver->Ub);
}

return current;
}
4 changes: 3 additions & 1 deletion src/drivers/StepperDriver2PWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ void StepperDriver2PWM::setPhaseState(PhaseState sa, PhaseState sb) {
}

// Set voltage to the pwm pin
void StepperDriver2PWM::setPwm(float Ua, float Ub) {
void StepperDriver2PWM::setPwm(float Ua_, float Ub_) {
Ua = Ua_;
Ub = Ub_;
float duty_cycle1(0.0f),duty_cycle2(0.0f);
// limit the voltage in driver
Ua = _constrain(Ua, -voltage_limit, voltage_limit);
Expand Down
20 changes: 11 additions & 9 deletions src/drivers/StepperDriver4PWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,23 @@ void StepperDriver4PWM::setPhaseState(PhaseState sa, PhaseState sb) {


// Set voltage to the pwm pin
void StepperDriver4PWM::setPwm(float Ualpha, float Ubeta) {
void StepperDriver4PWM::setPwm(float Ua_, float Ub_) {
Ua = Ua_;
Ub = Ub_;
float duty_cycle1A(0.0f),duty_cycle1B(0.0f),duty_cycle2A(0.0f),duty_cycle2B(0.0f);
// limit the voltage in driver
Ualpha = _constrain(Ualpha, -voltage_limit, voltage_limit);
Ubeta = _constrain(Ubeta, -voltage_limit, voltage_limit);
Ua = _constrain(Ua, -voltage_limit, voltage_limit);
Ub = _constrain(Ub, -voltage_limit, voltage_limit);
// hardware specific writing
if( Ualpha > 0 )
duty_cycle1B = _constrain(abs(Ualpha)/voltage_power_supply,0.0f,1.0f);
if( Ua > 0 )
duty_cycle1B = _constrain(abs(Ua)/voltage_power_supply,0.0f,1.0f);
else
duty_cycle1A = _constrain(abs(Ualpha)/voltage_power_supply,0.0f,1.0f);
duty_cycle1A = _constrain(abs(Ua)/voltage_power_supply,0.0f,1.0f);

if( Ubeta > 0 )
duty_cycle2B = _constrain(abs(Ubeta)/voltage_power_supply,0.0f,1.0f);
if( Ub > 0 )
duty_cycle2B = _constrain(abs(Ub)/voltage_power_supply,0.0f,1.0f);
else
duty_cycle2A = _constrain(abs(Ubeta)/voltage_power_supply,0.0f,1.0f);
duty_cycle2A = _constrain(abs(Ub)/voltage_power_supply,0.0f,1.0f);
// write to hardware
_writeDutyCycle4PWM(duty_cycle1A, duty_cycle1B, duty_cycle2A, duty_cycle2B, params);
}