Servo library

I was working on porting the servo library, and well, the code used on it is less than spectacular and rather messy at points. The library seems to allow only pins 9 and 10 for connection given that it seems to use PWM, correct me if I am wrong on that.

The main question I have is on this function:

void Servo::detach()
{
  // muck with timer flags
  if (pin == 9) {
    attached9 = 0;
    TCCR1A = TCCR1A & ~_BV(COM1A0) & ~_BV(COM1A1);
    pinMode(pin, INPUT);
  } 
  
  if (pin == 10) {
    attached10 = 0;
    TCCR1A = TCCR1A & ~_BV(COM1B0) & ~_BV(COM1B1);
    pinMode(pin, INPUT);
  }

  if (!attached9 && !attached10) releaseTimer1();
}

The function always calls releaseTimer1(), the problem is, releaseTimer1() does absolutely nothing! Can somebody explain to me what's going on here? I believe the timer is detached in one of the two previous blocks. So here's the question, why is this necessary?

The new servo library (I believe it’s in the v 17 release), already uses an interrupt driven system (I believe) to address as many servos as desired (on all pins if one desires).

So if you’re doing this for your own learning or use then go ahead, but the official release version is mostly written in stone now, after a painful birth on the developers list. So I’d predict the interest in your code is likely to be nil.

You might go through the developers list and grab that code, to compare with the solutions you come up with, or as a starting point. V-17 is out in a week or so and you can get the new code then too.

List-Archive: http://arduino.cc/pipermail/developers_arduino.cc

Sorry I can’t answer your tech questions on the function, not having gone through all the code.

paulb

I'm really not that interested if my code is used in the default environment or not. That is not why I am porting the library to C at all. Check my first post in these forums for that reason, I'm too lazy to go over all this again.

I'll stop porting the library for now and wait for the new version and port that one instead. Hopefully it is better than the mess it is right now (yuck!). I'll go and take a peek though, thanks for the reply.