mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
Fix bug where PPM rx stops working on sparky or CC3D when using motor
PWM rate > 500 (brushed motor mode). Fix is the same as for OneShot since both brushed motors and oneshot use an 8mhz timer. Fixes #58
This commit is contained in:
parent
b2f9e603df
commit
5d5fd81b2e
4 changed files with 12 additions and 4 deletions
|
@ -580,12 +580,12 @@ pwmOutputConfiguration_t *pwmInit(drv_pwm_config_t *init)
|
||||||
|
|
||||||
if (type == MAP_TO_PPM_INPUT) {
|
if (type == MAP_TO_PPM_INPUT) {
|
||||||
#ifdef CC3D
|
#ifdef CC3D
|
||||||
if (init->useOneshot) {
|
if (init->useOneshot || isMotorBrushed(init->motorPwmRate)) {
|
||||||
ppmAvoidPWMTimerClash(timerHardwarePtr, TIM4);
|
ppmAvoidPWMTimerClash(timerHardwarePtr, TIM4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef SPARKY
|
#ifdef SPARKY
|
||||||
if (init->useOneshot) {
|
if (init->useOneshot || isMotorBrushed(init->motorPwmRate)) {
|
||||||
ppmAvoidPWMTimerClash(timerHardwarePtr, TIM2);
|
ppmAvoidPWMTimerClash(timerHardwarePtr, TIM2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -596,7 +596,7 @@ pwmOutputConfiguration_t *pwmInit(drv_pwm_config_t *init)
|
||||||
} else if (type == MAP_TO_MOTOR_OUTPUT) {
|
} else if (type == MAP_TO_MOTOR_OUTPUT) {
|
||||||
if (init->useOneshot) {
|
if (init->useOneshot) {
|
||||||
pwmOneshotMotorConfig(timerHardwarePtr, pwmOutputConfiguration.motorCount);
|
pwmOneshotMotorConfig(timerHardwarePtr, pwmOutputConfiguration.motorCount);
|
||||||
} else if (init->motorPwmRate > 500) {
|
} else if (isMotorBrushed(init->motorPwmRate)) {
|
||||||
pwmBrushedMotorConfig(timerHardwarePtr, pwmOutputConfiguration.motorCount, init->motorPwmRate, init->idlePulse);
|
pwmBrushedMotorConfig(timerHardwarePtr, pwmOutputConfiguration.motorCount, init->motorPwmRate, init->idlePulse);
|
||||||
} else {
|
} else {
|
||||||
pwmBrushlessMotorConfig(timerHardwarePtr, pwmOutputConfiguration.motorCount, init->motorPwmRate, init->idlePulse);
|
pwmBrushlessMotorConfig(timerHardwarePtr, pwmOutputConfiguration.motorCount, init->motorPwmRate, init->idlePulse);
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
|
|
||||||
#define PWM_TIMER_MHZ 1
|
#define PWM_TIMER_MHZ 1
|
||||||
#define ONESHOT125_TIMER_MHZ 8
|
#define ONESHOT125_TIMER_MHZ 8
|
||||||
|
#define PWM_BRUSHED_TIMER_MHZ 8
|
||||||
|
|
||||||
|
|
||||||
typedef struct sonarGPIOConfig_s {
|
typedef struct sonarGPIOConfig_s {
|
||||||
GPIO_TypeDef *gpio;
|
GPIO_TypeDef *gpio;
|
||||||
|
|
|
@ -47,7 +47,6 @@ static pwmOutputPort_t *motors[MAX_PWM_MOTORS];
|
||||||
#ifdef USE_SERVOS
|
#ifdef USE_SERVOS
|
||||||
static pwmOutputPort_t *servos[MAX_PWM_SERVOS];
|
static pwmOutputPort_t *servos[MAX_PWM_SERVOS];
|
||||||
#endif
|
#endif
|
||||||
#define PWM_BRUSHED_TIMER_MHZ 8
|
|
||||||
|
|
||||||
static uint8_t allocatedOutputPortCount = 0;
|
static uint8_t allocatedOutputPortCount = 0;
|
||||||
|
|
||||||
|
@ -172,6 +171,11 @@ void pwmCompleteOneshotMotorUpdate(uint8_t motorCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isMotorBrushed(uint16_t motorPwmRate)
|
||||||
|
{
|
||||||
|
return (motorPwmRate > 500);
|
||||||
|
}
|
||||||
|
|
||||||
void pwmBrushedMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse)
|
void pwmBrushedMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse)
|
||||||
{
|
{
|
||||||
uint32_t hz = PWM_BRUSHED_TIMER_MHZ * 1000000;
|
uint32_t hz = PWM_BRUSHED_TIMER_MHZ * 1000000;
|
||||||
|
|
|
@ -22,3 +22,5 @@ void pwmShutdownPulsesForAllMotors(uint8_t motorCount);
|
||||||
void pwmCompleteOneshotMotorUpdate(uint8_t motorCount);
|
void pwmCompleteOneshotMotorUpdate(uint8_t motorCount);
|
||||||
|
|
||||||
void pwmWriteServo(uint8_t index, uint16_t value);
|
void pwmWriteServo(uint8_t index, uint16_t value);
|
||||||
|
|
||||||
|
bool isMotorBrushed(uint16_t motorPwmRate);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue