shindai
Dependents: linetrace tracer tracer tracer1 ... more
Revision 0:e6c391eb8fac, committed 2014-09-17
- Comitter:
- NT32
- Date:
- Wed Sep 17 03:43:44 2014 +0000
- Commit message:
- shinshu_university;
Changed in this revision
MotorDriver_SU.cpp | Show annotated file Show diff for this revision Revisions of this file |
MotorDriver_SU.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r e6c391eb8fac MotorDriver_SU.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MotorDriver_SU.cpp Wed Sep 17 03:43:44 2014 +0000 @@ -0,0 +1,38 @@ +#include "MotorDriver_SU.h" + +SPI spi(P1_22, NC, P1_15); +BusOut MotorDirect_A(P1_19, P1_25, P1_16, P0_19); +BusOut MotorDirect_B(P0_18, P0_17, P1_14, P1_13); + +MotorDriver_SU::MotorDriver_SU(PinName chip) : _chip(chip){ + if (chip == P0_2){ + MotorDirect = &MotorDirect_B; + }else{ + MotorDirect = &MotorDirect_A; + } + (*MotorDirect) = FREE; + _chip = 1; + dac.bit.AB = 0; + dac.bit.BUF = 1; + dac.bit.GA = 1; + dac.bit.SHDN = 1; + dac.bit.D = 0; + spi.format(16,0); + spi.frequency(20000000); + _chip = 0; + spi.write(dac.command); + _chip = 1; + dac.bit.AB = 1; + _chip = 0; + spi.write(dac.command); + _chip = 1; +} +void MotorDriver_SU::Drive(uint8_t channel, uint8_t direction, uint16_t velocity){ + dac.bit.AB = (channel ^ 0x01); + dac.bit.D = velocity; + _chip = 0; + spi.write(dac.command); + _chip = 1; +// (*MotorDirect) = ((*MotorDirect) & (0x0F & (0x0F << (channel * 2)))) | (direction <<(channel * 2)); + (*MotorDirect) = ((*MotorDirect) & (0x0C >> (channel * 2))) | (direction << (channel * 2)); +}
diff -r 000000000000 -r e6c391eb8fac MotorDriver_SU.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MotorDriver_SU.h Wed Sep 17 03:43:44 2014 +0000 @@ -0,0 +1,45 @@ +#ifndef MBED_MOTORDRIVER_SU_H_ +#define MBED_MOTORDRIVER_SU_H_ + +#include "mbed.h" + +#define MOTOR_SINGLE P0_2 +#define MOTOR_DOUBLE P0_20 + +#define FREE 0x00 +#define CW 0x01 +#define CCW 0x02 +#define STOP 0x03 + +class MotorDriver_SU{ +public: + MotorDriver_SU(PinName chip); + void Drive(uint8_t channel, uint8_t direction, uint16_t velocity); + +private: + + BusOut * MotorDirect; + DigitalOut _chip; + + + union MCP4922 + { + uint16_t command; + struct + { + //DAC data bits + uint16_t D :12; + //Output power down control bit + uint8_t SHDN:1; + //Outout gain select bit + uint8_t GA :1; + //Vref input buffer Control bit + uint8_t BUF :1; + //DACa or DACb select bit + uint8_t AB :1; + }bit; + }; + union MCP4922 dac; +}; + +#endif \ No newline at end of file