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-04-04
- Revision:
- 2:0cc71fa2f3fd
- Parent:
- 1:004a27caba52
- Child:
- 3:aa9cafc61475
File content as of revision 2:0cc71fa2f3fd:
#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);
DigitalOut stepper_step1(PB_6);
DigitalOut steppeer_dir1(PB_7);
/*INGRESE LA CONFIGURACION DE LOS MOTORES*/
#define INITCMD 0xFF
// definición de las variables globales
uint32_t VELOCITY = 500 ; // Tiempo enmicro segundos
uint8_t N_pasos ; // varable almacena el numero de pasos que se mueve el motor en leer_datos()
uint8_t Coman ; //variable que nosindica el movimiento del motor
// definición de las funciones
void setup_uart();
void mover_steper_nema( uint8_t num_pasos , uint8_t _Coman );
void leer_datos();
int main() {
setup_uart();
//command.printf("inicio de programa");
while(1){
leer_datos();
mover_steper_nema( N_pasos , Coman );
}
}
void setup_uart(){
command.baud( 115200 ) ;
}
void leer_datos(){
while(command.getc()!= INITCMD) ;
Coman = command.getc() ;
N_pasos = command.getc() ;
}
void mover_steper_nema( uint8_t num_pasos , uint8_t Coman ){
uint8_t i = 0;
switch (Coman){
case 5:
steppeer_dir = 1;
wait_us( 1 );
for ( i= 0 ; i <= num_pasos ; i++ ){
stepper_step=1;
wait_us(VELOCITY);
stepper_step=0;
wait_us(VELOCITY);
}
break;
case 6:
steppeer_dir = 0;
wait_us( 1 );
for ( i= 0 ; i <= num_pasos ; i++ ){
stepper_step=1;
wait_us(VELOCITY);
stepper_step=0;
wait_us(VELOCITY);
}
break;
case 7:
steppeer_dir = 1;
wait_us( 1 );
for ( i= 0 ; i <= 64 ; i++ ){
stepper_step=1;
wait_us(VELOCITY);
stepper_step=0;
wait_us(VELOCITY);
}
break;
case 8:
steppeer_dir = 0;
wait_us( 1 );
for ( i= 0 ; i <= 64 ; i++ ){
stepper_step=1;
wait_us(VELOCITY);
stepper_step=0;
wait_us(VELOCITY);
}
break;
case 9:
//VELOCITY = VELOCITY * num_pasos ;
break;
}
}