operating mode servo library

Hi guys

I working on a quadrocopter and currently using the servo library to write the values to the ESC/brushless motors. My question is about the generation of the Signal. I tried to understand the servo.cpp file but didn't found out more about my problem.

for a copter it's very important that the values for the ESC's are updated really often so the Signal has to have a high frequency. By changing the varible REFRESH_INTERVALL a frequency of maximum 200 Hz can be reached, which means one period of the Signal takes about 5ms.

This is high enough but what happens if I attach more ESC's (in total 4) and let the library generate all Signals. Will it create them in parallel or after each other (which would mean 4*5ms for completet update=> only 50Hz) ???

Thank you for any ideas

The pulses are sequential but not the refresh interval. For example, if you have 5 servos set to 1500 microseconds and the default refresh interval of 20,000 microseconds you will get all the pulses out in 7,500 microseconds (7.5 milliseconds) and then a pause of 12,500 microseconds. If the servos are all at 1000 microseconds it will be 5,000 microseconds for the pulses and 15,000 microseconds of pause. If the servos are all all 2000 microseconds you will have 10,000 microseconds of pulse and 10,000 microseconds of pause.

If you set REFRESH_INTERVAL to 1000 the pulses will repeat immediately, giving a refresh interval of 5 to 10 milliseconds (200 to 100 updates per second.

What the code is doing:

static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t *TCNTn, volatile uint16_t* OCRnA)
  if(/* This interrupt signals the end of the REFRESH_INTERVAL */)
    *TCNTn = 0; // Re-start the timer at 0
  else {
    if( /* The interrupt signals the end of pulse on this Channel. If this channel is active (not detached):  */ )  
      digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW); // Turn off the pin for this Channel

  Channel[timer]++;    // increment to the next Channel

  if( /* We have not gone past the list of servos for this timer */) {
    // Set the timeout for this timer to currentTime + pulse length for the new Channel
    if(/* This Channel's pin is active (not detached): */)  
      digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,HIGH); // Turn on the pin for this Channel
  else { 
    // finished all channels so wait for the refresh period to expire before starting over 
    if( /* The current time is less than REFRESH_INTERVAL - 4 */) )  // allow a few ticks to ensure the next OCR1A not missed
      // Set the timeout to REFRESH_INTERVAL;  
      // Set the timeout to four ticks from NOW
    Channel[timer] = -1; // This means the next interrupt signals the end of the REFRESH_INTERVAL

Hi john

Thank you very much for this detailed and clear description.
It works fine with this high refresh rate. I’m able to fly the copter.

I measured the Signal of one servo with REFRESH_INTERVAL = 1. It looks a following: