This class interface the MDSMC (Micro Dual Serial Motor Controller) by Pololu with our mbed module
Revision 0:e869912db757, committed 2012-11-16
- Comitter:
- fangoman91
- Date:
- Fri Nov 16 20:26:54 2012 +0000
- Commit message:
- this class interface the MDSMC (Micro Dual Serial Motor Controller) by pololu
Changed in this revision
MDSMC.cpp | Show annotated file Show diff for this revision Revisions of this file |
MDSMC.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r e869912db757 MDSMC.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MDSMC.cpp Fri Nov 16 20:26:54 2012 +0000 @@ -0,0 +1,43 @@ +//.cpp file of MDSMC library + +#include "mbed.h" +#include "MDSMC.h" + +MDSMC::MDSMC(PinName TX, PinName RX, PinName CLR, int bps, int nM): _serialMDSMC(TX, RX), _CLR(CLR) +{ + reset(); + _serialMDSMC.baud(bps); + switch (nM) + { + case 1: + _serialMDSMC.putc(Start); + _serialMDSMC.putc(ChangeConfig); + _serialMDSMC.putc(Setting1); + reset(); + break; + case 2: + _serialMDSMC.putc(Start); + _serialMDSMC.putc(ChangeConfig); + _serialMDSMC.putc(Setting2); + reset(); + break; + } +} + +//user functions +void MDSMC::use(char direction, char speed) +{ + _serialMDSMC.putc(Start); + _serialMDSMC.putc(Device); + _serialMDSMC.putc(direction); + _serialMDSMC.putc(speed); +} + +void MDSMC::reset() +{ + _CLR = 0; + wait_us(2); + _CLR = 1; +} + + \ No newline at end of file
diff -r 000000000000 -r e869912db757 MDSMC.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MDSMC.h Fri Nov 16 20:26:54 2012 +0000 @@ -0,0 +1,70 @@ +/*THIS CLASS INTERFACE THE MDSMC by pololu (Micro Dual Serial Motor Controller) +WITH OUR MBED MODULE. THE MDSMC MUST BE USED WITH UART MODULE*/ + +#ifndef MBED_MDSMC_H +#define MBED_MDSMC_H + +#include "mbed.h" + +#define Start 0x80 +#define ChangeConfig 0x02 +#define Setting1 0x7F +#define Setting2 0x13 +#define Device 0x00 +#define Forward1 0x7F +#define Reverse1 0x7E +#define Forward2 0x27 +#define Reverse2 0x26 +#define Right 0x21 +#define Left 0x05 + +class MDSMC +{ + public: + /* - Declare Mbed connections + ** - Select serial pin with "PinName data" parameter; + ** - select reset pin with "PinName CLR" parameter; + ** - select motor mode with "nM" parameter if you set nM = 1 the MDSMC drive one motor, + ** if you set nM = 2 the MDSMC drive two motors; + ** - select the baud rate with "bps" parameter you can select a bps value between 2000 + ** and 19200.*/ + MDSMC(PinName TX, PinName RX, PinName CLR, int bps, int nM); + + /* - Give direction and speed*/ + void use(char direction, char speed); + + protected: + Serial _serialMDSMC; + DigitalOut _CLR; + void reset(); +}; +typedef unsigned char BYTE; + +#endif + +/*example used to test the class + +#include "mbed.h" +#include "MDSMC.h" + +MDSMC(USBTX,USBRX,p5); + +int main() +{ + MDSMC.init(1,9600); + wait(1); + MDSMC.use(Forward1, 80); + wait(1); + MDSMC.use(Reverse1, 80); + wait(2); + MDSMC.init(2,9600); + wait(1); + MDSMC.use(Forward2, 80); + wait(1); + MDSMC.use(Reverse2, 80); + wait(1); + MDSMC.use(Right, 50); + wait(1); + MDSMC.use(Left, 50); +} +*/ \ No newline at end of file