control simple de motor paso a paso unipolar

Dependencies:   mbed

main.cpp

Committer:
lorzangas
Date:
2012-10-22
Revision:
2:42e4a5fcc99f
Parent:
1:26c2fd1ea036

File content as of revision 2:42e4a5fcc99f:

#include "mbed.h"

BusOut myleds(LED1, LED2, LED3, LED4);
BusOut motor(p10, p11, p12, p13);

/* Paso p10 p11 p12 p13
     1   1   0   1   0
     2   0   1   1   0
     3   0   1   0   1
     4   1   0   0   1
     */
int tiempo = 12000;//tiempo en us (tiempo entre pasos) nos da la velocidad 
int main() {
    while(1) {
        for (int s = 0; s < 120 ; s +=1) {//el 120 indica 120*4 pasos, en mi motor de 48 pasos 10 vueltas
        motor = (0xA); //1010
        wait_us(tiempo);
        motor = (0x6);//0110
        wait_us(tiempo);
        motor = (0x5);//0101
        wait_us(tiempo);
        motor = (0x9);//1001
        wait_us(tiempo);
        }
        wait(2);
        for (int s = 0; s < 120 ; s +=1) {//ahora en sentido contrario
        motor = (0x9);//1001
        wait_us(tiempo);
        motor = (0x5);//0101
        wait_us(tiempo);
        motor = (0x6);//0110
        wait_us(tiempo);
        motor = (0xA);//1010
        wait_us(tiempo);
        }
        wait(2);
   }
}