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.

Committer:
sk398
Date:
Sun Jan 24 15:10:48 2016 +0000
Revision:
1:6557cf755742
Parent:
0:870a29ad1074
Child:
2:b6789ad2af2b
StandardMode method added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sk398 0:870a29ad1074 1 #ifndef SD20_H
sk398 0:870a29ad1074 2 #define SD20_H
sk398 0:870a29ad1074 3
sk398 1:6557cf755742 4 /* I2C Parameters*/
sk398 1:6557cf755742 5
sk398 1:6557cf755742 6 // SD20 I2C Address
sk398 1:6557cf755742 7 #define SD20_ADDRESS 0xC2
sk398 1:6557cf755742 8
sk398 1:6557cf755742 9 // SCL Frequency
sk398 1:6557cf755742 10 #define BUS_FREQ 100000
sk398 1:6557cf755742 11
sk398 1:6557cf755742 12 // Output Buffer Length
sk398 1:6557cf755742 13 #define OUT_BUF_LEN 2
sk398 1:6557cf755742 14
sk398 0:870a29ad1074 15 /* SD20 Internal Register Map */
sk398 0:870a29ad1074 16 #define SOFTWARE_REVISION_REG 0x00
sk398 0:870a29ad1074 17 #define SERVO_1_REG 0x01
sk398 0:870a29ad1074 18 #define SERVO_2_REG 0x02
sk398 0:870a29ad1074 19 #define SERVO_3_REG 0x03
sk398 0:870a29ad1074 20 #define SERVO_4_REG 0x04
sk398 0:870a29ad1074 21 #define SERVO_5_REG 0x05
sk398 0:870a29ad1074 22 #define SERVO_6_REG 0x06
sk398 0:870a29ad1074 23 #define SERVO_7_REG 0x07
sk398 0:870a29ad1074 24 #define SERVO_8_REG 0x08
sk398 0:870a29ad1074 25 #define SERVO_9_REG 0x09
sk398 0:870a29ad1074 26 #define SERVO_10_REG 0x10
sk398 0:870a29ad1074 27 #define SERVO_11_REG 0x11
sk398 0:870a29ad1074 28 #define SERVO_12_REG 0x12
sk398 0:870a29ad1074 29 #define SERVO_13_REG 0x13
sk398 0:870a29ad1074 30 #define SERVO_14_REG 0x14
sk398 0:870a29ad1074 31 #define SERVO_15_REG 0x15
sk398 0:870a29ad1074 32 #define SERVO_16_REG 0x16
sk398 0:870a29ad1074 33 #define SERVO_17_REG 0x17
sk398 0:870a29ad1074 34 #define SERVO_18_REG 0x18
sk398 0:870a29ad1074 35 #define SERVO_19_REG 0x19
sk398 0:870a29ad1074 36 #define SERVO_20_REG 0x20
sk398 0:870a29ad1074 37 #define STD_ETD_MODE_CTRL 0x21
sk398 0:870a29ad1074 38 #define ETD_MODE_OFST_HIGH 0x22
sk398 0:870a29ad1074 39 #define ETD_MODE_OFST_LOW 0x23
sk398 0:870a29ad1074 40
sk398 1:6557cf755742 41 /* SD20 Channel constants*/
sk398 1:6557cf755742 42 #define CHANNEL_1 1
sk398 1:6557cf755742 43 #define CHANNEL_2 2
sk398 1:6557cf755742 44 #define CHANNEL_3 1
sk398 1:6557cf755742 45 #define CHANNEL_4 2
sk398 1:6557cf755742 46 #define CHANNEL_5 1
sk398 1:6557cf755742 47 #define CHANNEL_6 2
sk398 1:6557cf755742 48 #define CHANNEL_7 1
sk398 1:6557cf755742 49 #define CHANNEL_8 2
sk398 1:6557cf755742 50 #define CHANNEL_9 1
sk398 1:6557cf755742 51 #define CHANNEL_10 10
sk398 1:6557cf755742 52 #define CHANNEL_11 11
sk398 1:6557cf755742 53 #define CHANNEL_12 12
sk398 1:6557cf755742 54 #define CHANNEL_13 13
sk398 1:6557cf755742 55 #define CHANNEL_14 14
sk398 1:6557cf755742 56 #define CHANNEL_15 15
sk398 1:6557cf755742 57 #define CHANNEL_16 16
sk398 1:6557cf755742 58 #define CHANNEL_17 17
sk398 1:6557cf755742 59 #define CHANNEL_18 18
sk398 1:6557cf755742 60 #define CHANNEL_19 19
sk398 1:6557cf755742 61 #define CHANNEL_20 20
sk398 0:870a29ad1074 62
sk398 1:6557cf755742 63 #define CHANNEL_STOP 0x00
sk398 1:6557cf755742 64 #define CHANNEL_START 0x01
sk398 1:6557cf755742 65
sk398 1:6557cf755742 66 #define STD_MODE 0x00
sk398 1:6557cf755742 67
sk398 0:870a29ad1074 68
sk398 0:870a29ad1074 69 class SD20
sk398 0:870a29ad1074 70 {
sk398 0:870a29ad1074 71
sk398 0:870a29ad1074 72 private:
sk398 0:870a29ad1074 73 I2C *_bus;
sk398 0:870a29ad1074 74
sk398 0:870a29ad1074 75 public:
sk398 0:870a29ad1074 76
sk398 0:870a29ad1074 77 /** Create a SD20 Constructor, connected over I2C Master connection
sk398 0:870a29ad1074 78 *
sk398 0:870a29ad1074 79 * parameter bus: I2C object
sk398 0:870a29ad1074 80 */
sk398 1:6557cf755742 81 SD20(I2C *bus);
sk398 0:870a29ad1074 82
sk398 0:870a29ad1074 83 /**
sk398 0:870a29ad1074 84 * Start/Stop PWM output on specificed channel (Standard mode)
sk398 0:870a29ad1074 85 *
sk398 0:870a29ad1074 86 * parameter Channel: Servo Channel to be stopped
sk398 0:870a29ad1074 87 * parameter Start: Select whether to start[1] or stop [0] a given channel
sk398 0:870a29ad1074 88 * parameter mode: Select whether debug mode[0] and prints result or implementation mode [1]
sk398 0:870a29ad1074 89 * where print commands are skipped to save operational time
sk398 0:870a29ad1074 90 */
sk398 1:6557cf755742 91 int StartStopChannel(uint8_t ServoChannel, bool Start);
sk398 0:870a29ad1074 92
sk398 0:870a29ad1074 93 /**
sk398 0:870a29ad1074 94 * Update PWM output on specificed channel (Standard mode)
sk398 0:870a29ad1074 95 *
sk398 0:870a29ad1074 96 * parameter DataOutput: Structured as follows: [Servo Channel[1:20], Pulse Width[0x00:0xFF]]
sk398 0:870a29ad1074 97 * parameter mode: Select whether debug mode[0] and prints result or implementation mode [1]
sk398 0:870a29ad1074 98 * where print commands are skipped to save operational time
sk398 0:870a29ad1074 99 */
sk398 1:6557cf755742 100 int UpdateChannel(char *DataOutput);
sk398 0:870a29ad1074 101
sk398 1:6557cf755742 102
sk398 1:6557cf755742 103 int SetStandardMode();
sk398 0:870a29ad1074 104 };
sk398 0:870a29ad1074 105
sk398 0:870a29ad1074 106 #endif