This is a driver to control the SD20 20 Channel I2C to Servo Driver Chip from www.robot-electronics.co.uk (http://www.robot-electronics.co.uk/htm/sd20tech.htm). This driver will allow a servo channel to be started up, stopped and the duty cycle altered in standard mode. No attempt to include the extended mode is included.
SD20.h
- Committer:
- sk398
- Date:
- 2016-01-24
- Revision:
- 0:870a29ad1074
- Child:
- 1:6557cf755742
File content as of revision 0:870a29ad1074:
#ifndef SD20_H #define SD20_H /* SD20 Internal Register Map */ #define SOFTWARE_REVISION_REG 0x00 #define SERVO_1_REG 0x01 #define SERVO_2_REG 0x02 #define SERVO_3_REG 0x03 #define SERVO_4_REG 0x04 #define SERVO_5_REG 0x05 #define SERVO_6_REG 0x06 #define SERVO_7_REG 0x07 #define SERVO_8_REG 0x08 #define SERVO_9_REG 0x09 #define SERVO_10_REG 0x10 #define SERVO_11_REG 0x11 #define SERVO_12_REG 0x12 #define SERVO_13_REG 0x13 #define SERVO_14_REG 0x14 #define SERVO_15_REG 0x15 #define SERVO_16_REG 0x16 #define SERVO_17_REG 0x17 #define SERVO_18_REG 0x18 #define SERVO_19_REG 0x19 #define SERVO_20_REG 0x20 #define STD_ETD_MODE_CTRL 0x21 #define ETD_MODE_OFST_HIGH 0x22 #define ETD_MODE_OFST_LOW 0x23 // Output Buffer Length #define OUT_BUF_LEN 2 #define CHANNEL_STOP 0 #define CHANNEL_START 1 class SD20 { private: int deviceAddress; int BusHz; I2C *_bus; int OutputData(); char OutputBuffer[OUT_BUF_LEN]; public: /** Create a SD20 Constructor, connected over I2C Master connection * * parameter bus: I2C object * parameter BusHz: I2C Bus Frequency */ SD20(I2C *bus,int I2CAddress, int BusHz); /** * Start/Stop PWM output on specificed channel (Standard mode) * * parameter Channel: Servo Channel to be stopped * parameter Start: Select whether to start[1] or stop [0] a given channel * parameter mode: Select whether debug mode[0] and prints result or implementation mode [1] * where print commands are skipped to save operational time */ int StartStopPWM(int Channel, bool Start); /** * Update PWM output on specificed channel (Standard mode) * * parameter DataOutput: Structured as follows: [Servo Channel[1:20], Pulse Width[0x00:0xFF]] * parameter mode: Select whether debug mode[0] and prints result or implementation mode [1] * where print commands are skipped to save operational time */ int UpdatePWM(char *DataOutput); }; #endif