- Don't think anything was changed or updated.... simply viewed the class

Dependents:   Component_Test_Interface

Fork of BridgeDriver by Jason T

Committer:
jason701802
Date:
Thu Jul 03 17:09:29 2014 +0000
Revision:
0:b1e3fa917367
Child:
1:c8e328389a98
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jason701802 0:b1e3fa917367 1 #ifndef BRIDGEDRIVER_H
jason701802 0:b1e3fa917367 2
jason701802 0:b1e3fa917367 3 #include "mbed.h"
jason701802 0:b1e3fa917367 4 #include "MCP23017.h"
jason701802 0:b1e3fa917367 5
jason701802 0:b1e3fa917367 6 #define BRIDGEDRIVER_H
jason701802 0:b1e3fa917367 7
jason701802 0:b1e3fa917367 8 //pin definitions
jason701802 0:b1e3fa917367 9 #define PIN_CH1 P1_18 //hardware PWM1[1]
jason701802 0:b1e3fa917367 10 #define PIN_CH2 P2_0 //hardware PWM1[1]
jason701802 0:b1e3fa917367 11 #define PIN_CH3 P1_20 //hardware PWM1[2]
jason701802 0:b1e3fa917367 12 #define PIN_CH4 P2_1 //hardware PWM1[2]
jason701802 0:b1e3fa917367 13 #define PIN_CH5 P1_21 //hardware PWM1[3]
jason701802 0:b1e3fa917367 14 #define PIN_CH6 P1_23 //hardware PWM1[4]
jason701802 0:b1e3fa917367 15 #define PIN_CH7 P1_24 //hardware PWM1[5]
jason701802 0:b1e3fa917367 16 #define PIN_CH8 P1_26 //hardware PWM1[6]
jason701802 0:b1e3fa917367 17
jason701802 0:b1e3fa917367 18
jason701802 0:b1e3fa917367 19 #define EN_ADDR 0x40 //i2c address of enable pin port expander
jason701802 0:b1e3fa917367 20 #define LED_ADDR 0x4E //i2c address of button and LED port expander
jason701802 0:b1e3fa917367 21
jason701802 0:b1e3fa917367 22
jason701802 0:b1e3fa917367 23 class BridgeDriver{
jason701802 0:b1e3fa917367 24 enum Bridges{ BRIDGE_A,
jason701802 0:b1e3fa917367 25 BRIDGE_B,
jason701802 0:b1e3fa917367 26 BRIDGE_C,
jason701802 0:b1e3fa917367 27 BRIDGE_D
jason701802 0:b1e3fa917367 28 };
jason701802 0:b1e3fa917367 29
jason701802 0:b1e3fa917367 30 public:
jason701802 0:b1e3fa917367 31
jason701802 0:b1e3fa917367 32 BridgeDriver( I2C *i2c, const uint8_t enPwmA = 0, const uint8_t enPwmB = 0, const uint8_t enPwmC = 0, const uint8_t enPwmD = 0, const uint8_t enAddr = EN_ADDR, const uint8_t ledAddr = LED_ADDR);
jason701802 0:b1e3fa917367 33
jason701802 0:b1e3fa917367 34 ~BridgeDriver();
jason701802 0:b1e3fa917367 35
jason701802 0:b1e3fa917367 36 void enablePwm(uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD);
jason701802 0:b1e3fa917367 37 void enablePwm(Bridges bridge, uint8_t enPwm);
jason701802 0:b1e3fa917367 38
jason701802 0:b1e3fa917367 39
jason701802 0:b1e3fa917367 40 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 41 void enableBraking(Bridges bridge, uint8_t enBrake);
jason701802 0:b1e3fa917367 42
jason701802 0:b1e3fa917367 43 int forceBrake(uint8_t ch); //force a specific channel to GND without changing braking default
jason701802 0:b1e3fa917367 44 int forceBrake(Bridges bridge); //force a specific motor to GND without changing braking default
jason701802 0:b1e3fa917367 45 int forceFloat(uint8_t ch); //force a specific channel to float without changing braking default
jason701802 0:b1e3fa917367 46 int forceFloat(Bridges bridge); //force a specific motor to float without changing braking default
jason701802 0:b1e3fa917367 47
jason701802 0:b1e3fa917367 48 int drive(uint8_t state);
jason701802 0:b1e3fa917367 49 int drive(uint8_t ch, uint8_t on);
jason701802 0:b1e3fa917367 50 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 51 float drive(Bridges bridge, int8_t dir, float speed);
jason701802 0:b1e3fa917367 52 //dir: 1=fwd, -1=rev, 0=brake (irregardless of setting of _braking
jason701802 0:b1e3fa917367 53 //speed from 0 to 1, speed of 0 will coast or brake depending on setting of _braking
jason701802 0:b1e3fa917367 54
jason701802 0:b1e3fa917367 55
jason701802 0:b1e3fa917367 56
jason701802 0:b1e3fa917367 57 private:
jason701802 0:b1e3fa917367 58 DigitalOut *_d[8];
jason701802 0:b1e3fa917367 59 PwmOut *_p[8];
jason701802 0:b1e3fa917367 60 MCP23017 *_EnCtl;
jason701802 0:b1e3fa917367 61 MCP23017 *_IO;
jason701802 0:b1e3fa917367 62 I2C *_i2c;
jason701802 0:b1e3fa917367 63 uint8_t _enAddr;
jason701802 0:b1e3fa917367 64 uint8_t _ledAddr;
jason701802 0:b1e3fa917367 65 uint8_t _pwm[4];
jason701802 0:b1e3fa917367 66 int8_t _dir[4]; //dir of 1 means lower # ch is driving, dir of -1 means higher number ch is driving
jason701802 0:b1e3fa917367 67 uint8_t _braking[4];
jason701802 0:b1e3fa917367 68 uint8_t _oldLedState; //for setLed functions. Kept external to overload function
jason701802 0:b1e3fa917367 69
jason701802 0:b1e3fa917367 70 void enableCh(uint8_t ch, uint8_t en);
jason701802 0:b1e3fa917367 71 void setLed(uint8_t ch, uint8_t en);
jason701802 0:b1e3fa917367 72 void setLed(uint8_t state);
jason701802 0:b1e3fa917367 73 void setPwm(uint8_t ch, uint8_t en);
jason701802 0:b1e3fa917367 74
jason701802 0:b1e3fa917367 75
jason701802 0:b1e3fa917367 76
jason701802 0:b1e3fa917367 77 };
jason701802 0:b1e3fa917367 78
jason701802 0:b1e3fa917367 79
jason701802 0:b1e3fa917367 80
jason701802 0:b1e3fa917367 81 #endif