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@0:870a29ad1074, 2016-01-24 (annotated)
- Committer:
- sk398
- Date:
- Sun Jan 24 14:39:33 2016 +0000
- Revision:
- 0:870a29ad1074
- Child:
- 1:6557cf755742
Working edition. Basic and inefficient however;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sk398 | 0:870a29ad1074 | 1 | #ifndef SD20_H |
sk398 | 0:870a29ad1074 | 2 | #define SD20_H |
sk398 | 0:870a29ad1074 | 3 | |
sk398 | 0:870a29ad1074 | 4 | /* SD20 Internal Register Map */ |
sk398 | 0:870a29ad1074 | 5 | #define SOFTWARE_REVISION_REG 0x00 |
sk398 | 0:870a29ad1074 | 6 | #define SERVO_1_REG 0x01 |
sk398 | 0:870a29ad1074 | 7 | #define SERVO_2_REG 0x02 |
sk398 | 0:870a29ad1074 | 8 | #define SERVO_3_REG 0x03 |
sk398 | 0:870a29ad1074 | 9 | #define SERVO_4_REG 0x04 |
sk398 | 0:870a29ad1074 | 10 | #define SERVO_5_REG 0x05 |
sk398 | 0:870a29ad1074 | 11 | #define SERVO_6_REG 0x06 |
sk398 | 0:870a29ad1074 | 12 | #define SERVO_7_REG 0x07 |
sk398 | 0:870a29ad1074 | 13 | #define SERVO_8_REG 0x08 |
sk398 | 0:870a29ad1074 | 14 | #define SERVO_9_REG 0x09 |
sk398 | 0:870a29ad1074 | 15 | #define SERVO_10_REG 0x10 |
sk398 | 0:870a29ad1074 | 16 | #define SERVO_11_REG 0x11 |
sk398 | 0:870a29ad1074 | 17 | #define SERVO_12_REG 0x12 |
sk398 | 0:870a29ad1074 | 18 | #define SERVO_13_REG 0x13 |
sk398 | 0:870a29ad1074 | 19 | #define SERVO_14_REG 0x14 |
sk398 | 0:870a29ad1074 | 20 | #define SERVO_15_REG 0x15 |
sk398 | 0:870a29ad1074 | 21 | #define SERVO_16_REG 0x16 |
sk398 | 0:870a29ad1074 | 22 | #define SERVO_17_REG 0x17 |
sk398 | 0:870a29ad1074 | 23 | #define SERVO_18_REG 0x18 |
sk398 | 0:870a29ad1074 | 24 | #define SERVO_19_REG 0x19 |
sk398 | 0:870a29ad1074 | 25 | #define SERVO_20_REG 0x20 |
sk398 | 0:870a29ad1074 | 26 | #define STD_ETD_MODE_CTRL 0x21 |
sk398 | 0:870a29ad1074 | 27 | #define ETD_MODE_OFST_HIGH 0x22 |
sk398 | 0:870a29ad1074 | 28 | #define ETD_MODE_OFST_LOW 0x23 |
sk398 | 0:870a29ad1074 | 29 | |
sk398 | 0:870a29ad1074 | 30 | // Output Buffer Length |
sk398 | 0:870a29ad1074 | 31 | #define OUT_BUF_LEN 2 |
sk398 | 0:870a29ad1074 | 32 | |
sk398 | 0:870a29ad1074 | 33 | #define CHANNEL_STOP 0 |
sk398 | 0:870a29ad1074 | 34 | #define CHANNEL_START 1 |
sk398 | 0:870a29ad1074 | 35 | |
sk398 | 0:870a29ad1074 | 36 | class SD20 |
sk398 | 0:870a29ad1074 | 37 | { |
sk398 | 0:870a29ad1074 | 38 | |
sk398 | 0:870a29ad1074 | 39 | private: |
sk398 | 0:870a29ad1074 | 40 | |
sk398 | 0:870a29ad1074 | 41 | int deviceAddress; |
sk398 | 0:870a29ad1074 | 42 | int BusHz; |
sk398 | 0:870a29ad1074 | 43 | I2C *_bus; |
sk398 | 0:870a29ad1074 | 44 | int OutputData(); |
sk398 | 0:870a29ad1074 | 45 | char OutputBuffer[OUT_BUF_LEN]; |
sk398 | 0:870a29ad1074 | 46 | |
sk398 | 0:870a29ad1074 | 47 | public: |
sk398 | 0:870a29ad1074 | 48 | |
sk398 | 0:870a29ad1074 | 49 | /** Create a SD20 Constructor, connected over I2C Master connection |
sk398 | 0:870a29ad1074 | 50 | * |
sk398 | 0:870a29ad1074 | 51 | * parameter bus: I2C object |
sk398 | 0:870a29ad1074 | 52 | * parameter BusHz: I2C Bus Frequency |
sk398 | 0:870a29ad1074 | 53 | */ |
sk398 | 0:870a29ad1074 | 54 | SD20(I2C *bus,int I2CAddress, int BusHz); |
sk398 | 0:870a29ad1074 | 55 | |
sk398 | 0:870a29ad1074 | 56 | /** |
sk398 | 0:870a29ad1074 | 57 | * Start/Stop PWM output on specificed channel (Standard mode) |
sk398 | 0:870a29ad1074 | 58 | * |
sk398 | 0:870a29ad1074 | 59 | * parameter Channel: Servo Channel to be stopped |
sk398 | 0:870a29ad1074 | 60 | * parameter Start: Select whether to start[1] or stop [0] a given channel |
sk398 | 0:870a29ad1074 | 61 | * parameter mode: Select whether debug mode[0] and prints result or implementation mode [1] |
sk398 | 0:870a29ad1074 | 62 | * where print commands are skipped to save operational time |
sk398 | 0:870a29ad1074 | 63 | */ |
sk398 | 0:870a29ad1074 | 64 | int StartStopPWM(int Channel, bool Start); |
sk398 | 0:870a29ad1074 | 65 | |
sk398 | 0:870a29ad1074 | 66 | /** |
sk398 | 0:870a29ad1074 | 67 | * Update PWM output on specificed channel (Standard mode) |
sk398 | 0:870a29ad1074 | 68 | * |
sk398 | 0:870a29ad1074 | 69 | * parameter DataOutput: Structured as follows: [Servo Channel[1:20], Pulse Width[0x00:0xFF]] |
sk398 | 0:870a29ad1074 | 70 | * parameter mode: Select whether debug mode[0] and prints result or implementation mode [1] |
sk398 | 0:870a29ad1074 | 71 | * where print commands are skipped to save operational time |
sk398 | 0:870a29ad1074 | 72 | */ |
sk398 | 0:870a29ad1074 | 73 | int UpdatePWM(char *DataOutput); |
sk398 | 0:870a29ad1074 | 74 | |
sk398 | 0:870a29ad1074 | 75 | }; |
sk398 | 0:870a29ad1074 | 76 | |
sk398 | 0:870a29ad1074 | 77 | #endif |