pic32/libraries/Servo/Servo.cpp
//************************************************************************
// Note: PIC32 timers (TMRn) reset to zero when they match PRn.
PIC32 timers (TMRn) reset to zero when they match PRn.
PIC32 timers ( TMRn ) reset to zero when they match PRn .
void handle_interrupts(int timer, volatile unsigned int *TMRn, volatile unsigned int *PRn)
{
  static uint32_t AccumulatedTicks[3] = {0,0,0};
  if (timer >= 3)
  {
    return;
  }
  if ( channel[timer] < 0 )
  {
    AccumulatedTicks[timer] = 0;
  }
  else
  {
    if ( SERVO_INDEX(timer,channel[timer]) < ServoCount && SERVO(timer,channel[timer]).Pin.isActive == true )
    {
      digitalWrite( SERVO(timer,channel[timer]).Pin.nbr, LOW);
    }
  }
  channel[timer]++;
  if ( SERVO_INDEX(timer,channel[timer]) < ServoCount && channel[timer] < SERVOS_PER_TIMER)
  {
    *PRn  = SERVO(timer,channel[timer]).ticks;
    if (SERVO(timer,channel[timer]).Pin.isActive == true)
    {
      digitalWrite( SERVO(timer,channel[timer]).Pin.nbr, HIGH);
    }
    AccumulatedTicks[timer] += *PRn;
  }
  else
  {
    if (AccumulatedTicks[timer] < (usToTicks(REFRESH_INTERVAL) - 4))
    {
      *PRn  = (unsigned int)(usToTicks(REFRESH_INTERVAL)) - AccumulatedTicks[timer];
    }
    else
    {
      *PRn  = *TMRn + 4;
    }
    channel[timer] = -1;
  }
}
void handle_interrupts ( int timer , volatile unsigned int * TMRn , volatile unsigned int * PRn ) { static uint32_t AccumulatedTicks [ 3 ] = { 0 , 0 , 0 } ; if ( timer >= 3 ) { return ; } if ( channel [ timer ] < 0 ) { AccumulatedTicks [ timer ] = 0 ; } else { if ( SERVO_INDEX ( timer , channel [ timer ] ) < ServoCount && SERVO ( timer , channel [ timer ] ) . Pin . isActive == true ) { digitalWrite ( SERVO ( timer , channel [ timer ] ) . Pin . nbr , LOW ) ; } } channel [ timer ] ++ ; if ( SERVO_INDEX ( timer , channel [ timer ] ) < ServoCount && channel [ timer ] < SERVOS_PER_TIMER ) { * PRn = SERVO ( timer , channel [ timer ] ) . ticks ; if ( SERVO ( timer , channel [ timer ] ) . Pin . isActive == true ) { digitalWrite ( SERVO ( timer , channel [ timer ] ) . Pin . nbr , HIGH ) ; } AccumulatedTicks [ timer ] += * PRn ; } else { if ( AccumulatedTicks [ timer ] < ( usToTicks ( REFRESH_INTERVAL ) - 4 ) ) { * PRn = ( unsigned int ) ( usToTicks ( REFRESH_INTERVAL ) ) - AccumulatedTicks [ timer ] ; } else { * PRn = * TMRn + 4 ; } channel [ timer ] = -1 ; } }
Note: PIC32 timers (TMRn) reset to zero when they match PRn.
Note : PIC32 timers ( TMRn ) reset to zero when they match PRn .
// Store the number of ticks since the first rising edge for this timer // Test for invalid timer number // If this value is -1, then we have just finished with the time from  // the end of the last pulse and need to start with the first servo  // index on this timer again. // Clear the accumulated time for this timer on first rising edge // If this is not the first pulse, then set the old pin low // pulse this channel low if activated // increment to the next channel // If we have not run out of channels (on this timer), // Then set the time we want to fire next (the width for this channel) // Set this channel's pin high if its active // check if activated // its an active channel so pulse it high // Add the time we are about to spend on this channel // Otherwise, finished all channels so next fire needs to be at  // REFRESH_INTERVAL - AccumulatedTicks // at least REFRESH_INTERVAL has elapsed // this will get incremented at the end of the refresh period to  // start again at the first channel