- Don't think anything was changed or updated.... simply viewed the class
Dependents: Component_Test_Interface
Fork of BridgeDriver by
BridgeDriver.h@5:c1f32ce026f6, 2014-07-24 (annotated)
- Committer:
- jason701802
- Date:
- Thu Jul 24 17:34:23 2014 +0000
- Revision:
- 5:c1f32ce026f6
- Parent:
- 4:87768972db3f
- Child:
- 7:7dabd934ebe4
moved #define
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jason701802 | 0:b1e3fa917367 | 1 | #include "mbed.h" |
jason701802 | 0:b1e3fa917367 | 2 | #include "MCP23017.h" |
jason701802 | 1:c8e328389a98 | 3 | #include "TextLCD.h" //if using diagnostic |
jason701802 | 0:b1e3fa917367 | 4 | |
jason701802 | 5:c1f32ce026f6 | 5 | #ifndef BRIDGEDRIVER_H |
jason701802 | 0:b1e3fa917367 | 6 | #define BRIDGEDRIVER_H |
jason701802 | 0:b1e3fa917367 | 7 | |
jason701802 | 4:87768972db3f | 8 | |
jason701802 | 4:87768972db3f | 9 | #define PWM_PERIOD 0.001 |
jason701802 | 4:87768972db3f | 10 | |
jason701802 | 0:b1e3fa917367 | 11 | //pin definitions |
jason701802 | 0:b1e3fa917367 | 12 | #define PIN_CH1 P1_18 //hardware PWM1[1] |
jason701802 | 0:b1e3fa917367 | 13 | #define PIN_CH2 P2_0 //hardware PWM1[1] |
jason701802 | 0:b1e3fa917367 | 14 | #define PIN_CH3 P1_20 //hardware PWM1[2] |
jason701802 | 0:b1e3fa917367 | 15 | #define PIN_CH4 P2_1 //hardware PWM1[2] |
jason701802 | 0:b1e3fa917367 | 16 | #define PIN_CH5 P1_21 //hardware PWM1[3] |
jason701802 | 0:b1e3fa917367 | 17 | #define PIN_CH6 P1_23 //hardware PWM1[4] |
jason701802 | 0:b1e3fa917367 | 18 | #define PIN_CH7 P1_24 //hardware PWM1[5] |
jason701802 | 0:b1e3fa917367 | 19 | #define PIN_CH8 P1_26 //hardware PWM1[6] |
jason701802 | 0:b1e3fa917367 | 20 | |
jason701802 | 0:b1e3fa917367 | 21 | |
jason701802 | 0:b1e3fa917367 | 22 | #define EN_ADDR 0x40 //i2c address of enable pin port expander |
jason701802 | 0:b1e3fa917367 | 23 | #define LED_ADDR 0x4E //i2c address of button and LED port expander |
jason701802 | 0:b1e3fa917367 | 24 | |
jason701802 | 0:b1e3fa917367 | 25 | |
jason701802 | 0:b1e3fa917367 | 26 | class BridgeDriver{ |
jason701802 | 1:c8e328389a98 | 27 | |
jason701802 | 1:c8e328389a98 | 28 | |
jason701802 | 1:c8e328389a98 | 29 | public: |
jason701802 | 1:c8e328389a98 | 30 | enum Bridges{ BRIDGE_A, |
jason701802 | 0:b1e3fa917367 | 31 | BRIDGE_B, |
jason701802 | 0:b1e3fa917367 | 32 | BRIDGE_C, |
jason701802 | 0:b1e3fa917367 | 33 | BRIDGE_D |
jason701802 | 1:c8e328389a98 | 34 | }; |
jason701802 | 1:c8e328389a98 | 35 | |
jason701802 | 1:c8e328389a98 | 36 | |
jason701802 | 1:c8e328389a98 | 37 | BridgeDriver( I2C *i2c, uint8_t enPwmA = 0, uint8_t enPwmB = 0, uint8_t enPwmC = 0, uint8_t enPwmD = 0, uint8_t enAddr = EN_ADDR, uint8_t ledAddr = LED_ADDR); |
jason701802 | 0:b1e3fa917367 | 38 | |
jason701802 | 0:b1e3fa917367 | 39 | ~BridgeDriver(); |
jason701802 | 0:b1e3fa917367 | 40 | |
jason701802 | 0:b1e3fa917367 | 41 | void enablePwm(uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD); |
jason701802 | 0:b1e3fa917367 | 42 | void enablePwm(Bridges bridge, uint8_t enPwm); |
jason701802 | 0:b1e3fa917367 | 43 | |
jason701802 | 0:b1e3fa917367 | 44 | |
jason701802 | 0:b1e3fa917367 | 45 | void enableBraking(uint8_t enBrakeA, uint8_t enBrakeB, uint8_t enBrakeC, uint8_t enBrakeD); //1 - drives output to GND when off; 0 - floats output when off |
jason701802 | 0:b1e3fa917367 | 46 | void enableBraking(Bridges bridge, uint8_t enBrake); |
jason701802 | 0:b1e3fa917367 | 47 | |
jason701802 | 0:b1e3fa917367 | 48 | int forceBrake(uint8_t ch); //force a specific channel to GND without changing braking default |
jason701802 | 0:b1e3fa917367 | 49 | int forceBrake(Bridges bridge); //force a specific motor to GND without changing braking default |
jason701802 | 0:b1e3fa917367 | 50 | int forceFloat(uint8_t ch); //force a specific channel to float without changing braking default |
jason701802 | 0:b1e3fa917367 | 51 | int forceFloat(Bridges bridge); //force a specific motor to float without changing braking default |
jason701802 | 0:b1e3fa917367 | 52 | |
jason701802 | 0:b1e3fa917367 | 53 | int drive(uint8_t state); |
jason701802 | 0:b1e3fa917367 | 54 | int drive(uint8_t ch, uint8_t on); |
jason701802 | 0:b1e3fa917367 | 55 | float drive(Bridges bridge, float speed); //speed from -1 to 1, speed of 0 will coast or brake depending on setting of _braking |
jason701802 | 0:b1e3fa917367 | 56 | float drive(Bridges bridge, int8_t dir, float speed); |
jason701802 | 0:b1e3fa917367 | 57 | //dir: 1=fwd, -1=rev, 0=brake (irregardless of setting of _braking |
jason701802 | 0:b1e3fa917367 | 58 | //speed from 0 to 1, speed of 0 will coast or brake depending on setting of _braking |
jason701802 | 1:c8e328389a98 | 59 | |
jason701802 | 1:c8e328389a98 | 60 | void diagnostic(TextLCD_I2C *lcd); |
jason701802 | 0:b1e3fa917367 | 61 | |
jason701802 | 0:b1e3fa917367 | 62 | |
jason701802 | 0:b1e3fa917367 | 63 | |
jason701802 | 0:b1e3fa917367 | 64 | private: |
jason701802 | 0:b1e3fa917367 | 65 | DigitalOut *_d[8]; |
jason701802 | 0:b1e3fa917367 | 66 | PwmOut *_p[8]; |
jason701802 | 0:b1e3fa917367 | 67 | MCP23017 *_EnCtl; |
jason701802 | 0:b1e3fa917367 | 68 | MCP23017 *_IO; |
jason701802 | 0:b1e3fa917367 | 69 | I2C *_i2c; |
jason701802 | 0:b1e3fa917367 | 70 | uint8_t _enAddr; |
jason701802 | 0:b1e3fa917367 | 71 | uint8_t _ledAddr; |
jason701802 | 1:c8e328389a98 | 72 | uint8_t _pwm[4]; //enabled full bridges |
jason701802 | 1:c8e328389a98 | 73 | uint8_t _pwmCh; //currently actie PWM pins |
jason701802 | 1:c8e328389a98 | 74 | int8_t _dir[4]; //dir of 1 means lower # ch is driving, dir of -1 means higher number ch is driving |
jason701802 | 0:b1e3fa917367 | 75 | uint8_t _braking[4]; |
jason701802 | 1:c8e328389a98 | 76 | uint8_t _oldLedState; //for setLed functions. Kept external to overload function |
jason701802 | 0:b1e3fa917367 | 77 | |
jason701802 | 0:b1e3fa917367 | 78 | void enableCh(uint8_t ch, uint8_t en); |
jason701802 | 0:b1e3fa917367 | 79 | void setLed(uint8_t ch, uint8_t en); |
jason701802 | 0:b1e3fa917367 | 80 | void setLed(uint8_t state); |
jason701802 | 0:b1e3fa917367 | 81 | void setPwm(uint8_t ch, uint8_t en); |
jason701802 | 0:b1e3fa917367 | 82 | |
jason701802 | 0:b1e3fa917367 | 83 | |
jason701802 | 0:b1e3fa917367 | 84 | |
jason701802 | 0:b1e3fa917367 | 85 | }; |
jason701802 | 0:b1e3fa917367 | 86 | |
jason701802 | 0:b1e3fa917367 | 87 | |
jason701802 | 0:b1e3fa917367 | 88 | |
jason701802 | 0:b1e3fa917367 | 89 | #endif |