mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 08:15:30 +03:00
Gyro Sync separated by target
This commit is contained in:
parent
aadbc94c9a
commit
074e389789
9 changed files with 65 additions and 37 deletions
|
@ -29,7 +29,7 @@
|
|||
extern gyro_t gyro;
|
||||
|
||||
uint32_t targetLooptime;
|
||||
static uint8_t mpuDivider;
|
||||
static uint8_t mpuDividerDrops;
|
||||
|
||||
bool getMpuDataStatus(gyro_t *gyro)
|
||||
{
|
||||
|
@ -48,52 +48,73 @@ void gyroUpdateSampleRate(uint32_t looptime, uint8_t lpf, uint8_t syncGyroToLoop
|
|||
int minLooptime;
|
||||
|
||||
if (syncGyroToLoop) {
|
||||
#ifdef STM32F303xC
|
||||
#if defined(SPRACINGF3) || defined(ALIENWIIF3) || defined(NAZE32PRO) || defined(STM32F3DISCOVERY) || defined(CHEBUZZF3) || defined(EUSTM32F103RC) || defined(PORT103R) || defined(MOTOLAB)
|
||||
if (lpf == INV_FILTER_256HZ_NOLPF2) {
|
||||
gyroSamplePeriod = 125;
|
||||
|
||||
if(!sensors(SENSOR_ACC)) {
|
||||
minLooptime = 500; // Max refresh 2khz
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
minLooptime = 625; // Max refresh 1,6khz
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
gyroSamplePeriod = 1000;
|
||||
minLooptime = 1000; // Full sampling
|
||||
}
|
||||
#elif STM32F10X
|
||||
#elif defined(CC3D)
|
||||
if (lpf == INV_FILTER_256HZ_NOLPF2) {
|
||||
gyroSamplePeriod = 125;
|
||||
|
||||
if(!sensors(SENSOR_ACC)) {
|
||||
minLooptime = 625; // Max refresh 1,33khz
|
||||
minLooptime = 890; // Max refresh 1,12khz
|
||||
} else {
|
||||
minLooptime = 1000; // Max refresh 1khz
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
gyroSamplePeriod = 1000;
|
||||
minLooptime = 1000; // Full sampling
|
||||
}
|
||||
#elif defined(COLIBRI_RACE)
|
||||
if (lpf == INV_FILTER_256HZ_NOLPF2) {
|
||||
gyroSamplePeriod = 125;
|
||||
|
||||
if(!sensors(SENSOR_ACC)) { // TODO - increase to 8khz when oneshot125 can be limited
|
||||
minLooptime = 250; // Max refresh 4khz
|
||||
} else {
|
||||
minLooptime = 250; // Max refresh 4khz
|
||||
}
|
||||
} else {
|
||||
gyroSamplePeriod = 1000;
|
||||
minLooptime = 1000; // Full sampling
|
||||
}
|
||||
#else
|
||||
if (lpf == INV_FILTER_256HZ_NOLPF2) {
|
||||
gyroSamplePeriod = 125;
|
||||
|
||||
if(!sensors(SENSOR_ACC)) {
|
||||
minLooptime = 625; // Max refresh 1,6khz
|
||||
} else {
|
||||
minLooptime = 1625; // Max refresh 615hz
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
gyroSamplePeriod = 1000;
|
||||
|
||||
if(!sensors(SENSOR_ACC)) {
|
||||
minLooptime = 1000; // Full sampling without ACC
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
minLooptime = 2000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
looptime = constrain(looptime, minLooptime, 4000);
|
||||
mpuDivider = (looptime + gyroSamplePeriod -1 ) / gyroSamplePeriod - 1;
|
||||
targetLooptime = (mpuDivider + 1) * gyroSamplePeriod;
|
||||
}
|
||||
else {
|
||||
mpuDivider = 0;
|
||||
mpuDividerDrops = (looptime + gyroSamplePeriod -1 ) / gyroSamplePeriod - 1;
|
||||
targetLooptime = (mpuDividerDrops + 1) * gyroSamplePeriod;
|
||||
} else {
|
||||
mpuDividerDrops = 0;
|
||||
targetLooptime = looptime;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t gyroMPU6xxxGetDivider(void) {
|
||||
return mpuDivider;
|
||||
uint8_t gyroMPU6xxxGetDividerDrops(void) {
|
||||
return mpuDividerDrops;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue