Realizamos una PCB para integrar los driver de los motores y el circuito de la matriz 8x8, trabajando ademas el núcleo STM32 f446re
main.cpp@0:8180a93bf2dc, 2017-06-09 (annotated)
- Committer:
- Paxtel
- Date:
- Fri Jun 09 18:05:53 2017 +0000
- Revision:
- 0:8180a93bf2dc
PROYECTO FINAL PICCOLO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Paxtel | 0:8180a93bf2dc | 1 | #include "mbed.h" |
Paxtel | 0:8180a93bf2dc | 2 | #include "max7219.h" // incluir librerias. |
Paxtel | 0:8180a93bf2dc | 3 | #include "vision.h" |
Paxtel | 0:8180a93bf2dc | 4 | #include "stdlib.h" |
Paxtel | 0:8180a93bf2dc | 5 | |
Paxtel | 0:8180a93bf2dc | 6 | int motorSpeed; // variable para la velocidad del motor |
Paxtel | 0:8180a93bf2dc | 7 | int cuadrante;//variable de cuadrante |
Paxtel | 0:8180a93bf2dc | 8 | int pasos; |
Paxtel | 0:8180a93bf2dc | 9 | |
Paxtel | 0:8180a93bf2dc | 10 | //#define DEBUG 1 |
Paxtel | 0:8180a93bf2dc | 11 | |
Paxtel | 0:8180a93bf2dc | 12 | //***************************************************************************** |
Paxtel | 0:8180a93bf2dc | 13 | // COMANDO MOVER MOTOR |
Paxtel | 0:8180a93bf2dc | 14 | // |POS 1|POS 2|POS 3|POS 4| POS 5| |
Paxtel | 0:8180a93bf2dc | 15 | // | < | #M | , | #°G | > | |
Paxtel | 0:8180a93bf2dc | 16 | // |
Paxtel | 0:8180a93bf2dc | 17 | // #M -> indica el motor que se va a mover |
Paxtel | 0:8180a93bf2dc | 18 | // #°G -> indica los grados a mover del servomotor |
Paxtel | 0:8180a93bf2dc | 19 | // <,> -> inicio, separdor y fin de comando |
Paxtel | 0:8180a93bf2dc | 20 | // el inicio de comando no se almacena en el buffer |
Paxtel | 0:8180a93bf2dc | 21 | //***************************************************************************** |
Paxtel | 0:8180a93bf2dc | 22 | |
Paxtel | 0:8180a93bf2dc | 23 | // VARIABLES PARA DEFINIR EL COMMANDO |
Paxtel | 0:8180a93bf2dc | 24 | #define BUFF_SIZE 4 |
Paxtel | 0:8180a93bf2dc | 25 | #define COMM_NUM_MOTOR 0 |
Paxtel | 0:8180a93bf2dc | 26 | #define COMM_SEPARADOR 1 |
Paxtel | 0:8180a93bf2dc | 27 | #define COMM_GRADOS_MOTOR 2 |
Paxtel | 0:8180a93bf2dc | 28 | |
Paxtel | 0:8180a93bf2dc | 29 | |
Paxtel | 0:8180a93bf2dc | 30 | uint8_t buffer_command[BUFF_SIZE]={0,0,0,0}; |
Paxtel | 0:8180a93bf2dc | 31 | |
Paxtel | 0:8180a93bf2dc | 32 | |
Paxtel | 0:8180a93bf2dc | 33 | void print_num(uint8_t val) |
Paxtel | 0:8180a93bf2dc | 34 | |
Paxtel | 0:8180a93bf2dc | 35 | { |
Paxtel | 0:8180a93bf2dc | 36 | if (val <10) |
Paxtel | 0:8180a93bf2dc | 37 | command.putc(val+0x30); |
Paxtel | 0:8180a93bf2dc | 38 | else |
Paxtel | 0:8180a93bf2dc | 39 | command.putc(val-9+0x40); |
Paxtel | 0:8180a93bf2dc | 40 | |
Paxtel | 0:8180a93bf2dc | 41 | } |
Paxtel | 0:8180a93bf2dc | 42 | void print_bin2hex (uint8_t val) |
Paxtel | 0:8180a93bf2dc | 43 | { |
Paxtel | 0:8180a93bf2dc | 44 | command.printf(" 0x"); |
Paxtel | 0:8180a93bf2dc | 45 | print_num(val>>4); |
Paxtel | 0:8180a93bf2dc | 46 | print_num(val&0x0f); |
Paxtel | 0:8180a93bf2dc | 47 | |
Paxtel | 0:8180a93bf2dc | 48 | |
Paxtel | 0:8180a93bf2dc | 49 | } |
Paxtel | 0:8180a93bf2dc | 50 | |
Paxtel | 0:8180a93bf2dc | 51 | // TODO : TIMEOUT UART SERIAL |
Paxtel | 0:8180a93bf2dc | 52 | void Read_command() |
Paxtel | 0:8180a93bf2dc | 53 | { |
Paxtel | 0:8180a93bf2dc | 54 | for (uint8_t i=0; i<BUFF_SIZE;i++) |
Paxtel | 0:8180a93bf2dc | 55 | buffer_command[i]=command.getc(); |
Paxtel | 0:8180a93bf2dc | 56 | |
Paxtel | 0:8180a93bf2dc | 57 | } |
Paxtel | 0:8180a93bf2dc | 58 | |
Paxtel | 0:8180a93bf2dc | 59 | void echo_command() |
Paxtel | 0:8180a93bf2dc | 60 | { |
Paxtel | 0:8180a93bf2dc | 61 | for (uint8_t i=0; i<BUFF_SIZE;i++) |
Paxtel | 0:8180a93bf2dc | 62 | print_bin2hex(buffer_command[i]); |
Paxtel | 0:8180a93bf2dc | 63 | |
Paxtel | 0:8180a93bf2dc | 64 | } |
Paxtel | 0:8180a93bf2dc | 65 | |
Paxtel | 0:8180a93bf2dc | 66 | |
Paxtel | 0:8180a93bf2dc | 67 | uint8_t check_command() |
Paxtel | 0:8180a93bf2dc | 68 | { if(buffer_command[BUFF_SIZE-1]== '>' && buffer_command[COMM_NUM_MOTOR]==03){ // seleccion del motor paso a paso |
Paxtel | 0:8180a93bf2dc | 69 | |
Paxtel | 0:8180a93bf2dc | 70 | if(cuadrante >buffer_command[COMM_GRADOS_MOTOR]){ // seleccion direccion del motor paso a paso (derecha) |
Paxtel | 0:8180a93bf2dc | 71 | Print_pantalla_tabla(m4right); |
Paxtel | 0:8180a93bf2dc | 72 | cuadrante=(cuadrante-buffer_command[COMM_GRADOS_MOTOR]); |
Paxtel | 0:8180a93bf2dc | 73 | pasos=(cuadrante*255); |
Paxtel | 0:8180a93bf2dc | 74 | stepper(pasos,00); |
Paxtel | 0:8180a93bf2dc | 75 | } |
Paxtel | 0:8180a93bf2dc | 76 | else if(cuadrante<buffer_command[COMM_GRADOS_MOTOR]){// seleccion direccion del motor paso a paso (izquierda) |
Paxtel | 0:8180a93bf2dc | 77 | Print_pantalla_tabla(m4left); |
Paxtel | 0:8180a93bf2dc | 78 | cuadrante=(cuadrante-buffer_command[COMM_GRADOS_MOTOR]); |
Paxtel | 0:8180a93bf2dc | 79 | cuadrante=(abs(cuadrante)); |
Paxtel | 0:8180a93bf2dc | 80 | pasos=(cuadrante*255); |
Paxtel | 0:8180a93bf2dc | 81 | stepper(pasos,01); |
Paxtel | 0:8180a93bf2dc | 82 | } |
Paxtel | 0:8180a93bf2dc | 83 | else{ |
Paxtel | 0:8180a93bf2dc | 84 | return 0;} |
Paxtel | 0:8180a93bf2dc | 85 | } |
Paxtel | 0:8180a93bf2dc | 86 | |
Paxtel | 0:8180a93bf2dc | 87 | else if (buffer_command[BUFF_SIZE-1]== '>' && buffer_command[COMM_SEPARADOR]==','){ // seleccion solo servo motores, verifica que la entrada sea correcta |
Paxtel | 0:8180a93bf2dc | 88 | |
Paxtel | 0:8180a93bf2dc | 89 | #if DEBUG |
Paxtel | 0:8180a93bf2dc | 90 | command.printf("\nMover Motor:"); |
Paxtel | 0:8180a93bf2dc | 91 | print_bin2hex(buffer_command[COMM_NUM_MOTOR]); |
Paxtel | 0:8180a93bf2dc | 92 | command.printf(" -> "); |
Paxtel | 0:8180a93bf2dc | 93 | print_bin2hex(buffer_command[COMM_GRADOS_MOTOR]); |
Paxtel | 0:8180a93bf2dc | 94 | command.printf(" grados \n"); |
Paxtel | 0:8180a93bf2dc | 95 | #endif |
Paxtel | 0:8180a93bf2dc | 96 | return 1; |
Paxtel | 0:8180a93bf2dc | 97 | } |
Paxtel | 0:8180a93bf2dc | 98 | #if DEBUG |
Paxtel | 0:8180a93bf2dc | 99 | command.printf("\n ERROR COMANDO -> "); // error si los simbolos de entrada son incorrectos |
Paxtel | 0:8180a93bf2dc | 100 | echo_command(); |
Paxtel | 0:8180a93bf2dc | 101 | #endif |
Paxtel | 0:8180a93bf2dc | 102 | return 0; |
Paxtel | 0:8180a93bf2dc | 103 | |
Paxtel | 0:8180a93bf2dc | 104 | |
Paxtel | 0:8180a93bf2dc | 105 | } |
Paxtel | 0:8180a93bf2dc | 106 | |
Paxtel | 0:8180a93bf2dc | 107 | |
Paxtel | 0:8180a93bf2dc | 108 | |
Paxtel | 0:8180a93bf2dc | 109 | |
Paxtel | 0:8180a93bf2dc | 110 | |
Paxtel | 0:8180a93bf2dc | 111 | |
Paxtel | 0:8180a93bf2dc | 112 | |
Paxtel | 0:8180a93bf2dc | 113 | void command_motor(uint8_t nm,uint8_t grados) |
Paxtel | 0:8180a93bf2dc | 114 | { |
Paxtel | 0:8180a93bf2dc | 115 | unsigned int k; |
Paxtel | 0:8180a93bf2dc | 116 | |
Paxtel | 0:8180a93bf2dc | 117 | k=((grados*9)+550); // formula para los grados de los servomotores |
Paxtel | 0:8180a93bf2dc | 118 | |
Paxtel | 0:8180a93bf2dc | 119 | |
Paxtel | 0:8180a93bf2dc | 120 | |
Paxtel | 0:8180a93bf2dc | 121 | |
Paxtel | 0:8180a93bf2dc | 122 | switch(nm){ // seleccion del servo a mover |
Paxtel | 0:8180a93bf2dc | 123 | case 00: |
Paxtel | 0:8180a93bf2dc | 124 | if(grados==0x5a){ //90 grados |
Paxtel | 0:8180a93bf2dc | 125 | |
Paxtel | 0:8180a93bf2dc | 126 | Print_pantalla_tabla(m1up); |
Paxtel | 0:8180a93bf2dc | 127 | |
Paxtel | 0:8180a93bf2dc | 128 | |
Paxtel | 0:8180a93bf2dc | 129 | mipwm.pulsewidth_us(k); |
Paxtel | 0:8180a93bf2dc | 130 | |
Paxtel | 0:8180a93bf2dc | 131 | } |
Paxtel | 0:8180a93bf2dc | 132 | else if (grados<0x5a){ // visualizacion cuando es menor que 90 |
Paxtel | 0:8180a93bf2dc | 133 | Print_pantalla_tabla(m1right); |
Paxtel | 0:8180a93bf2dc | 134 | |
Paxtel | 0:8180a93bf2dc | 135 | mipwm.pulsewidth_us(k); |
Paxtel | 0:8180a93bf2dc | 136 | |
Paxtel | 0:8180a93bf2dc | 137 | } |
Paxtel | 0:8180a93bf2dc | 138 | else{ // visualizacion cuando es mayor que 90 |
Paxtel | 0:8180a93bf2dc | 139 | Print_pantalla_tabla(m1left); |
Paxtel | 0:8180a93bf2dc | 140 | |
Paxtel | 0:8180a93bf2dc | 141 | mipwm.pulsewidth_us(k); |
Paxtel | 0:8180a93bf2dc | 142 | |
Paxtel | 0:8180a93bf2dc | 143 | } |
Paxtel | 0:8180a93bf2dc | 144 | |
Paxtel | 0:8180a93bf2dc | 145 | mipwm.pulsewidth_us(k); |
Paxtel | 0:8180a93bf2dc | 146 | |
Paxtel | 0:8180a93bf2dc | 147 | break; |
Paxtel | 0:8180a93bf2dc | 148 | case 01:if(grados==0x5a){ //90 grados |
Paxtel | 0:8180a93bf2dc | 149 | |
Paxtel | 0:8180a93bf2dc | 150 | Print_pantalla_tabla(m2up); |
Paxtel | 0:8180a93bf2dc | 151 | |
Paxtel | 0:8180a93bf2dc | 152 | } |
Paxtel | 0:8180a93bf2dc | 153 | else if (grados<0x5a){ // visualizacion cuando es menor que 90 |
Paxtel | 0:8180a93bf2dc | 154 | Print_pantalla_tabla(m2right); |
Paxtel | 0:8180a93bf2dc | 155 | |
Paxtel | 0:8180a93bf2dc | 156 | } |
Paxtel | 0:8180a93bf2dc | 157 | else{// visualizacion cuando es mayor que 90 |
Paxtel | 0:8180a93bf2dc | 158 | Print_pantalla_tabla(m2left); |
Paxtel | 0:8180a93bf2dc | 159 | |
Paxtel | 0:8180a93bf2dc | 160 | } |
Paxtel | 0:8180a93bf2dc | 161 | mipwm2.pulsewidth_us(k); |
Paxtel | 0:8180a93bf2dc | 162 | |
Paxtel | 0:8180a93bf2dc | 163 | break; |
Paxtel | 0:8180a93bf2dc | 164 | case 02: |
Paxtel | 0:8180a93bf2dc | 165 | if(grados==0x5a){ //90 grados |
Paxtel | 0:8180a93bf2dc | 166 | |
Paxtel | 0:8180a93bf2dc | 167 | Print_pantalla_tabla(m3up); |
Paxtel | 0:8180a93bf2dc | 168 | |
Paxtel | 0:8180a93bf2dc | 169 | } |
Paxtel | 0:8180a93bf2dc | 170 | else if (grados<0x5a){ // visualizacion cuando es menor que 90 |
Paxtel | 0:8180a93bf2dc | 171 | Print_pantalla_tabla(m3right); |
Paxtel | 0:8180a93bf2dc | 172 | |
Paxtel | 0:8180a93bf2dc | 173 | } |
Paxtel | 0:8180a93bf2dc | 174 | else{ // visualizacion cuando es mayor que 90 |
Paxtel | 0:8180a93bf2dc | 175 | Print_pantalla_tabla(m3left); |
Paxtel | 0:8180a93bf2dc | 176 | |
Paxtel | 0:8180a93bf2dc | 177 | } |
Paxtel | 0:8180a93bf2dc | 178 | mipwm3.pulsewidth_us(k); |
Paxtel | 0:8180a93bf2dc | 179 | |
Paxtel | 0:8180a93bf2dc | 180 | break; |
Paxtel | 0:8180a93bf2dc | 181 | default: |
Paxtel | 0:8180a93bf2dc | 182 | break; |
Paxtel | 0:8180a93bf2dc | 183 | } |
Paxtel | 0:8180a93bf2dc | 184 | |
Paxtel | 0:8180a93bf2dc | 185 | |
Paxtel | 0:8180a93bf2dc | 186 | |
Paxtel | 0:8180a93bf2dc | 187 | } |
Paxtel | 0:8180a93bf2dc | 188 | |
Paxtel | 0:8180a93bf2dc | 189 | |
Paxtel | 0:8180a93bf2dc | 190 | |
Paxtel | 0:8180a93bf2dc | 191 | int main() { |
Paxtel | 0:8180a93bf2dc | 192 | cuadrante=0; |
Paxtel | 0:8180a93bf2dc | 193 | max7219_configuration_t cfg = { |
Paxtel | 0:8180a93bf2dc | 194 | .device_number = 1, |
Paxtel | 0:8180a93bf2dc | 195 | .decode_mode = 0, //configuracion del max7219 |
Paxtel | 0:8180a93bf2dc | 196 | .intensity = Max7219::MAX7219_INTENSITY_5, |
Paxtel | 0:8180a93bf2dc | 197 | .scan_limit = Max7219::MAX7219_SCAN_8 |
Paxtel | 0:8180a93bf2dc | 198 | }; |
Paxtel | 0:8180a93bf2dc | 199 | |
Paxtel | 0:8180a93bf2dc | 200 | pantalla.init_device(cfg); |
Paxtel | 0:8180a93bf2dc | 201 | pantalla.enable_device(1); |
Paxtel | 0:8180a93bf2dc | 202 | pantalla.set_display_test(); //testeo de la matriz |
Paxtel | 0:8180a93bf2dc | 203 | wait(1); |
Paxtel | 0:8180a93bf2dc | 204 | pantalla.clear_display_test(); |
Paxtel | 0:8180a93bf2dc | 205 | |
Paxtel | 0:8180a93bf2dc | 206 | |
Paxtel | 0:8180a93bf2dc | 207 | |
Paxtel | 0:8180a93bf2dc | 208 | |
Paxtel | 0:8180a93bf2dc | 209 | |
Paxtel | 0:8180a93bf2dc | 210 | |
Paxtel | 0:8180a93bf2dc | 211 | Print_pantalla_tabla(clear); // limpiar matriz |
Paxtel | 0:8180a93bf2dc | 212 | #if DEBUG |
Paxtel | 0:8180a93bf2dc | 213 | command.printf("inicio con debug\n"); |
Paxtel | 0:8180a93bf2dc | 214 | #else |
Paxtel | 0:8180a93bf2dc | 215 | command.printf("inicio sin debug\n"); |
Paxtel | 0:8180a93bf2dc | 216 | #endif |
Paxtel | 0:8180a93bf2dc | 217 | uint8_t val; |
Paxtel | 0:8180a93bf2dc | 218 | while(1){ |
Paxtel | 0:8180a93bf2dc | 219 | val=command.getc(); |
Paxtel | 0:8180a93bf2dc | 220 | if (val== '<'){ |
Paxtel | 0:8180a93bf2dc | 221 | Read_command(); |
Paxtel | 0:8180a93bf2dc | 222 | if (check_command()){ |
Paxtel | 0:8180a93bf2dc | 223 | command_motor(buffer_command[COMM_NUM_MOTOR],buffer_command[COMM_GRADOS_MOTOR]); |
Paxtel | 0:8180a93bf2dc | 224 | } |
Paxtel | 0:8180a93bf2dc | 225 | } |
Paxtel | 0:8180a93bf2dc | 226 | |
Paxtel | 0:8180a93bf2dc | 227 | } |
Paxtel | 0:8180a93bf2dc | 228 | } |
Paxtel | 0:8180a93bf2dc | 229 | |
Paxtel | 0:8180a93bf2dc | 230 | |
Paxtel | 0:8180a93bf2dc | 231 | |
Paxtel | 0:8180a93bf2dc | 232 | |
Paxtel | 0:8180a93bf2dc | 233 | void Print_pantalla_tabla(unsigned char *pValor){ |
Paxtel | 0:8180a93bf2dc | 234 | int i; //funcion de puntero, impresión de pantalla |
Paxtel | 0:8180a93bf2dc | 235 | for (i =0;i<8;i++) |
Paxtel | 0:8180a93bf2dc | 236 | pantalla.write_digit(1,i+1,pValor[i]); |
Paxtel | 0:8180a93bf2dc | 237 | |
Paxtel | 0:8180a93bf2dc | 238 | } |
Paxtel | 0:8180a93bf2dc | 239 | |
Paxtel | 0:8180a93bf2dc | 240 | |
Paxtel | 0:8180a93bf2dc | 241 | |
Paxtel | 0:8180a93bf2dc | 242 | |
Paxtel | 0:8180a93bf2dc | 243 | void anticlockwise() { // rotacion del motor paso a paso sentido antihorario |
Paxtel | 0:8180a93bf2dc | 244 | for (int i = 0; i < 8; i++) { |
Paxtel | 0:8180a93bf2dc | 245 | |
Paxtel | 0:8180a93bf2dc | 246 | switch (i) { // activar(1) o desactivar(0) las bobinas |
Paxtel | 0:8180a93bf2dc | 247 | case 0: { |
Paxtel | 0:8180a93bf2dc | 248 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 249 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 250 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 251 | _A3=1; |
Paxtel | 0:8180a93bf2dc | 252 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 253 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 254 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 255 | _A7=1; |
Paxtel | 0:8180a93bf2dc | 256 | } |
Paxtel | 0:8180a93bf2dc | 257 | break; |
Paxtel | 0:8180a93bf2dc | 258 | case 1: { |
Paxtel | 0:8180a93bf2dc | 259 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 260 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 261 | _A2=1; |
Paxtel | 0:8180a93bf2dc | 262 | _A3=1; |
Paxtel | 0:8180a93bf2dc | 263 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 264 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 265 | _A6=1; |
Paxtel | 0:8180a93bf2dc | 266 | _A7=1; |
Paxtel | 0:8180a93bf2dc | 267 | } |
Paxtel | 0:8180a93bf2dc | 268 | break; |
Paxtel | 0:8180a93bf2dc | 269 | case 2: { |
Paxtel | 0:8180a93bf2dc | 270 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 271 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 272 | _A2=1; |
Paxtel | 0:8180a93bf2dc | 273 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 274 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 275 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 276 | _A6=1; |
Paxtel | 0:8180a93bf2dc | 277 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 278 | } |
Paxtel | 0:8180a93bf2dc | 279 | break; |
Paxtel | 0:8180a93bf2dc | 280 | case 3: { |
Paxtel | 0:8180a93bf2dc | 281 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 282 | _A1=1; |
Paxtel | 0:8180a93bf2dc | 283 | _A2=1; |
Paxtel | 0:8180a93bf2dc | 284 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 285 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 286 | _A5=1; |
Paxtel | 0:8180a93bf2dc | 287 | _A6=1; |
Paxtel | 0:8180a93bf2dc | 288 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 289 | } |
Paxtel | 0:8180a93bf2dc | 290 | break; |
Paxtel | 0:8180a93bf2dc | 291 | case 4: { |
Paxtel | 0:8180a93bf2dc | 292 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 293 | _A1=1; |
Paxtel | 0:8180a93bf2dc | 294 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 295 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 296 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 297 | _A5=1; |
Paxtel | 0:8180a93bf2dc | 298 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 299 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 300 | } |
Paxtel | 0:8180a93bf2dc | 301 | break; |
Paxtel | 0:8180a93bf2dc | 302 | case 5: { |
Paxtel | 0:8180a93bf2dc | 303 | _A0=1; |
Paxtel | 0:8180a93bf2dc | 304 | _A1=1; |
Paxtel | 0:8180a93bf2dc | 305 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 306 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 307 | _A4=1; |
Paxtel | 0:8180a93bf2dc | 308 | _A5=1; |
Paxtel | 0:8180a93bf2dc | 309 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 310 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 311 | } |
Paxtel | 0:8180a93bf2dc | 312 | break; |
Paxtel | 0:8180a93bf2dc | 313 | case 6: { |
Paxtel | 0:8180a93bf2dc | 314 | _A0=1; |
Paxtel | 0:8180a93bf2dc | 315 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 316 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 317 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 318 | _A4=1; |
Paxtel | 0:8180a93bf2dc | 319 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 320 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 321 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 322 | } |
Paxtel | 0:8180a93bf2dc | 323 | break; |
Paxtel | 0:8180a93bf2dc | 324 | case 7: { |
Paxtel | 0:8180a93bf2dc | 325 | _A0=1; |
Paxtel | 0:8180a93bf2dc | 326 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 327 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 328 | _A3=1; |
Paxtel | 0:8180a93bf2dc | 329 | _A4=1; |
Paxtel | 0:8180a93bf2dc | 330 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 331 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 332 | _A7=1; |
Paxtel | 0:8180a93bf2dc | 333 | } |
Paxtel | 0:8180a93bf2dc | 334 | break; |
Paxtel | 0:8180a93bf2dc | 335 | } |
Paxtel | 0:8180a93bf2dc | 336 | |
Paxtel | 0:8180a93bf2dc | 337 | |
Paxtel | 0:8180a93bf2dc | 338 | wait_us(motorSpeed); // velocidad |
Paxtel | 0:8180a93bf2dc | 339 | } |
Paxtel | 0:8180a93bf2dc | 340 | } |
Paxtel | 0:8180a93bf2dc | 341 | |
Paxtel | 0:8180a93bf2dc | 342 | void clockwise() { // rotacion del motor paso a paso sentido horario |
Paxtel | 0:8180a93bf2dc | 343 | for (int i = 7; i >= 0; i--) { |
Paxtel | 0:8180a93bf2dc | 344 | |
Paxtel | 0:8180a93bf2dc | 345 | switch (i) { // activar(1) o desactivar(0) las bobinas |
Paxtel | 0:8180a93bf2dc | 346 | case 0: { |
Paxtel | 0:8180a93bf2dc | 347 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 348 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 349 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 350 | _A3=1; |
Paxtel | 0:8180a93bf2dc | 351 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 352 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 353 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 354 | _A7=1; |
Paxtel | 0:8180a93bf2dc | 355 | } |
Paxtel | 0:8180a93bf2dc | 356 | break; |
Paxtel | 0:8180a93bf2dc | 357 | case 1: { |
Paxtel | 0:8180a93bf2dc | 358 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 359 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 360 | _A2=1; |
Paxtel | 0:8180a93bf2dc | 361 | _A3=1; |
Paxtel | 0:8180a93bf2dc | 362 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 363 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 364 | _A6=1; |
Paxtel | 0:8180a93bf2dc | 365 | _A7=1; |
Paxtel | 0:8180a93bf2dc | 366 | } |
Paxtel | 0:8180a93bf2dc | 367 | break; |
Paxtel | 0:8180a93bf2dc | 368 | case 2: { |
Paxtel | 0:8180a93bf2dc | 369 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 370 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 371 | _A2=1; |
Paxtel | 0:8180a93bf2dc | 372 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 373 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 374 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 375 | _A6=1; |
Paxtel | 0:8180a93bf2dc | 376 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 377 | } |
Paxtel | 0:8180a93bf2dc | 378 | break; |
Paxtel | 0:8180a93bf2dc | 379 | case 3: { |
Paxtel | 0:8180a93bf2dc | 380 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 381 | _A1=1; |
Paxtel | 0:8180a93bf2dc | 382 | _A2=1; |
Paxtel | 0:8180a93bf2dc | 383 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 384 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 385 | _A5=1; |
Paxtel | 0:8180a93bf2dc | 386 | _A6=1; |
Paxtel | 0:8180a93bf2dc | 387 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 388 | } |
Paxtel | 0:8180a93bf2dc | 389 | break; |
Paxtel | 0:8180a93bf2dc | 390 | case 4: { |
Paxtel | 0:8180a93bf2dc | 391 | _A0=0; |
Paxtel | 0:8180a93bf2dc | 392 | _A1=1; |
Paxtel | 0:8180a93bf2dc | 393 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 394 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 395 | _A4=0; |
Paxtel | 0:8180a93bf2dc | 396 | _A5=1; |
Paxtel | 0:8180a93bf2dc | 397 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 398 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 399 | } |
Paxtel | 0:8180a93bf2dc | 400 | break; |
Paxtel | 0:8180a93bf2dc | 401 | case 5: { |
Paxtel | 0:8180a93bf2dc | 402 | _A0=1; |
Paxtel | 0:8180a93bf2dc | 403 | _A1=1; |
Paxtel | 0:8180a93bf2dc | 404 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 405 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 406 | _A4=1; |
Paxtel | 0:8180a93bf2dc | 407 | _A5=1; |
Paxtel | 0:8180a93bf2dc | 408 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 409 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 410 | } |
Paxtel | 0:8180a93bf2dc | 411 | break; |
Paxtel | 0:8180a93bf2dc | 412 | case 6: { |
Paxtel | 0:8180a93bf2dc | 413 | _A0=1; |
Paxtel | 0:8180a93bf2dc | 414 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 415 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 416 | _A3=0; |
Paxtel | 0:8180a93bf2dc | 417 | _A4=1; |
Paxtel | 0:8180a93bf2dc | 418 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 419 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 420 | _A7=0; |
Paxtel | 0:8180a93bf2dc | 421 | } |
Paxtel | 0:8180a93bf2dc | 422 | break; |
Paxtel | 0:8180a93bf2dc | 423 | case 7: { |
Paxtel | 0:8180a93bf2dc | 424 | _A0=1; |
Paxtel | 0:8180a93bf2dc | 425 | _A1=0; |
Paxtel | 0:8180a93bf2dc | 426 | _A2=0; |
Paxtel | 0:8180a93bf2dc | 427 | _A3=1; |
Paxtel | 0:8180a93bf2dc | 428 | _A4=1; |
Paxtel | 0:8180a93bf2dc | 429 | _A5=0; |
Paxtel | 0:8180a93bf2dc | 430 | _A6=0; |
Paxtel | 0:8180a93bf2dc | 431 | _A7=1; |
Paxtel | 0:8180a93bf2dc | 432 | } |
Paxtel | 0:8180a93bf2dc | 433 | break; |
Paxtel | 0:8180a93bf2dc | 434 | } |
Paxtel | 0:8180a93bf2dc | 435 | |
Paxtel | 0:8180a93bf2dc | 436 | |
Paxtel | 0:8180a93bf2dc | 437 | wait_us(motorSpeed); // velocidad de giro |
Paxtel | 0:8180a93bf2dc | 438 | } |
Paxtel | 0:8180a93bf2dc | 439 | } |
Paxtel | 0:8180a93bf2dc | 440 | |
Paxtel | 0:8180a93bf2dc | 441 | |
Paxtel | 0:8180a93bf2dc | 442 | |
Paxtel | 0:8180a93bf2dc | 443 | void stepper(uint8_t num_steps, uint8_t direction) {// funcion para el numero de pasos direccion(0-derecha, 1-izquierda) |
Paxtel | 0:8180a93bf2dc | 444 | int count=0; //inicializar conteo |
Paxtel | 0:8180a93bf2dc | 445 | motorSpeed=1200; //velocidad de giro |
Paxtel | 0:8180a93bf2dc | 446 | if (direction==0) // giro hacia la derecha |
Paxtel | 0:8180a93bf2dc | 447 | do { |
Paxtel | 0:8180a93bf2dc | 448 | clockwise(); |
Paxtel | 0:8180a93bf2dc | 449 | count++; |
Paxtel | 0:8180a93bf2dc | 450 | } while (count<num_steps); // definicion de pasos |
Paxtel | 0:8180a93bf2dc | 451 | else if (direction==1)// giro antihorario |
Paxtel | 0:8180a93bf2dc | 452 | do { |
Paxtel | 0:8180a93bf2dc | 453 | anticlockwise(); |
Paxtel | 0:8180a93bf2dc | 454 | count++; |
Paxtel | 0:8180a93bf2dc | 455 | } while (count<num_steps);// definicion de pasos |
Paxtel | 0:8180a93bf2dc | 456 | |
Paxtel | 0:8180a93bf2dc | 457 | } |
Paxtel | 0:8180a93bf2dc | 458 | |
Paxtel | 0:8180a93bf2dc | 459 | |
Paxtel | 0:8180a93bf2dc | 460 | |
Paxtel | 0:8180a93bf2dc | 461 | |
Paxtel | 0:8180a93bf2dc | 462 | |
Paxtel | 0:8180a93bf2dc | 463 |