NAME

k8055m_set_servor, k8055m_get_servo -- Control and query the pulse width and direction of a digital output port, that is in mode K8055M_DIGITAL_OUT_MODE_SERVO.

LIBRARY

k8055-pic18f access library

SYNOPSIS

#include "k8055m.h"

int
k8055m_set_servo(int cardNumber, int port, float pulseWidth, int pulseHigh);

int
k8055m_get_servo(int cardNumber, int port, float *pulseWidth, int *pulseHigh);
    

DESCRIPTION

While a digital output port is set to K8055M_DIGITAL_OUT_MODE_SERVO, the K8055M will continuously send PWM pulses to the port at a rate of 40 Hz. These pulses are square wave patterns and their shape is controlled with k8055m_set_servo().

When pulseHigh is TRUE (1), the wave pattern will consist of a logical "0" base, with logical "1" pulses at the corresponding PORTB output. Since the K8055M's digital output ports are routed through a darlington transistor array, turning them into open collector outputs, this is not the most desirable wave pattern. pulseHigh = FALSE will produce the exact opposite wave pattern, which will allow for a very simple connection of standard servos with just one pull up resistor per port and the K8055M sharing common ground with the servo power supply.

The pulseWidth is specified as a floating point value in microseconds (µS). Timer3, used in the firmware to measure timed events, is running with a 1:1 prescaler, so the total resolution is 12 MHz. Taking possible interrupt latencies into account, one can expect the pulse width emitted by the PIC to be within +/- 0.5 µS.

WARNING

Sending pulses outside a servo's specification can damage the servo! It is the application developers response to know the specifications of the used servos and limit the used pulse width range in the application accordingly.

Standard servos come in a wide range of different specifications. Most share the requirement that the controller should send pulses at a rate between 30 and 50 Hz and that the servo's center position is at 1500 µS. But many accept a different range of pulse widths. Some only accept 1000 to 2000 µS, while others accept 500 to 2400 µS. The library code therefore only forces the pulse width to be within 400..2600 µS.

RETURN VALUES

k8055m_set_servo() and k8055m_get_servo() return 0 on success, -1 on error. k8055m_get_servo() will leave the current servo settings in *pwmWidth and *pwmHigh on success.