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.
Diff: SD20.h
- Revision:
- 1:6557cf755742
- Parent:
- 0:870a29ad1074
- Child:
- 2:b6789ad2af2b
--- a/SD20.h Sun Jan 24 14:39:33 2016 +0000 +++ b/SD20.h Sun Jan 24 15:10:48 2016 +0000 @@ -1,6 +1,17 @@ #ifndef SD20_H #define SD20_H +/* I2C Parameters*/ + +// SD20 I2C Address +#define SD20_ADDRESS 0xC2 + +// SCL Frequency +#define BUS_FREQ 100000 + +// Output Buffer Length +#define OUT_BUF_LEN 2 + /* SD20 Internal Register Map */ #define SOFTWARE_REVISION_REG 0x00 #define SERVO_1_REG 0x01 @@ -27,31 +38,47 @@ #define ETD_MODE_OFST_HIGH 0x22 #define ETD_MODE_OFST_LOW 0x23 -// Output Buffer Length -#define OUT_BUF_LEN 2 +/* SD20 Channel constants*/ +#define CHANNEL_1 1 +#define CHANNEL_2 2 +#define CHANNEL_3 1 +#define CHANNEL_4 2 +#define CHANNEL_5 1 +#define CHANNEL_6 2 +#define CHANNEL_7 1 +#define CHANNEL_8 2 +#define CHANNEL_9 1 +#define CHANNEL_10 10 +#define CHANNEL_11 11 +#define CHANNEL_12 12 +#define CHANNEL_13 13 +#define CHANNEL_14 14 +#define CHANNEL_15 15 +#define CHANNEL_16 16 +#define CHANNEL_17 17 +#define CHANNEL_18 18 +#define CHANNEL_19 19 +#define CHANNEL_20 20 -#define CHANNEL_STOP 0 -#define CHANNEL_START 1 +#define CHANNEL_STOP 0x00 +#define CHANNEL_START 0x01 + +#define STD_MODE 0x00 + 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); + SD20(I2C *bus); /** * Start/Stop PWM output on specificed channel (Standard mode) @@ -61,7 +88,7 @@ * 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); + int StartStopChannel(uint8_t ServoChannel, bool Start); /** * Update PWM output on specificed channel (Standard mode) @@ -70,8 +97,10 @@ * 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); + int UpdateChannel(char *DataOutput); + + int SetStandardMode(); }; #endif \ No newline at end of file