frequency change?

Fork of BridgeDriver by Jason T

Revision:
0:b1e3fa917367
Child:
1:c8e328389a98
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BridgeDriver.h	Thu Jul 03 17:09:29 2014 +0000
@@ -0,0 +1,81 @@
+#ifndef BRIDGEDRIVER_H
+
+#include "mbed.h"
+#include "MCP23017.h"
+
+#define BRIDGEDRIVER_H
+
+//pin definitions
+#define PIN_CH1 P1_18 //hardware PWM1[1]
+#define PIN_CH2 P2_0  //hardware PWM1[1]
+#define PIN_CH3 P1_20 //hardware PWM1[2]
+#define PIN_CH4 P2_1  //hardware PWM1[2]
+#define PIN_CH5 P1_21 //hardware PWM1[3]
+#define PIN_CH6 P1_23 //hardware PWM1[4]
+#define PIN_CH7 P1_24 //hardware PWM1[5]
+#define PIN_CH8 P1_26 //hardware PWM1[6]
+
+
+#define EN_ADDR  0x40 //i2c address of enable pin port expander
+#define LED_ADDR 0x4E //i2c address of button and LED port expander
+
+
+class BridgeDriver{
+    enum Bridges{ BRIDGE_A, 
+                  BRIDGE_B, 
+                  BRIDGE_C, 
+                  BRIDGE_D 
+                }; 
+    
+    public:
+    
+        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);
+        
+        ~BridgeDriver();
+        
+        void enablePwm(uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD);
+        void enablePwm(Bridges bridge, uint8_t enPwm);
+
+        
+        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
+        void enableBraking(Bridges bridge, uint8_t enBrake);
+        
+        int forceBrake(uint8_t ch);             //force a specific channel to GND without changing braking default
+        int forceBrake(Bridges bridge);     //force a specific motor to GND without changing braking default
+        int forceFloat(uint8_t ch);             //force a specific channel to float without changing braking default
+        int forceFloat(Bridges bridge);     //force a specific motor to float without changing braking default
+        
+        int drive(uint8_t state);
+        int drive(uint8_t ch, uint8_t on);
+        float drive(Bridges bridge, float speed); //speed from -1 to 1, speed of 0 will coast or brake depending on setting of _braking
+        float drive(Bridges bridge, int8_t dir, float speed); 
+            //dir: 1=fwd,  -1=rev, 0=brake (irregardless of setting of _braking
+            //speed from 0 to 1, speed of 0 will coast or brake depending on setting of _braking
+        
+        
+        
+    private:
+        DigitalOut *_d[8];
+        PwmOut *_p[8];
+        MCP23017 *_EnCtl;
+        MCP23017 *_IO;
+        I2C *_i2c;
+        uint8_t _enAddr;
+        uint8_t _ledAddr;
+        uint8_t _pwm[4];      
+        int8_t  _dir[4];       //dir of 1 means lower # ch is driving, dir of -1 means higher number ch is driving
+        uint8_t _braking[4]; 
+        uint8_t _oldLedState; //for setLed functions. Kept external to overload function
+        
+        void enableCh(uint8_t ch, uint8_t en);
+        void setLed(uint8_t ch, uint8_t en);
+        void setLed(uint8_t state);
+        void setPwm(uint8_t ch, uint8_t en);
+        
+        
+        
+};
+    
+
+
+#endif
\ No newline at end of file