Fix oneshot timer overflow by @nathansoi

This commit is contained in:
borisbstyle 2016-08-02 23:13:59 +02:00
parent 571b9ba991
commit 3cd6ed4245
1 changed files with 11 additions and 11 deletions

View File

@ -170,18 +170,18 @@ void pwmEnableMotors(void)
void pwmCompleteOneshotMotorUpdate(uint8_t motorCount)
{
uint8_t index;
TIM_TypeDef *lastTimerPtr = NULL;
for(index = 0; index < motorCount; index++){
// Force the timer to overflow if it's the first motor to output, or if we change timers
if(motors[index]->tim != lastTimerPtr){
lastTimerPtr = motors[index]->tim;
timerForceOverflow(motors[index]->tim);
for (int index = 0; index < motorCount; index++) {
bool overflowed = false;
// If we have not already overflowed this timer
for (int j = 0; j < index; j++) {
if (motors[j]->tim == motors[index]->tim) {
overflowed = true;
break;
}
}
if (!overflowed) {
timerForceOverflow(motors[index]->tim);
}
// 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.
*motors[index]->ccr = 0;