STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
← STM32duino documentation
Loading...
Searching...
No Matches
Servo.h File Reference

Interrupt driven Servo library using 16 bit timers - Version 2. More...

#include "api/Common.h"
#include <inttypes.h>
#include "stm32/ServoTimers.h"

Classes

struct  ServoPin_t
 Pin of a servo channel. More...
 
struct  servo_t
 Servo channel data. More...
 
class  Servo
 Servo motor controller. More...
 

Macros

#define Servo_VERSION   2
 Software version of this library.
 
#define MIN_PULSE_WIDTH   544
 Shortest pulse sent to a servo, in microseconds.
 
#define MAX_PULSE_WIDTH   2400
 Longest pulse sent to a servo, in microseconds.
 
#define DEFAULT_PULSE_WIDTH   1500
 Default pulse width when a servo is attached, in microseconds.
 
#define REFRESH_INTERVAL   20000
 Minimum time to refresh servos, in microseconds.
 
#define SERVOS_PER_TIMER   12
 Maximum number of servos controlled by one timer.
 
#define MAX_SERVOS   (_Nbr_16timers * SERVOS_PER_TIMER)
 Maximum number of servos supported by the available 16 bit timers.
 
#define INVALID_SERVO   255
 Flag indicating an invalid servo index.
 

Detailed Description

Interrupt driven Servo library using 16 bit timers - Version 2.

A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. The servos are pulsed in the background using the value most recently written using the write() method.

Note
analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. The sequence used to seize timers is defined in timers.h

The methods are:

  • Servo: class for manipulating servo motors connected to Arduino pins.
  • attach(pin): attach a servo motor to an i/o pin.
  • attach(pin, min, max): attach to a pin setting min and max values in microseconds, default min is 544, max is 2400.
  • write(): set the servo angle in degrees (an invalid angle that is valid as pulse in microseconds is treated as microseconds).
  • writeMicroseconds(): set the servo pulse width in microseconds.
  • read(): get the last written servo pulse width as an angle between 0 and 180.
  • readMicroseconds(): get the last written servo pulse width in microseconds (was read_us() in first release).
  • attached(): return true if there is a servo attached.
  • detach(): stop an attached servo from pulsing its i/o pin.