z ysaito
/
Pro_B2_1ZNR_CrExpB2_MotorCtrl_LPC824MAX
2018.08.06
common.h@1:c3508bfe65b6, 2016-04-14 (annotated)
- Committer:
- sayzyas
- Date:
- Thu Apr 14 10:25:30 2016 +0000
- Revision:
- 1:c3508bfe65b6
- Parent:
- 0:653609b2a5cf
- Child:
- 2:aeff576d5013
2014.04.14
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sayzyas | 0:653609b2a5cf | 1 | /* |
sayzyas | 0:653609b2a5cf | 2 | * mbed LPC824-Max header |
sayzyas | 0:653609b2a5cf | 3 | * |
sayzyas | 0:653609b2a5cf | 4 | */ |
sayzyas | 0:653609b2a5cf | 5 | |
sayzyas | 0:653609b2a5cf | 6 | #define __IIC_COMAMND_SEND__ |
sayzyas | 0:653609b2a5cf | 7 | |
sayzyas | 0:653609b2a5cf | 8 | /* Information */ |
sayzyas | 0:653609b2a5cf | 9 | #define LatestUpDate "2016.03.16" |
sayzyas | 0:653609b2a5cf | 10 | #define ProgramRevision "---" |
sayzyas | 0:653609b2a5cf | 11 | #define Author "zinsor" |
sayzyas | 0:653609b2a5cf | 12 | #define Company "NRst" |
sayzyas | 0:653609b2a5cf | 13 | #define ProgramCode "RVM-X0F0A" |
sayzyas | 0:653609b2a5cf | 14 | |
sayzyas | 0:653609b2a5cf | 15 | #define __DEBUG_L0__ |
sayzyas | 0:653609b2a5cf | 16 | #define __DEBUG_L1__ |
sayzyas | 1:c3508bfe65b6 | 17 | //#define __DEBUG_L2__ |
sayzyas | 1:c3508bfe65b6 | 18 | //#define __DEBUG_L3__ |
sayzyas | 0:653609b2a5cf | 19 | //#define __DEBUG_L4__ |
sayzyas | 1:c3508bfe65b6 | 20 | #define __DEBUG_DSPMCNT__ // Display motor current percentage value |
sayzyas | 0:653609b2a5cf | 21 | |
sayzyas | 0:653609b2a5cf | 22 | #ifdef __DEBUG_L0__ |
sayzyas | 0:653609b2a5cf | 23 | #define DEBUG_PRINT_L0(...) pc.printf(__VA_ARGS__) |
sayzyas | 0:653609b2a5cf | 24 | #else |
sayzyas | 0:653609b2a5cf | 25 | #define DEBUG_PRINT_L0(...) |
sayzyas | 0:653609b2a5cf | 26 | #endif |
sayzyas | 0:653609b2a5cf | 27 | #ifdef __DEBUG_L1__ |
sayzyas | 0:653609b2a5cf | 28 | #define DEBUG_PRINT_L1(...) pc.printf(__VA_ARGS__) |
sayzyas | 0:653609b2a5cf | 29 | #else |
sayzyas | 0:653609b2a5cf | 30 | #define DEBUG_PRINT_L1(...) |
sayzyas | 0:653609b2a5cf | 31 | #endif |
sayzyas | 0:653609b2a5cf | 32 | #ifdef __DEBUG_L2__ |
sayzyas | 0:653609b2a5cf | 33 | #define DEBUG_PRINT_L2(...) pc.printf(__VA_ARGS__) |
sayzyas | 0:653609b2a5cf | 34 | #else |
sayzyas | 0:653609b2a5cf | 35 | #define DEBUG_PRINT_L2(...) |
sayzyas | 0:653609b2a5cf | 36 | #endif |
sayzyas | 0:653609b2a5cf | 37 | #ifdef __DEBUG_L3__ |
sayzyas | 0:653609b2a5cf | 38 | #define DEBUG_PRINT_L3(...) pc.printf(__VA_ARGS__) |
sayzyas | 0:653609b2a5cf | 39 | #else |
sayzyas | 0:653609b2a5cf | 40 | #define DEBUG_PRINT_L3(...) |
sayzyas | 0:653609b2a5cf | 41 | #endif |
sayzyas | 0:653609b2a5cf | 42 | #ifdef __DEBUG_L4__ |
sayzyas | 0:653609b2a5cf | 43 | #define DEBUG_PRINT_L4(...) pc.printf(__VA_ARGS__) |
sayzyas | 0:653609b2a5cf | 44 | #else |
sayzyas | 0:653609b2a5cf | 45 | #define DEBUG_PRINT_L4(...) |
sayzyas | 0:653609b2a5cf | 46 | #endif |
sayzyas | 1:c3508bfe65b6 | 47 | #ifdef __DEBUG_DSPMCNT__ |
sayzyas | 1:c3508bfe65b6 | 48 | #define DEBUG_DSPMCNT(...) pc.printf(__VA_ARGS__) |
sayzyas | 1:c3508bfe65b6 | 49 | #else |
sayzyas | 1:c3508bfe65b6 | 50 | #define DEBUG_DSPMCNT(...) |
sayzyas | 1:c3508bfe65b6 | 51 | #endif |
sayzyas | 0:653609b2a5cf | 52 | |
sayzyas | 0:653609b2a5cf | 53 | /* Motor Controller I2C address definition */ |
sayzyas | 0:653609b2a5cf | 54 | #define I2C_ADDRESS_HANDY 0x20 |
sayzyas | 0:653609b2a5cf | 55 | #define I2C_ADDRESS_WINCH 0x10 |
sayzyas | 0:653609b2a5cf | 56 | #define I2C_ADDRESS_TRANSFORM 0x08 |
sayzyas | 0:653609b2a5cf | 57 | #define I2C_ADDRESS_CRAWLER 0x04 |
sayzyas | 0:653609b2a5cf | 58 | #define I2C_ADDRESS_RESOLVER 0x02 |
sayzyas | 0:653609b2a5cf | 59 | |
sayzyas | 0:653609b2a5cf | 60 | |
sayzyas | 0:653609b2a5cf | 61 | /* Command definition */ |
sayzyas | 0:653609b2a5cf | 62 | //#define I2C_TFM_RF_K '6' |
sayzyas | 0:653609b2a5cf | 63 | //#define I2C_TFM_RF_I '8' |
sayzyas | 0:653609b2a5cf | 64 | //#define I2C_TFM_LB_K '7' |
sayzyas | 0:653609b2a5cf | 65 | //#define I2C_TFM_LB_I '5' |
sayzyas | 0:653609b2a5cf | 66 | //#define I2C_TFM_PAN_CW '2' |
sayzyas | 0:653609b2a5cf | 67 | //#define I2C_TFM_PAN_CCW '4' |
sayzyas | 0:653609b2a5cf | 68 | //#define I2C_TFM_TILT_UP '1' |
sayzyas | 0:653609b2a5cf | 69 | //#define I2C_TFM_TILT_DWN '3' |
sayzyas | 0:653609b2a5cf | 70 | |
sayzyas | 0:653609b2a5cf | 71 | /* Command definition */ |
sayzyas | 0:653609b2a5cf | 72 | #define MOTOR_1 '1' |
sayzyas | 0:653609b2a5cf | 73 | #define MOTOR_2 '2' |
sayzyas | 0:653609b2a5cf | 74 | |
sayzyas | 0:653609b2a5cf | 75 | #define MOTOR_FWD 'F' /* Forward Rotation */ |
sayzyas | 0:653609b2a5cf | 76 | #define MOTOR_RVS 'R' /* Reverse Rotation */ |
sayzyas | 0:653609b2a5cf | 77 | #define MOTOR_STP 'S' /* Stop */ |
sayzyas | 0:653609b2a5cf | 78 | |
sayzyas | 0:653609b2a5cf | 79 | #define HELLO_PACKET 'A' |
sayzyas | 0:653609b2a5cf | 80 | #define READ_MCURRENT_PACKET 'C' |
sayzyas | 0:653609b2a5cf | 81 | |
sayzyas | 0:653609b2a5cf | 82 | |
sayzyas | 0:653609b2a5cf | 83 | #define MOTOR_ON '0' |
sayzyas | 0:653609b2a5cf | 84 | #define MOTOR_OFF '1' |
sayzyas | 0:653609b2a5cf | 85 | |
sayzyas | 0:653609b2a5cf | 86 | #define LED_ON 0 |
sayzyas | 0:653609b2a5cf | 87 | #define LED_OFF 1 |
sayzyas | 0:653609b2a5cf | 88 | |
sayzyas | 0:653609b2a5cf | 89 | #define FLG_MOTOR1 1 |
sayzyas | 0:653609b2a5cf | 90 | #define FLG_MOTOR2 2 |
sayzyas | 0:653609b2a5cf | 91 | #define FLG_MOTOR_ON 1 |
sayzyas | 0:653609b2a5cf | 92 | #define FLG_MOTOR_OFF 0 |
sayzyas | 0:653609b2a5cf | 93 | |
sayzyas | 0:653609b2a5cf | 94 | enum { |
sayzyas | 0:653609b2a5cf | 95 | FLG_MOTOR_DIR_FWD, |
sayzyas | 0:653609b2a5cf | 96 | FLG_MOTOR_DIR_RVS, |
sayzyas | 0:653609b2a5cf | 97 | FLG_MOTOR_DIR_NONE |
sayzyas | 0:653609b2a5cf | 98 | }; |
sayzyas | 0:653609b2a5cf | 99 | |
sayzyas | 1:c3508bfe65b6 | 100 | /* I2C Command packet to motor controller */ |
sayzyas | 1:c3508bfe65b6 | 101 | /* For motor controller */ |
sayzyas | 1:c3508bfe65b6 | 102 | enum{ |
sayzyas | 1:c3508bfe65b6 | 103 | I2C_CP_PREAMBLE, // Preamble of command packet |
sayzyas | 1:c3508bfe65b6 | 104 | I2C_CP_COMMAND, // instruction command |
sayzyas | 1:c3508bfe65b6 | 105 | I2C_CP_M1_DIR, // motor1 rotation direction |
sayzyas | 1:c3508bfe65b6 | 106 | I2C_CP_M1_SPEED, // motor1 rotation speed |
sayzyas | 1:c3508bfe65b6 | 107 | I2C_CP_M1_FWD_CNTTH_U, // motor1 current limit detection threshold upper byte |
sayzyas | 1:c3508bfe65b6 | 108 | I2C_CP_M1_FWD_CNTTH_L, // motor1 current limit detection threshold lower byte |
sayzyas | 1:c3508bfe65b6 | 109 | I2C_CP_M1_RVS_CNTTH_U, // motor1 current limit detection threshold upper byte |
sayzyas | 1:c3508bfe65b6 | 110 | I2C_CP_M1_RVS_CNTTH_L, // motor1 current limit detection threshold lower byte |
sayzyas | 1:c3508bfe65b6 | 111 | I2C_CP_M2_DIR, // motor2 rotation direction |
sayzyas | 1:c3508bfe65b6 | 112 | I2C_CP_M2_SPEED, // motor2 rotation speed |
sayzyas | 1:c3508bfe65b6 | 113 | I2C_CP_M2_FWD_CNTTH_U, // motor2 current limit detection threshold upper byte |
sayzyas | 1:c3508bfe65b6 | 114 | I2C_CP_M2_FWD_CNTTH_L, // motor2 current limit detection threshold lower byte |
sayzyas | 1:c3508bfe65b6 | 115 | I2C_CP_M2_RVS_CNTTH_U, // motor2 current limit detection threshold upper byte |
sayzyas | 1:c3508bfe65b6 | 116 | I2C_CP_M2_RVS_CNTTH_L, // motor2 current limit detection threshold lower byte |
sayzyas | 1:c3508bfe65b6 | 117 | }; |
sayzyas | 0:653609b2a5cf | 118 | |
sayzyas | 0:653609b2a5cf | 119 | #define MC_UPPER_LIMIT 95.0f |
sayzyas | 0:653609b2a5cf | 120 | #define MC_LOWER_LIMIT 5.0f |
sayzyas | 0:653609b2a5cf | 121 | #define MC_LOCK_COUNT 5 |
sayzyas | 0:653609b2a5cf | 122 | |
sayzyas | 0:653609b2a5cf | 123 | #define NumberOfPcCommand 11 |
sayzyas | 1:c3508bfe65b6 | 124 | #define NumberOfI2CCommand 14 |
sayzyas | 0:653609b2a5cf | 125 | |
sayzyas | 0:653609b2a5cf | 126 | #define ROTATE_PER_RESOLUTION 24 |