1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 21:35:44 +03:00

Bugfix for when looptime is longer than timer size.

Previously, when a looptime of 8300 uS was chosen, the output would be unpredictable.  Now the shots are fired only after every loop, not when the timer overflows.
This commit is contained in:
Ben Hitchcock 2014-11-29 22:51:41 +08:00
parent 94c5573c39
commit da35b3844c

View file

@ -148,13 +148,23 @@ void pwmFinishedWritingMotors(uint8_t numberMotors)
if(feature(FEATURE_ONESHOT125)){ if(feature(FEATURE_ONESHOT125)){
for(index = 0; index < numberMotors; index++){ for(index = 0; index < numberMotors; index++){
// Set the counter to overflow if it's the first motor to output, or if we change timers // Force the counter to overflow if it's the first motor to output, or if we change timers
if((index == 0) || (motors[index]->cnt != lastCounterPtr)){ if((index == 0) || (motors[index]->cnt != lastCounterPtr)){
lastCounterPtr = motors[index]->cnt; lastCounterPtr = motors[index]->cnt;
*motors[index]->cnt = 0xfffe; *motors[index]->cnt = 0xfffe;
} }
} }
// Wait until the timers have overflowed (should take less than 0.125 uS)
while(*motors[numberMotors - 1]->cnt >= 0xfffe){
}
// Set the compare register to 0, which stops the output pulsing if the timer overflows before the main loop completes again.
// This compare register will be set to the output value on the next main loop.
for(index = 0; index < numberMotors; index++){
*motors[index]->ccr = 0;
}
} }
} }