mirror of https://github.com/rusefi/rusefi-1.git
fix ETB PWM (#2870)
* iwpm * dc motor has configure * consume * format * use fake PWM to save one SimplePwm instance * comments * not sure why I changed that * init the pins otherwise * typo Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
a65448ce80
commit
50889671c0
|
@ -12,6 +12,17 @@
|
|||
#include "dc_motors.h"
|
||||
#include "dc_motor.h"
|
||||
|
||||
// Simple wrapper to use an OutputPin as "PWM" that can only do 0 or 1
|
||||
struct PwmWrapper : public IPwm {
|
||||
OutputPin& m_pin;
|
||||
|
||||
PwmWrapper(OutputPin& pin) : m_pin(pin) { }
|
||||
|
||||
void setSimplePwmDutyCycle(float dutyCycle) override {
|
||||
m_pin.setValue(dutyCycle > 0.5f);
|
||||
}
|
||||
};
|
||||
|
||||
class DcHardware {
|
||||
private:
|
||||
OutputPin m_pinEnable;
|
||||
|
@ -19,9 +30,12 @@ private:
|
|||
OutputPin m_pinDir2;
|
||||
OutputPin m_disablePin;
|
||||
|
||||
SimplePwm m_pwmEnable;
|
||||
SimplePwm m_pwmDir1;
|
||||
SimplePwm m_pwmDir2;
|
||||
PwmWrapper wrappedEnable{m_pinEnable};
|
||||
PwmWrapper wrappedDir1{m_pinDir1};
|
||||
PwmWrapper wrappedDir2{m_pinDir2};
|
||||
|
||||
SimplePwm m_pwm1;
|
||||
SimplePwm m_pwm2;
|
||||
|
||||
public:
|
||||
DcHardware() : dcMotor(m_disablePin) {}
|
||||
|
@ -29,9 +43,8 @@ public:
|
|||
TwoPinDcMotor dcMotor;
|
||||
|
||||
void setFrequency(int frequency) {
|
||||
m_pwmEnable.setFrequency(frequency);
|
||||
m_pwmDir1.setFrequency(frequency);
|
||||
m_pwmDir2.setFrequency(frequency);
|
||||
m_pwm1.setFrequency(frequency);
|
||||
m_pwm2.setFrequency(frequency);
|
||||
}
|
||||
|
||||
void start(bool useTwoWires,
|
||||
|
@ -50,17 +63,12 @@ public:
|
|||
// Clamp to >100hz
|
||||
int clampedFrequency = maxI(100, frequency);
|
||||
|
||||
if (useTwoWires) {
|
||||
m_pinEnable.initPin("ETB Enable", pinEnable);
|
||||
|
||||
// no need to complicate event queue with ETB PWM in unit tests
|
||||
#if ! EFI_UNIT_TEST
|
||||
startSimplePwmHard(&m_pwmEnable, "ETB Enable",
|
||||
executor,
|
||||
pinEnable,
|
||||
&m_pinEnable,
|
||||
clampedFrequency,
|
||||
0
|
||||
);
|
||||
|
||||
startSimplePwmHard(&m_pwmDir1, "ETB Dir 1",
|
||||
startSimplePwmHard(&m_pwm1, "ETB Dir 1",
|
||||
executor,
|
||||
pinDir1,
|
||||
&m_pinDir1,
|
||||
|
@ -68,16 +76,33 @@ public:
|
|||
0
|
||||
);
|
||||
|
||||
startSimplePwmHard(&m_pwmDir2, "ETB Dir 2",
|
||||
startSimplePwmHard(&m_pwm2, "ETB Dir 2",
|
||||
executor,
|
||||
pinDir2,
|
||||
&m_pinDir2,
|
||||
clampedFrequency,
|
||||
0
|
||||
);
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
#endif // EFI_UNIT_TEST
|
||||
|
||||
dcMotor.configure(m_pwmEnable, m_pwmDir1, m_pwmDir2);
|
||||
dcMotor.configure(wrappedEnable, m_pwm1, m_pwm2);
|
||||
} else {
|
||||
m_pinDir1.initPin("ETB Dir 1", pinDir1);
|
||||
m_pinDir2.initPin("ETB Dir 2", pinDir2);
|
||||
|
||||
// no need to complicate event queue with ETB PWM in unit tests
|
||||
#if ! EFI_UNIT_TEST
|
||||
startSimplePwmHard(&m_pwm1, "ETB Enable",
|
||||
executor,
|
||||
pinEnable,
|
||||
&m_pinEnable,
|
||||
clampedFrequency,
|
||||
0
|
||||
);
|
||||
#endif // EFI_UNIT_TEST
|
||||
|
||||
dcMotor.configure(m_pwm1, wrappedDir1, wrappedDir2);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue