- Don't think anything was changed or updated.... simply viewed the class
Dependents: Component_Test_Interface
Fork of BridgeDriver by
BridgeDriver.h@8:36e2cd31ccf3, 2014-07-28 (annotated)
- Committer:
- jason701802
- Date:
- Mon Jul 28 18:17:29 2014 +0000
- Revision:
- 8:36e2cd31ccf3
- Parent:
- 7:7dabd934ebe4
- Child:
- 9:00e8b7afb2c7
Changed default PWM period to 0.2ms (5kHz) and added function to change PWM period.
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 | 8:36e2cd31ccf3 | 9 | #define DEFAULT_PWM_PERIOD 0.0002 |
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 | 7:7dabd934ebe4 | 30 | enum Motors{ MOTOR_A, |
jason701802 | 7:7dabd934ebe4 | 31 | MOTOR_B, |
jason701802 | 7:7dabd934ebe4 | 32 | MOTOR_C, |
jason701802 | 7:7dabd934ebe4 | 33 | MOTOR_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 | 7:7dabd934ebe4 | 42 | void enablePwm(Motors motor, 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 | 7:7dabd934ebe4 | 46 | void enableBraking(Motors motor, 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 | 7:7dabd934ebe4 | 49 | int forceBrake(Motors motor); //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 | 7:7dabd934ebe4 | 51 | int forceFloat(Motors motor); //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 | 7:7dabd934ebe4 | 55 | float drive(Motors motor, float speed); //speed from -1 to 1, speed of 0 will coast or brake depending on setting of _braking |
jason701802 | 7:7dabd934ebe4 | 56 | float drive(Motors motor, 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 | 8:36e2cd31ccf3 | 61 | void setPWMperiod(float newPWMperiod); |
jason701802 | 0:b1e3fa917367 | 62 | |
jason701802 | 0:b1e3fa917367 | 63 | |
jason701802 | 0:b1e3fa917367 | 64 | |
jason701802 | 0:b1e3fa917367 | 65 | private: |
jason701802 | 0:b1e3fa917367 | 66 | DigitalOut *_d[8]; |
jason701802 | 0:b1e3fa917367 | 67 | PwmOut *_p[8]; |
jason701802 | 0:b1e3fa917367 | 68 | MCP23017 *_EnCtl; |
jason701802 | 0:b1e3fa917367 | 69 | MCP23017 *_IO; |
jason701802 | 0:b1e3fa917367 | 70 | I2C *_i2c; |
jason701802 | 0:b1e3fa917367 | 71 | uint8_t _enAddr; |
jason701802 | 0:b1e3fa917367 | 72 | uint8_t _ledAddr; |
jason701802 | 1:c8e328389a98 | 73 | uint8_t _pwm[4]; //enabled full bridges |
jason701802 | 1:c8e328389a98 | 74 | uint8_t _pwmCh; //currently actie PWM pins |
jason701802 | 1:c8e328389a98 | 75 | int8_t _dir[4]; //dir of 1 means lower # ch is driving, dir of -1 means higher number ch is driving |
jason701802 | 0:b1e3fa917367 | 76 | uint8_t _braking[4]; |
jason701802 | 1:c8e328389a98 | 77 | uint8_t _oldLedState; //for setLed functions. Kept external to overload function |
jason701802 | 8:36e2cd31ccf3 | 78 | float _PWMperiod; |
jason701802 | 0:b1e3fa917367 | 79 | |
jason701802 | 0:b1e3fa917367 | 80 | void enableCh(uint8_t ch, uint8_t en); |
jason701802 | 0:b1e3fa917367 | 81 | void setLed(uint8_t ch, uint8_t en); |
jason701802 | 0:b1e3fa917367 | 82 | void setLed(uint8_t state); |
jason701802 | 0:b1e3fa917367 | 83 | void setPwm(uint8_t ch, uint8_t en); |
jason701802 | 0:b1e3fa917367 | 84 | |
jason701802 | 0:b1e3fa917367 | 85 | |
jason701802 | 0:b1e3fa917367 | 86 | |
jason701802 | 0:b1e3fa917367 | 87 | }; |
jason701802 | 0:b1e3fa917367 | 88 | |
jason701802 | 0:b1e3fa917367 | 89 | |
jason701802 | 0:b1e3fa917367 | 90 | |
jason701802 | 0:b1e3fa917367 | 91 | #endif |