stepper mottor for pumps

Dependencies:   mbed

Committer:
ekasinambela
Date:
Mon Jun 20 13:44:12 2016 +0000
Revision:
2:5b26538ab9ab
Parent:
0:29fc24ce612f
i changed the function, now its good; in the main function the initialization of the pumps is written

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ekasinambela 0:29fc24ce612f 1 #include "DRV8825.h"
ekasinambela 0:29fc24ce612f 2 #include "mbed.h"
ekasinambela 0:29fc24ce612f 3
ekasinambela 0:29fc24ce612f 4 DigitalOut myled(LED1);
ekasinambela 0:29fc24ce612f 5
ekasinambela 0:29fc24ce612f 6 DRV8825::DRV8825(PinName _en, PinName m0, PinName m1, PinName m2, PinName _stepPin, PinName dir):en(_en),
ekasinambela 0:29fc24ce612f 7 microstepping(m0, m1, m2),
ekasinambela 0:29fc24ce612f 8 stepPin(_stepPin),
ekasinambela 0:29fc24ce612f 9 direction(dir)
ekasinambela 0:29fc24ce612f 10 {
ekasinambela 0:29fc24ce612f 11 }
ekasinambela 0:29fc24ce612f 12
ekasinambela 0:29fc24ce612f 13 void DRV8825::settings(float microstep, int dir, float speed)
ekasinambela 0:29fc24ce612f 14 {
ekasinambela 0:29fc24ce612f 15 //Microsteppiing settings
ekasinambela 0:29fc24ce612f 16 if (microstep == 1) microstepping = 0;
ekasinambela 0:29fc24ce612f 17 else if (microstep == 1/2) microstepping = 1;
ekasinambela 0:29fc24ce612f 18 else if (microstep == 1/4) microstepping = 2;
ekasinambela 0:29fc24ce612f 19 else if (microstep == 1/8) microstepping = 3;
ekasinambela 0:29fc24ce612f 20 else if (microstep == 1/16) microstepping = 4;
ekasinambela 0:29fc24ce612f 21 else if (microstep == 1/32) microstepping = 8;
ekasinambela 0:29fc24ce612f 22
ekasinambela 0:29fc24ce612f 23 if (dir == 1) {
ekasinambela 0:29fc24ce612f 24 direction = 0;
ekasinambela 0:29fc24ce612f 25 } else if (dir == 0) {
ekasinambela 0:29fc24ce612f 26 direction = 1;
ekasinambela 0:29fc24ce612f 27 }
ekasinambela 0:29fc24ce612f 28
ekasinambela 0:29fc24ce612f 29 // Speeed or times per second
ekasinambela 0:29fc24ce612f 30 if(stepPin == 1){
ekasinambela 0:29fc24ce612f 31 stepPin = 0;
ekasinambela 0:29fc24ce612f 32 wait(1/speed);
ekasinambela 0:29fc24ce612f 33 }
ekasinambela 0:29fc24ce612f 34 else{
ekasinambela 0:29fc24ce612f 35 stepPin = 1;
ekasinambela 0:29fc24ce612f 36 wait(1/speed);
ekasinambela 0:29fc24ce612f 37 }
ekasinambela 0:29fc24ce612f 38 myled = stepPin;
ekasinambela 0:29fc24ce612f 39
ekasinambela 0:29fc24ce612f 40
ekasinambela 0:29fc24ce612f 41 }
ekasinambela 0:29fc24ce612f 42
ekasinambela 0:29fc24ce612f 43 void DRV8825::enable()
ekasinambela 0:29fc24ce612f 44 {
ekasinambela 0:29fc24ce612f 45 en = 0;
ekasinambela 0:29fc24ce612f 46 }
ekasinambela 0:29fc24ce612f 47
ekasinambela 0:29fc24ce612f 48 void DRV8825::disable()
ekasinambela 0:29fc24ce612f 49 {
ekasinambela 0:29fc24ce612f 50 en = 1;
ekasinambela 0:29fc24ce612f 51 }
ekasinambela 0:29fc24ce612f 52