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.cpp@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 | #include "mbed.h" |
sk398 | 0:870a29ad1074 | 2 | #include "SD20.h" |
sk398 | 0:870a29ad1074 | 3 | |
sk398 | 0:870a29ad1074 | 4 | SD20::SD20(I2C *bus,int I2CAddress, int BusHz) |
sk398 | 0:870a29ad1074 | 5 | { |
sk398 | 0:870a29ad1074 | 6 | _bus = bus; |
sk398 | 0:870a29ad1074 | 7 | deviceAddress = I2CAddress; |
sk398 | 0:870a29ad1074 | 8 | BusHz = BusHz; |
sk398 | 0:870a29ad1074 | 9 | _bus -> frequency(BusHz); |
sk398 | 0:870a29ad1074 | 10 | } |
sk398 | 0:870a29ad1074 | 11 | |
sk398 | 0:870a29ad1074 | 12 | int SD20::UpdatePWM(char *DataOutput) |
sk398 | 0:870a29ad1074 | 13 | { |
sk398 | 0:870a29ad1074 | 14 | if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN)) |
sk398 | 0:870a29ad1074 | 15 | { |
sk398 | 0:870a29ad1074 | 16 | printf("I2C Failed to write\r\n"); |
sk398 | 0:870a29ad1074 | 17 | return 1; |
sk398 | 0:870a29ad1074 | 18 | } |
sk398 | 0:870a29ad1074 | 19 | else |
sk398 | 0:870a29ad1074 | 20 | { |
sk398 | 0:870a29ad1074 | 21 | printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput); |
sk398 | 0:870a29ad1074 | 22 | return 0; |
sk398 | 0:870a29ad1074 | 23 | } |
sk398 | 0:870a29ad1074 | 24 | } |
sk398 | 0:870a29ad1074 | 25 | |
sk398 | 0:870a29ad1074 | 26 | int SD20::StartStopPWM(int Channel,bool Start) |
sk398 | 0:870a29ad1074 | 27 | { |
sk398 | 0:870a29ad1074 | 28 | if(Start == CHANNEL_START) |
sk398 | 0:870a29ad1074 | 29 | { |
sk398 | 0:870a29ad1074 | 30 | int DataOutput[] = {Channel,0x01}; |
sk398 | 0:870a29ad1074 | 31 | if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN)) |
sk398 | 0:870a29ad1074 | 32 | { |
sk398 | 0:870a29ad1074 | 33 | printf("I2C Failed to write\r\n"); |
sk398 | 0:870a29ad1074 | 34 | return 1; |
sk398 | 0:870a29ad1074 | 35 | } |
sk398 | 0:870a29ad1074 | 36 | else |
sk398 | 0:870a29ad1074 | 37 | { |
sk398 | 0:870a29ad1074 | 38 | printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput); |
sk398 | 0:870a29ad1074 | 39 | return 0; |
sk398 | 0:870a29ad1074 | 40 | } |
sk398 | 0:870a29ad1074 | 41 | } |
sk398 | 0:870a29ad1074 | 42 | else |
sk398 | 0:870a29ad1074 | 43 | { |
sk398 | 0:870a29ad1074 | 44 | int DataOutput[] = {Channel,0x00}; |
sk398 | 0:870a29ad1074 | 45 | if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN)) |
sk398 | 0:870a29ad1074 | 46 | { |
sk398 | 0:870a29ad1074 | 47 | printf("I2C Failed to write\r\n"); |
sk398 | 0:870a29ad1074 | 48 | return 1; |
sk398 | 0:870a29ad1074 | 49 | } |
sk398 | 0:870a29ad1074 | 50 | else |
sk398 | 0:870a29ad1074 | 51 | { |
sk398 | 0:870a29ad1074 | 52 | printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput); |
sk398 | 0:870a29ad1074 | 53 | return 0; |
sk398 | 0:870a29ad1074 | 54 | } |
sk398 | 0:870a29ad1074 | 55 | } |
sk398 | 0:870a29ad1074 | 56 | } |
sk398 | 0:870a29ad1074 | 57 |