Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- MarlonQ
- Date:
- 2019-03-22
- Revision:
- 1:004a27caba52
- Parent:
- 0:5e6b543c1179
- Child:
- 2:0cc71fa2f3fd
File content as of revision 1:004a27caba52:
#include "mbed.h"
/*****************************************************************************
generar un programa que controle por el puerto serial el sentido de giro del motor nema,
y el nímero de pasos. en este caso dejar la velocidad cosntantes pero con un define .
por medio de la comunicacion serial el comando es
| | | |
| INITCMD | sentido | N_pasos |
| 0xff | 0x00- 0x01 | 0x00 - 0xff |
para enviar los comandos usar el programa Coolterm http://freeware.the-meiers.org/
# para el motor nena se configurar el driver drv8825:
#
#
# <------period 4us min-------->
# <-1.9us min -> <-1.9us min ->
# _____________ _____________
# ____| |______________| |___________ signal step
# ____ ____
# _| |________________________| |____________________ dir modex 1-cw 0ccw
# <-> min 650ns <-> min 650ns
#
*****************************************************************************/
Serial command(USBTX, USBRX);
DigitalOut stepper_step(PB_4);
DigitalOut steppeer_dir(PB_5);
/*INGRESE LA CONFIGURACION DE LOS MOTORES*/
#define INITCMD 0xFF
#define VELOCITY 500 ///en micro segundos
// definición de las variables globales
uint8_t sentido_motor; // variable almacena el sentido de giro de motor en leer_datos()
uint8_t N_pasos; // varable almacena el numero de pasos que se mueve el motor en leer_datos()
// definición de las funciones
void setup_uart();
void mover_steper_nema(uint8_t sentido, uint8_t num_pasos);
void leer_datos();
int main() {
setup_uart();
//command.printf("inicio de programa");
while(1){
leer_datos();
mover_steper_nema(sentido_motor, N_pasos);
}
}
void setup_uart(){
command.baud(115200);
}
void leer_datos(){
while(command.getc()!= INITCMD);
sentido_motor=command.getc();
N_pasos=command.getc();
}
void mover_steper_nema(uint8_t sentido, uint8_t num_pasos){
uint8_t i = 0;
/* complementar el código necesario */
if (sentido == 1) {
steppeer_dir = 0;
} else if (sentido == 0) {
steppeer_dir = 1;
}
wait_us( 1 );
/*esperar 650 nsegundo*/
/* complementar el código necesario */
for ( i= 0 ; i <= num_pasos ; i++){
printf ("%x",i );
stepper_step=1;
wait_us(VELOCITY);
stepper_step=0;
wait_us(VELOCITY);
}
}