- 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:
Mon Jul 21 19:03:42 2014 +0000
Revision:
4:87768972db3f
Parent:
1:c8e328389a98
Child:
5:c1f32ce026f6
Cleaned up ordering of enabling/disabling and setting output for each channel

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 1:c8e328389a98 5 #include "TextLCD.h" //if using diagnostic
jason701802 0:b1e3fa917367 6
jason701802 0:b1e3fa917367 7 #define BRIDGEDRIVER_H
jason701802 0:b1e3fa917367 8
jason701802 4:87768972db3f 9
jason701802 4:87768972db3f 10 #define PWM_PERIOD 0.001
jason701802 4:87768972db3f 11
jason701802 0:b1e3fa917367 12 //pin definitions
jason701802 0:b1e3fa917367 13 #define PIN_CH1 P1_18 //hardware PWM1[1]
jason701802 0:b1e3fa917367 14 #define PIN_CH2 P2_0 //hardware PWM1[1]
jason701802 0:b1e3fa917367 15 #define PIN_CH3 P1_20 //hardware PWM1[2]
jason701802 0:b1e3fa917367 16 #define PIN_CH4 P2_1 //hardware PWM1[2]
jason701802 0:b1e3fa917367 17 #define PIN_CH5 P1_21 //hardware PWM1[3]
jason701802 0:b1e3fa917367 18 #define PIN_CH6 P1_23 //hardware PWM1[4]
jason701802 0:b1e3fa917367 19 #define PIN_CH7 P1_24 //hardware PWM1[5]
jason701802 0:b1e3fa917367 20 #define PIN_CH8 P1_26 //hardware PWM1[6]
jason701802 0:b1e3fa917367 21
jason701802 0:b1e3fa917367 22
jason701802 0:b1e3fa917367 23 #define EN_ADDR 0x40 //i2c address of enable pin port expander
jason701802 0:b1e3fa917367 24 #define LED_ADDR 0x4E //i2c address of button and LED port expander
jason701802 0:b1e3fa917367 25
jason701802 0:b1e3fa917367 26
jason701802 0:b1e3fa917367 27 class BridgeDriver{
jason701802 1:c8e328389a98 28
jason701802 1:c8e328389a98 29
jason701802 1:c8e328389a98 30 public:
jason701802 1:c8e328389a98 31 enum Bridges{ BRIDGE_A,
jason701802 0:b1e3fa917367 32 BRIDGE_B,
jason701802 0:b1e3fa917367 33 BRIDGE_C,
jason701802 0:b1e3fa917367 34 BRIDGE_D
jason701802 1:c8e328389a98 35 };
jason701802 1:c8e328389a98 36
jason701802 1:c8e328389a98 37
jason701802 1:c8e328389a98 38 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 39
jason701802 0:b1e3fa917367 40 ~BridgeDriver();
jason701802 0:b1e3fa917367 41
jason701802 0:b1e3fa917367 42 void enablePwm(uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD);
jason701802 0:b1e3fa917367 43 void enablePwm(Bridges bridge, uint8_t enPwm);
jason701802 0:b1e3fa917367 44
jason701802 0:b1e3fa917367 45
jason701802 0:b1e3fa917367 46 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 47 void enableBraking(Bridges bridge, uint8_t enBrake);
jason701802 0:b1e3fa917367 48
jason701802 0:b1e3fa917367 49 int forceBrake(uint8_t ch); //force a specific channel to GND without changing braking default
jason701802 0:b1e3fa917367 50 int forceBrake(Bridges bridge); //force a specific motor to GND without changing braking default
jason701802 0:b1e3fa917367 51 int forceFloat(uint8_t ch); //force a specific channel to float without changing braking default
jason701802 0:b1e3fa917367 52 int forceFloat(Bridges bridge); //force a specific motor to float without changing braking default
jason701802 0:b1e3fa917367 53
jason701802 0:b1e3fa917367 54 int drive(uint8_t state);
jason701802 0:b1e3fa917367 55 int drive(uint8_t ch, uint8_t on);
jason701802 0:b1e3fa917367 56 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 57 float drive(Bridges bridge, int8_t dir, float speed);
jason701802 0:b1e3fa917367 58 //dir: 1=fwd, -1=rev, 0=brake (irregardless of setting of _braking
jason701802 0:b1e3fa917367 59 //speed from 0 to 1, speed of 0 will coast or brake depending on setting of _braking
jason701802 1:c8e328389a98 60
jason701802 1:c8e328389a98 61 void diagnostic(TextLCD_I2C *lcd);
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 0:b1e3fa917367 78
jason701802 0:b1e3fa917367 79 void enableCh(uint8_t ch, uint8_t en);
jason701802 0:b1e3fa917367 80 void setLed(uint8_t ch, uint8_t en);
jason701802 0:b1e3fa917367 81 void setLed(uint8_t state);
jason701802 0:b1e3fa917367 82 void setPwm(uint8_t ch, uint8_t en);
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
jason701802 0:b1e3fa917367 90 #endif