mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +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:
parent
94c5573c39
commit
da35b3844c
1 changed files with 11 additions and 1 deletions
|
@ -148,13 +148,23 @@ void pwmFinishedWritingMotors(uint8_t numberMotors)
|
|||
if(feature(FEATURE_ONESHOT125)){
|
||||
|
||||
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)){
|
||||
lastCounterPtr = motors[index]->cnt;
|
||||
|
||||
*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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue