mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 22:05:17 +03:00
Rework Fast PWM protocol configuration and timing
This commit is contained in:
parent
c74c5df73d
commit
9e5c5e88c7
12 changed files with 67 additions and 77 deletions
|
@ -135,27 +135,6 @@ static void pwmWriteStandard(uint8_t index, uint16_t value)
|
|||
{
|
||||
*motors[index]->ccr = value;
|
||||
}
|
||||
#if defined(STM32F10X) && !defined(CC3D)
|
||||
static void pwmWriteOneshot125(uint8_t index, uint16_t value)
|
||||
{
|
||||
*motors[index]->ccr = value * 21 / 6; // 24Mhz -> 8Mhz
|
||||
}
|
||||
|
||||
static void pwmWriteOneshot42(uint8_t index, uint16_t value)
|
||||
{
|
||||
*motors[index]->ccr = value * 7 / 6;
|
||||
}
|
||||
#else
|
||||
static void pwmWriteOneshot125(uint8_t index, uint16_t value)
|
||||
{
|
||||
*motors[index]->ccr = value * 3; // 24Mhz -> 8Mhz
|
||||
}
|
||||
|
||||
static void pwmWriteOneshot42(uint8_t index, uint16_t value)
|
||||
{
|
||||
*motors[index]->ccr = value;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void pwmWriteMultiShot(uint8_t index, uint16_t value)
|
||||
{
|
||||
|
@ -227,20 +206,30 @@ void pwmBrushlessMotorConfig(const timerHardware_t *timerHardware, uint8_t motor
|
|||
motors[motorIndex]->pwmWritePtr = pwmWriteStandard;
|
||||
}
|
||||
|
||||
void pwmOneshotMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint8_t useOneshot42)
|
||||
void pwmFastPwmMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint8_t fastPwmProtocolType, uint16_t motorPwmRate, uint8_t useUnsyncedPwm, uint16_t idlePulse)
|
||||
{
|
||||
motors[motorIndex] = pwmOutConfig(timerHardware, ONESHOT_TIMER_MHZ, 0xFFFF, 0);
|
||||
if (useOneshot42) {
|
||||
motors[motorIndex]->pwmWritePtr = pwmWriteOneshot42;
|
||||
} else {
|
||||
motors[motorIndex]->pwmWritePtr = pwmWriteOneshot125;
|
||||
}
|
||||
}
|
||||
uint32_t timerMhzCounter;
|
||||
|
||||
void pwmMultiShotMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex)
|
||||
{
|
||||
motors[motorIndex] = pwmOutConfig(timerHardware, MULTISHOT_TIMER_MHZ, 0xFFFF, 0);
|
||||
motors[motorIndex]->pwmWritePtr = pwmWriteMultiShot;
|
||||
switch (fastPwmProtocolType) {
|
||||
default:
|
||||
case (PWM_TYPE_ONESHOT125):
|
||||
timerMhzCounter = ONESHOT125_TIMER_MHZ;
|
||||
break;
|
||||
case (PWM_TYPE_ONESHOT42):
|
||||
timerMhzCounter = ONESHOT42_TIMER_MHZ;
|
||||
break;
|
||||
case (PWM_TYPE_MULTISHOT):
|
||||
timerMhzCounter = MULTISHOT_TIMER_MHZ;
|
||||
}
|
||||
|
||||
if (useUnsyncedPwm) {
|
||||
uint32_t hz = timerMhzCounter * 1000000;
|
||||
motors[motorIndex] = pwmOutConfig(timerHardware, timerMhzCounter, hz / motorPwmRate, idlePulse);
|
||||
} else {
|
||||
motors[motorIndex] = pwmOutConfig(timerHardware, timerMhzCounter, 0xFFFF, 0);
|
||||
}
|
||||
|
||||
motors[motorIndex]->pwmWritePtr = (fastPwmProtocolType == PWM_TYPE_MULTISHOT) ? pwmWriteMultiShot : pwmWriteStandard;
|
||||
}
|
||||
|
||||
#ifdef USE_SERVOS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue