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 Feb 21 23:19:27 2016 +0000
Revision:
2:b6789ad2af2b
Parent:
1:6557cf755742
Child:
6:973d6a66dbf7
Beginning commenting

Who changed what in which revision?

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