Servo Library

It was made several changes in Arduino Servo Library to allow it to be used in Lithne Board. The changes will be explained here.

The problem of the library was that it doesn’t recognize AVR XMEGA. So, for timer declaration, the program was entering in the following lines in “Servo.h” file:

#else // everything else
#define _useTimer1
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
#endif
So, the first thing to do was change the timer declaration:
#elif defined(__AVR_XMEGA__)
#define TIMER2 TCD0
#define TIMER2__vect TCD0_CCD_vect
#define TC_SetPeriod( _tc, _period ) ( (_tc)->PER = (_period) )
#define TIMER2_INTERRUPT_DISABLE() TIMER2.INTCTRLB = TC_CCDINTLVL_OFF_gc
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

This declaration was copied from Dmxsimple library, but I change the timer from TCC0 to TCD0.  In the Servo.cpp file several changes were made. You can find them looking for __AVR_XMEGA__ declarations. Basically, what I did was change the timer uses to Xmega datasheet definitions and also changing the interruption definitions. I tried the maximum not to change too much the file, so I’m using the handle_interruption() function also, but changing the registers sent.


Subcategories