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.
Diff: main.cpp
- Revision:
- 2:0cc71fa2f3fd
- Parent:
- 1:004a27caba52
- Child:
- 3:aa9cafc61475
--- a/main.cpp Fri Mar 22 03:14:42 2019 +0000
+++ b/main.cpp Thu Apr 04 23:38:54 2019 +0000
@@ -29,26 +29,25 @@
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
-#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()
-
+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 sentido, uint8_t num_pasos);
+void mover_steper_nema( uint8_t num_pasos , uint8_t _Coman );
-void leer_datos();
-
-
+void leer_datos();
int main() {
@@ -56,52 +55,85 @@
//command.printf("inicio de programa");
while(1){
leer_datos();
- mover_steper_nema(sentido_motor, N_pasos);
+ mover_steper_nema( N_pasos , Coman );
}
}
-
-
void setup_uart(){
- command.baud(115200);
+ command.baud( 115200 ) ;
}
void leer_datos(){
- while(command.getc()!= INITCMD);
- sentido_motor=command.getc();
- N_pasos=command.getc();
+ while(command.getc()!= INITCMD) ;
+ Coman = command.getc() ;
+ N_pasos = command.getc() ;
}
-
+void mover_steper_nema( uint8_t num_pasos , uint8_t Coman ){
-void mover_steper_nema(uint8_t sentido, uint8_t num_pasos){
-
- uint8_t i = 0;
+ 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 );
-/* complementar el código necesario */
-
-
- if (sentido == 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;
- } else if (sentido == 0) {
- 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 9:
+ //VELOCITY = VELOCITY * num_pasos ;
+ break;
+ }
- 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);
- }
-
}
-
-