Serial Wombat 4A and 4B Firmware
|
Classes | |
struct | servo_n |
Macros | |
#define | servo ((servoPin_t*) CurrentPinRegister) |
Typedefs | |
typedef struct servo_n | servoPin_t |
Functions | |
void | initServoSimple () |
A simple, no-parameter call to initialze the Servo. Used in ASCII pin configuration commands. More... | |
void | initServo (void) |
void | updateServo () |
Periodic call to service the Servo State Machine for a pin. More... | |
#define servo ((servoPin_t*) CurrentPinRegister) |
typedef struct servo_n servoPin_t |
void initServo | ( | void | ) |
\brief Initialization routine for Servo.
Initialize Servo. This command causes the pulse width to default to 500uS to 2500uS.
BYTE 0 | BYTE 1 | BYTE 2 | BYTE 3 | BYTE 4 | BYTE 5 | BYTE 6 | BYTE 7 |
---|---|---|---|---|---|---|---|
0xC0 | Pin To Set | 0x03 (servo mode) | Pin To Set (Required for compatability with SW19) | Position Value Low Byte | Position Value High Byte | 0x00 or 0x01 (Normal or Reverse) | 0x55* |
*0x55 is recommended, but any byte is acceptable
Response:
Command is echoed back.
Examples:
Set pin 2 to Servo, Position 0x4080, no reverse
0xC0 0x02 0x03 0x02 0x80 0x40 0x00 0x55
Set Pulse widths. This command must come after a servo CONFIGURE_CHANNEL_MODE_0 command for the same pin. Units are microseconds
BYTE 0 | BYTE 1 | BYTE 2 | BYTE 3 | BYTE 4 | BYTE 5 | BYTE 6 | BYTE 7 |
---|---|---|---|---|---|---|---|
0xC1 | Pin To Set | 0x03 (servo mode) | Fixed pulse time low byte | Fixed pulse time high byte | Variable pulse time low byte | variable pulse time high byte | 0x55* |
*0x55 is recommended, but any byte is acceptable
Response:
Command is echoed back.
Examples:
Set pin 2 Servo Pulse width to range between 750 and 1750 uS.
Fixed period is 750 = 0x02EE, variable period is (1750 - 750) = 1000 = 0x03E8
0xC1 0x02 0x03 0xEE 0x02 0xE8 0x03 0x55
void initServoSimple | ( | ) |
A simple, no-parameter call to initialze the Servo. Used in ASCII pin configuration commands.
Initializes servo to 500-2500 uS pulse, not reversed.
void updateServo | ( | ) |
Periodic call to service the Servo State Machine for a pin.
This function expects to get called every mS.
On most calls increments inactiveCount and returns.
When inactive count >= 20 and the CCP1 compare register isn't busy (indicated by CCP1SetLowMask == 0xFF) the function sets the output high, sets the CCP1SetLowMask variable to set the pin low when its port is &'d with the CCP1SetLowMask, and calculates a time in the future based on the calculated pulse width + TMR1 reading.
When the interrupt goes off it and's the LAT register with CCP1SetLowMask, setting the value low again.
This algorithm assumes that only one pin is using the CCP1 at a time, which is enforced by the check for CCP1SetLowMask == 0xFF.
pulsetime = fixed time + variableTime * buffer / 65536.