Need help with Servo Speeds.

Hi there. I am having a difficult time controlling the servo speeds, I need to be able to control the speeds for a 180 degree movement. I installed VarSpeedServo but I keep getting errors.

Arduino: 1.6.3 (Windows 7), Board: "Arduino Due (Programming Port)"

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:137:8: error: expected constructor, destructor, or type conversion before '(' token

SIGNAL (TIMER1_COMPA_vect)

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In function 'void initISR(timer16_Sequence_t)':

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:185:5: error: 'TCCR1A' was not declared in this scope

TCCR1A = 0; // normal counting mode

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:186:5: error: 'TCCR1B' was not declared in this scope

TCCR1B = _BV(CS11); // set prescaler of 8

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:186:18: error: 'CS11' was not declared in this scope

TCCR1B = _BV(CS11); // set prescaler of 8

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:186:22: error: '_BV' was not declared in this scope

TCCR1B = _BV(CS11); // set prescaler of 8

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:187:5: error: 'TCNT1' was not declared in this scope

TCNT1 = 0; // clear the timer count

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:193:5: error: 'TIFR1' was not declared in this scope

TIFR1 |= _BV(OCF1A); // clear any pending interrupts;

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:193:18: error: 'OCF1A' was not declared in this scope

TIFR1 |= _BV(OCF1A); // clear any pending interrupts;

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:194:5: error: 'TIMSK1' was not declared in this scope

TIMSK1 |= _BV(OCIE1A) ; // enable the output compare interrupt

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:194:20: error: 'OCIE1A' was not declared in this scope

TIMSK1 |= _BV(OCIE1A) ; // enable the output compare interrupt

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::writeMicroseconds(int)':

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:345:23: error: 'SREG' was not declared in this scope

uint8_t oldSREG = SREG;

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:346:9: error: 'cli' was not declared in this scope

cli();

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::slowmove(int, uint8_t)':

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:391:22: error: 'SREG' was not declared in this scope

uint8_t oldSREG = SREG;

^

C:\Users\Eli\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:392:8: error: 'cli' was not declared in this scope

cli();

^

Error compiling.

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.

I have no idea what any of this means. I am using an Arduino DUE with the latest software version of 1.6.3. Any help would be greatly appreciated.

Does the VarSpeedServo library work with the Due ? As a test, set the target board to Uno and try verifying your program.

UKHeliBob: Does the VarSpeedServo library work with the Due ? As a test, set the target board to Uno and try verifying your program.

Yup, just tried with UNO and it verified without a problem. Is there anyway to make it work with DUE? It's the only board that I have.

Is there anyway to make it work with DUE?

From the error messages it looks like it is trying to use registers defined for Atmel chips whilst the Due uses an ARM chip so, unless you are willing to write your own library the answer is no.

However, there are ways of making a servo move slowly using the standard servo library. Move a little, wait a while (using millis() for timing), move a bit more, wait a while and so on.

UKHeliBob: From the error messages it looks like it is trying to use registers defined for Atmel chips whilst the Due uses an ARM chip so, unless you are willing to write your own library the answer is no.

However, there are ways of making a servo move slowly using the standard servo library. Move a little, wait a while (using millis() for timing), move a bit more, wait a while and so on.

I tried using writeMicroseconds(), but it isn't working out exactly. How do I use millis() for a servo?

An example

#include <Servo.h>
Servo aServo;
const byte servoPin = 9;
unsigned long startTime;
unsigned long period = 50;
byte servoPos = 0;

void setup()
{
  Serial.begin(115200);
  aServo.attach(servoPin);
  startTime = millis();
}

void loop()
{
  unsigned long currentTime = millis();
  if (currentTime - startTime >= period)
  {
    servoPos++;
    if (servoPos >= 180)
    {
      servoPos = 0;
    }
    aServo.write(servoPos);
    startTime = currentTime;
  }
  //any code that you want to execute can go here as long as it does not block the free execution of loop()
}