ferney alberto beltran molina
/
00_LAB_COMMAND_STEPMOTOR_NEMA
laboratorio de comando con el motor paso a paso nema
main.cpp@0:5e6b543c1179, 2019-02-25 (annotated)
- Committer:
- fabeltranm
- Date:
- Mon Feb 25 22:49:23 2019 +0000
- Revision:
- 0:5e6b543c1179
ok lab
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabeltranm | 0:5e6b543c1179 | 1 | #include "mbed.h" |
fabeltranm | 0:5e6b543c1179 | 2 | |
fabeltranm | 0:5e6b543c1179 | 3 | /***************************************************************************** |
fabeltranm | 0:5e6b543c1179 | 4 | generar un programa que controle por el puerto serial el sentido de giro del motor nema, |
fabeltranm | 0:5e6b543c1179 | 5 | y el nímero de pasos. en este caso dejar la velocidad cosntantes pero con un define . |
fabeltranm | 0:5e6b543c1179 | 6 | |
fabeltranm | 0:5e6b543c1179 | 7 | por medio de la comunicacion serial el comando es |
fabeltranm | 0:5e6b543c1179 | 8 | |
fabeltranm | 0:5e6b543c1179 | 9 | | | | | |
fabeltranm | 0:5e6b543c1179 | 10 | | INITCMD | sentido | N_pasos | |
fabeltranm | 0:5e6b543c1179 | 11 | | 0xff | 0x00- 0x01 | 0x00 - 0xff | |
fabeltranm | 0:5e6b543c1179 | 12 | |
fabeltranm | 0:5e6b543c1179 | 13 | para enviar los comandos usar el programa Coolterm http://freeware.the-meiers.org/ |
fabeltranm | 0:5e6b543c1179 | 14 | |
fabeltranm | 0:5e6b543c1179 | 15 | # para el motor nena se configurar el driver drv8825: |
fabeltranm | 0:5e6b543c1179 | 16 | # |
fabeltranm | 0:5e6b543c1179 | 17 | # |
fabeltranm | 0:5e6b543c1179 | 18 | # <------period 4us min--------> |
fabeltranm | 0:5e6b543c1179 | 19 | # <-1.9us min -> <-1.9us min -> |
fabeltranm | 0:5e6b543c1179 | 20 | # _____________ _____________ |
fabeltranm | 0:5e6b543c1179 | 21 | # ____| |______________| |___________ signal step |
fabeltranm | 0:5e6b543c1179 | 22 | # ____ ____ |
fabeltranm | 0:5e6b543c1179 | 23 | # _| |________________________| |____________________ dir modex 1-cw 0ccw |
fabeltranm | 0:5e6b543c1179 | 24 | # <-> min 650ns <-> min 650ns |
fabeltranm | 0:5e6b543c1179 | 25 | # |
fabeltranm | 0:5e6b543c1179 | 26 | *****************************************************************************/ |
fabeltranm | 0:5e6b543c1179 | 27 | |
fabeltranm | 0:5e6b543c1179 | 28 | |
fabeltranm | 0:5e6b543c1179 | 29 | Serial command(USBTX, USBRX); |
fabeltranm | 0:5e6b543c1179 | 30 | DigitalOut stepper_step(PB_4); |
fabeltranm | 0:5e6b543c1179 | 31 | DigitalOut steppeer_dir(PB_5); |
fabeltranm | 0:5e6b543c1179 | 32 | |
fabeltranm | 0:5e6b543c1179 | 33 | /*INGRESE LA CONFIGURACION DE LOS MOTORES*/ |
fabeltranm | 0:5e6b543c1179 | 34 | |
fabeltranm | 0:5e6b543c1179 | 35 | #define INITCMD 0xFF |
fabeltranm | 0:5e6b543c1179 | 36 | #define VELOCITY 5 ///en micro segundos |
fabeltranm | 0:5e6b543c1179 | 37 | |
fabeltranm | 0:5e6b543c1179 | 38 | // definición de las variables globales |
fabeltranm | 0:5e6b543c1179 | 39 | |
fabeltranm | 0:5e6b543c1179 | 40 | uint8_t sentido_motor; // variable almacena el sentido de giro de motor en leer_datos() |
fabeltranm | 0:5e6b543c1179 | 41 | uint8_t N_pasos; // varable almacena el numero de pasos que se mueve el motor en leer_datos() |
fabeltranm | 0:5e6b543c1179 | 42 | |
fabeltranm | 0:5e6b543c1179 | 43 | |
fabeltranm | 0:5e6b543c1179 | 44 | // definición de las funciones |
fabeltranm | 0:5e6b543c1179 | 45 | void setup_uart(); |
fabeltranm | 0:5e6b543c1179 | 46 | |
fabeltranm | 0:5e6b543c1179 | 47 | void mover_steper_nema(uint8_t sentido, uint8_t num_pasos); |
fabeltranm | 0:5e6b543c1179 | 48 | |
fabeltranm | 0:5e6b543c1179 | 49 | void leer_datos(); |
fabeltranm | 0:5e6b543c1179 | 50 | |
fabeltranm | 0:5e6b543c1179 | 51 | |
fabeltranm | 0:5e6b543c1179 | 52 | |
fabeltranm | 0:5e6b543c1179 | 53 | int main() { |
fabeltranm | 0:5e6b543c1179 | 54 | |
fabeltranm | 0:5e6b543c1179 | 55 | setup_uart(); |
fabeltranm | 0:5e6b543c1179 | 56 | //command.printf("inicio de programa"); |
fabeltranm | 0:5e6b543c1179 | 57 | while(1){ |
fabeltranm | 0:5e6b543c1179 | 58 | leer_datos(); |
fabeltranm | 0:5e6b543c1179 | 59 | mover_steper_nema(sentido_motor, N_pasos); |
fabeltranm | 0:5e6b543c1179 | 60 | } |
fabeltranm | 0:5e6b543c1179 | 61 | } |
fabeltranm | 0:5e6b543c1179 | 62 | |
fabeltranm | 0:5e6b543c1179 | 63 | |
fabeltranm | 0:5e6b543c1179 | 64 | |
fabeltranm | 0:5e6b543c1179 | 65 | void setup_uart(){ |
fabeltranm | 0:5e6b543c1179 | 66 | command.baud(115200); |
fabeltranm | 0:5e6b543c1179 | 67 | } |
fabeltranm | 0:5e6b543c1179 | 68 | |
fabeltranm | 0:5e6b543c1179 | 69 | |
fabeltranm | 0:5e6b543c1179 | 70 | |
fabeltranm | 0:5e6b543c1179 | 71 | void leer_datos(){ |
fabeltranm | 0:5e6b543c1179 | 72 | while(command.getc()!= INITCMD); |
fabeltranm | 0:5e6b543c1179 | 73 | sentido_motor=command.getc(); |
fabeltranm | 0:5e6b543c1179 | 74 | N_pasos=command.getc(); |
fabeltranm | 0:5e6b543c1179 | 75 | |
fabeltranm | 0:5e6b543c1179 | 76 | } |
fabeltranm | 0:5e6b543c1179 | 77 | |
fabeltranm | 0:5e6b543c1179 | 78 | |
fabeltranm | 0:5e6b543c1179 | 79 | |
fabeltranm | 0:5e6b543c1179 | 80 | void mover_steper_nema(uint8_t sentido, uint8_t num_pasos){ |
fabeltranm | 0:5e6b543c1179 | 81 | |
fabeltranm | 0:5e6b543c1179 | 82 | uint32_t dpulse=0; |
fabeltranm | 0:5e6b543c1179 | 83 | |
fabeltranm | 0:5e6b543c1179 | 84 | /* complementar el código necesario */ |
fabeltranm | 0:5e6b543c1179 | 85 | |
fabeltranm | 0:5e6b543c1179 | 86 | if (sentido == 1) { |
fabeltranm | 0:5e6b543c1179 | 87 | steppeer_dir = 0; |
fabeltranm | 0:5e6b543c1179 | 88 | } else if (sentido == 0) { |
fabeltranm | 0:5e6b543c1179 | 89 | steppeer_dir = 1; |
fabeltranm | 0:5e6b543c1179 | 90 | } |
fabeltranm | 0:5e6b543c1179 | 91 | /*esperar 650 nsegundo*/ |
fabeltranm | 0:5e6b543c1179 | 92 | |
fabeltranm | 0:5e6b543c1179 | 93 | /* complementar el código necesario */ |
fabeltranm | 0:5e6b543c1179 | 94 | stepper_step=1; |
fabeltranm | 0:5e6b543c1179 | 95 | wait_us(VELOCITY); |
fabeltranm | 0:5e6b543c1179 | 96 | stepper_step=0; |
fabeltranm | 0:5e6b543c1179 | 97 | wait_us(VELOCITY); |
fabeltranm | 0:5e6b543c1179 | 98 | |
fabeltranm | 0:5e6b543c1179 | 99 | |
fabeltranm | 0:5e6b543c1179 | 100 | } |
fabeltranm | 0:5e6b543c1179 | 101 | |
fabeltranm | 0:5e6b543c1179 | 102 |