Skip to content

Commit

Permalink
Fixes after discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Dec 4, 2023
1 parent cd5a01e commit 3f310ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,30 +673,19 @@ void validateAndFixGyroConfig(void)
// check for looptime restrictions based on motor protocol. Motor times have safety margin
float motorUpdateRestriction;

#ifdef USE_DSHOT
#if defined(STM32F4) || defined(STM32G4)
#if defined(USE_DSHOT) && defined(USE_PID_DENOM_CHECK)
/* If bidirectional DSHOT is being used on an F4 or G4 then force DSHOT300. The motor update restrictions then applied
* will automatically consider the loop time and adjust pid_process_denom appropriately
*/
if (motorConfig()->dev.useDshotTelemetry && (motorConfig()->dev.motorPwmProtocol == PWM_TYPE_DSHOT600)) {
motorConfigMutable()->dev.motorPwmProtocol = PWM_TYPE_DSHOT300;
}
#endif

#ifdef USE_PID_DENOM_CHECK
if (motorConfig()->dev.motorPwmProtocol == PWM_TYPE_DSHOT300 || motorConfig()->dev.motorPwmProtocol == PWM_TYPE_DSHOT600) {
if (gyro.sampleRateHz == 8000) {
if (featureIsEnabled(FEATURE_RX_SPI)) {
pidConfigMutable()->pid_process_denom = motorConfig()->dev.useDshotTelemetry ? 4: 2;
} else {
pidConfigMutable()->pid_process_denom = motorConfig()->dev.useDshotTelemetry ? 2: 1;
}
} else if (gyro.sampleRateHz == 3200 && motorConfig()->dev.useDshotTelemetry) {
pidConfigMutable()->pid_process_denom = featureIsEnabled(FEATURE_RX_SPI) ? 2: 1;
if (motorConfig()->dev.useDshotTelemetry) {
if (motorConfig()->dev.motorPwmProtocol == PWM_TYPE_DSHOT600) {
motorConfigMutable()->dev.motorPwmProtocol = PWM_TYPE_DSHOT300;
}
if (gyro.sampleRateHz >= 4000) {
pidConfigMutable()->pid_process_denom = 2;
}
}
#endif
#endif
#endif // USE_DSHOT && USE_PID_DENOM_CHECK
switch (motorConfig()->dev.motorPwmProtocol) {
case PWM_TYPE_STANDARD:
motorUpdateRestriction = 1.0f / BRUSHLESS_MOTORS_PWM_RATE;
Expand Down
4 changes: 4 additions & 0 deletions src/main/target/STM32G47X/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@
#define USE_ESCSERIAL

#define USE_ADC

#define USE_EXTI

#define USE_PID_DENOM_CHECK

#define USE_TIMER_UP_CONFIG

0 comments on commit 3f310ef

Please sign in to comment.