Giro en su propio eje Presentado por: Julio Fajardo, Cesar Pacheco, Angel Trujillo, Daniel Vizcaya

Dependencies:   mbed

Fork of 01_Embebidos by Daniel Vizcaya

Committer:
Bethory
Date:
Wed Apr 25 02:12:19 2018 +0000
Revision:
6:87a37f4163bd
Ejercicio 2do corte

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bethory 6:87a37f4163bd 1
Bethory 6:87a37f4163bd 2 /******************************************************************************
Bethory 6:87a37f4163bd 3 Desarrollado por ferney beltran fbeltran@ecci.edu.co
Bethory 6:87a37f4163bd 4
Bethory 6:87a37f4163bd 5 libreria ejemplo para el motor paso a paso unipolar de 4 fases
Bethory 6:87a37f4163bd 6
Bethory 6:87a37f4163bd 7 ******************************************************************************/
Bethory 6:87a37f4163bd 8
Bethory 6:87a37f4163bd 9 //*****************************************************************************
Bethory 6:87a37f4163bd 10
Bethory 6:87a37f4163bd 11 #include "stepmotor.h"
Bethory 6:87a37f4163bd 12 #include "mbed.h"
Bethory 6:87a37f4163bd 13
Bethory 6:87a37f4163bd 14
Bethory 6:87a37f4163bd 15
Bethory 6:87a37f4163bd 16
Bethory 6:87a37f4163bd 17
Bethory 6:87a37f4163bd 18
Bethory 6:87a37f4163bd 19 stepmotor::stepmotor(PinName in1, PinName in2, PinName in3, PinName in4) : motor_out(in1,in2,in3,in4) {
Bethory 6:87a37f4163bd 20
Bethory 6:87a37f4163bd 21
Bethory 6:87a37f4163bd 22 motor_out=0x0;
Bethory 6:87a37f4163bd 23 nstep=0;
Bethory 6:87a37f4163bd 24 motorSpeed=1100;
Bethory 6:87a37f4163bd 25
Bethory 6:87a37f4163bd 26 }
Bethory 6:87a37f4163bd 27
Bethory 6:87a37f4163bd 28
Bethory 6:87a37f4163bd 29 void stepmotor::move() {
Bethory 6:87a37f4163bd 30
Bethory 6:87a37f4163bd 31 switch(nstep)
Bethory 6:87a37f4163bd 32 {
Bethory 6:87a37f4163bd 33 case 0: motor_out = 0x1; break; // 0001
Bethory 6:87a37f4163bd 34 case 1: motor_out = 0x3; break; // 0011
Bethory 6:87a37f4163bd 35 case 2: motor_out = 0x2; break; // 0010
Bethory 6:87a37f4163bd 36 case 3: motor_out = 0x6; break; // 0110
Bethory 6:87a37f4163bd 37 case 4: motor_out = 0x4; break; // 0100
Bethory 6:87a37f4163bd 38 case 5: motor_out = 0xC; break; // 1100
Bethory 6:87a37f4163bd 39 case 6: motor_out = 0x8; break; // 1000
Bethory 6:87a37f4163bd 40 case 7: motor_out = 0x9; break; // 1001
Bethory 6:87a37f4163bd 41
Bethory 6:87a37f4163bd 42 default: motor_out = 0x0; break; // 0000
Bethory 6:87a37f4163bd 43 }
Bethory 6:87a37f4163bd 44 wait_us(motorSpeed);
Bethory 6:87a37f4163bd 45
Bethory 6:87a37f4163bd 46 }
Bethory 6:87a37f4163bd 47
Bethory 6:87a37f4163bd 48 void stepmotor::set_speed(int speed){
Bethory 6:87a37f4163bd 49 motorSpeed=speed; //set motor speed us
Bethory 6:87a37f4163bd 50 }
Bethory 6:87a37f4163bd 51 uint32_t stepmotor::get_speed(){
Bethory 6:87a37f4163bd 52 return motorSpeed; //
Bethory 6:87a37f4163bd 53 }
Bethory 6:87a37f4163bd 54
Bethory 6:87a37f4163bd 55 void stepmotor::step(uint32_t num_steps, bool cw) {
Bethory 6:87a37f4163bd 56 // funcion para mover el motor N pasos CW o CCW
Bethory 6:87a37f4163bd 57 // num_steps número de paso que da el motor
Bethory 6:87a37f4163bd 58 // cw =True para dirección en sentido del reloj
Bethory 6:87a37f4163bd 59 // cw =False para dirección contraria de las manecillas del reloj
Bethory 6:87a37f4163bd 60
Bethory 6:87a37f4163bd 61 uint32_t count=num_steps ;
Bethory 6:87a37f4163bd 62 while(count){
Bethory 6:87a37f4163bd 63 if (cw) nstep++;
Bethory 6:87a37f4163bd 64 else nstep--;
Bethory 6:87a37f4163bd 65 if (nstep>7) nstep=0;
Bethory 6:87a37f4163bd 66 if (nstep<0) nstep=7;
Bethory 6:87a37f4163bd 67 move();
Bethory 6:87a37f4163bd 68 count--;
Bethory 6:87a37f4163bd 69
Bethory 6:87a37f4163bd 70 }
Bethory 6:87a37f4163bd 71
Bethory 6:87a37f4163bd 72 }