Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>
Dependencies: EthernetNetIf HTTPServer QEI_hw RPCInterface mbed
setup.cpp@19:c26cf8a48986, 2012-05-23 (annotated)
- Committer:
- Yo_Robot
- Date:
- Wed May 23 17:09:28 2012 +0000
- Revision:
- 19:c26cf8a48986
- Parent:
- 18:cf1e07d82630
- Child:
- 20:4b154134ab20
Version 1.5 El Switch de configuracin funciona bien. Archivo de configuracin aun no se prueba. El conector ethernet tiene problemas en la placa 1.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yo_Robot | 4:552beeda4722 | 1 | /** |
Yo_Robot | 4:552beeda4722 | 2 | * @brief Tren de impulsos con Timer2 |
Yo_Robot | 4:552beeda4722 | 3 | * @file setup.cpp |
Yo_Robot | 4:552beeda4722 | 4 | * @author Ernesto Palacios |
Yo_Robot | 4:552beeda4722 | 5 | * |
Yo_Robot | 4:552beeda4722 | 6 | * Created on 25 de Marzo de 2012 |
Yo_Robot | 4:552beeda4722 | 7 | * |
Yo_Robot | 4:552beeda4722 | 8 | * Licencia GPL v3.0 |
Yo_Robot | 4:552beeda4722 | 9 | * http://www.gnu.org/licenses/gpl-3.0.html |
Yo_Robot | 4:552beeda4722 | 10 | */ |
Yo_Robot | 4:552beeda4722 | 11 | |
Yo_Robot | 3:8d5a9e3cd680 | 12 | |
Yo_Robot | 3:8d5a9e3cd680 | 13 | #include "setup.h" |
Yo_Robot | 18:cf1e07d82630 | 14 | #include "EthernetNetIf.h" |
Yo_Robot | 3:8d5a9e3cd680 | 15 | #include "mbed.h" |
Yo_Robot | 3:8d5a9e3cd680 | 16 | |
Yo_Robot | 3:8d5a9e3cd680 | 17 | // Salida Serial de mbed |
Yo_Robot | 19:c26cf8a48986 | 18 | extern Serial pc; |
Yo_Robot | 19:c26cf8a48986 | 19 | extern Serial RS_232; |
Yo_Robot | 19:c26cf8a48986 | 20 | extern DigitalIn isPC; |
Yo_Robot | 12:c02b08dacc45 | 21 | extern DigitalOut pin_son; // SON |
Yo_Robot | 12:c02b08dacc45 | 22 | extern DigitalOut pin_dir; // SIGN+ |
Yo_Robot | 12:c02b08dacc45 | 23 | extern InterruptIn pin_alm; // ALM |
Yo_Robot | 12:c02b08dacc45 | 24 | extern AnalogOut aout; // +-10V |
Yo_Robot | 3:8d5a9e3cd680 | 25 | |
Yo_Robot | 15:a1ffa32ce9d1 | 26 | int fq_posicion = 10000; // Variable global donde se almacenara |
Yo_Robot | 15:a1ffa32ce9d1 | 27 | // la velocidad de posicionamiento en Hz |
Yo_Robot | 15:a1ffa32ce9d1 | 28 | |
Yo_Robot | 3:8d5a9e3cd680 | 29 | |
Yo_Robot | 18:cf1e07d82630 | 30 | EthernetNetIf configurarEthernet() |
Yo_Robot | 18:cf1e07d82630 | 31 | { |
Yo_Robot | 18:cf1e07d82630 | 32 | //____________ *** ARCHIVO DE CONFIGURACION ***_______________________ // |
Yo_Robot | 18:cf1e07d82630 | 33 | |
Yo_Robot | 18:cf1e07d82630 | 34 | printf("\n *** CONFIGURACION ETHERNET DE MBED ***\n"); |
Yo_Robot | 18:cf1e07d82630 | 35 | printf("Leyendo archivo de configuracion...\n\n"); |
Yo_Robot | 18:cf1e07d82630 | 36 | |
Yo_Robot | 18:cf1e07d82630 | 37 | FILE *fp = fopen("/local/config.txt", "r"); // Abre el archivo y lo guarda en fp |
Yo_Robot | 18:cf1e07d82630 | 38 | |
Yo_Robot | 18:cf1e07d82630 | 39 | if(!fp) // En caso de no encontrarse el archivo |
Yo_Robot | 18:cf1e07d82630 | 40 | { |
Yo_Robot | 18:cf1e07d82630 | 41 | printf("\nEl archivo /mbed/config.txt no puede ser abierto!\n"); |
Yo_Robot | 18:cf1e07d82630 | 42 | exit(1); |
Yo_Robot | 18:cf1e07d82630 | 43 | |
Yo_Robot | 18:cf1e07d82630 | 44 | } |
Yo_Robot | 18:cf1e07d82630 | 45 | else |
Yo_Robot | 18:cf1e07d82630 | 46 | { |
Yo_Robot | 18:cf1e07d82630 | 47 | // Cadenas de caracteres desde el Archivo config.txt |
Yo_Robot | 18:cf1e07d82630 | 48 | char isDHCP [15]; //Modo Automatico o Manual |
Yo_Robot | 18:cf1e07d82630 | 49 | char empty [2]; // Linea vacia |
Yo_Robot | 18:cf1e07d82630 | 50 | char ip [40]; // Direccion IP |
Yo_Robot | 18:cf1e07d82630 | 51 | char mask [40]; // Mascara de Subred |
Yo_Robot | 18:cf1e07d82630 | 52 | char gate [40]; // Puerta de enlace |
Yo_Robot | 18:cf1e07d82630 | 53 | char dns [40]; // Direccion DNS |
Yo_Robot | 18:cf1e07d82630 | 54 | |
Yo_Robot | 18:cf1e07d82630 | 55 | // Valores 'int' para agregar a la configuracion manual |
Yo_Robot | 18:cf1e07d82630 | 56 | int DHCP; |
Yo_Robot | 18:cf1e07d82630 | 57 | int n_ip[4]; |
Yo_Robot | 18:cf1e07d82630 | 58 | int n_mask[4]; |
Yo_Robot | 18:cf1e07d82630 | 59 | int n_gate[4]; |
Yo_Robot | 18:cf1e07d82630 | 60 | int n_dns[4]; |
Yo_Robot | 18:cf1e07d82630 | 61 | |
Yo_Robot | 18:cf1e07d82630 | 62 | |
Yo_Robot | 18:cf1e07d82630 | 63 | // Leer linea a linea el archivo |
Yo_Robot | 18:cf1e07d82630 | 64 | fgets( isDHCP, 15, fp ); |
Yo_Robot | 18:cf1e07d82630 | 65 | fgets( empty, 2, fp ); |
Yo_Robot | 18:cf1e07d82630 | 66 | fgets( ip, 40, fp ); |
Yo_Robot | 18:cf1e07d82630 | 67 | fgets( mask, 40, fp ); |
Yo_Robot | 18:cf1e07d82630 | 68 | fgets( gate, 40, fp ); |
Yo_Robot | 18:cf1e07d82630 | 69 | fgets( dns, 40, fp ); |
Yo_Robot | 18:cf1e07d82630 | 70 | |
Yo_Robot | 18:cf1e07d82630 | 71 | printf("Cerrando archivo...\n"); |
Yo_Robot | 18:cf1e07d82630 | 72 | fclose(fp); |
Yo_Robot | 18:cf1e07d82630 | 73 | |
Yo_Robot | 18:cf1e07d82630 | 74 | // Extraer los valores numericos |
Yo_Robot | 18:cf1e07d82630 | 75 | sscanf( isDHCP,"%*s %d",&DHCP ); |
Yo_Robot | 18:cf1e07d82630 | 76 | |
Yo_Robot | 18:cf1e07d82630 | 77 | sscanf( ip,"%*s %d.%d.%d.%d",&n_ip[0],&n_ip[1],&n_ip[2],&n_ip[3] ); |
Yo_Robot | 18:cf1e07d82630 | 78 | sscanf( mask,"%*s %d.%d.%d.%d",&n_mask[0],&n_mask[1],&n_mask[2],&n_mask[3] ); |
Yo_Robot | 18:cf1e07d82630 | 79 | sscanf( gate,"%*s %d.%d.%d.%d",&n_gate[0],&n_gate[1],&n_gate[2],&n_gate[3] ); |
Yo_Robot | 18:cf1e07d82630 | 80 | sscanf( dns,"%*s %d.%d.%d.%d",&n_dns[0],&n_dns[1],&n_dns[2],&n_dns[3] ); |
Yo_Robot | 18:cf1e07d82630 | 81 | |
Yo_Robot | 18:cf1e07d82630 | 82 | |
Yo_Robot | 18:cf1e07d82630 | 83 | if(DHCP) //En caso de modo DHCP |
Yo_Robot | 18:cf1e07d82630 | 84 | { |
Yo_Robot | 18:cf1e07d82630 | 85 | printf("\n Configurar red de manera automatica\n"); |
Yo_Robot | 18:cf1e07d82630 | 86 | EthernetNetIf eth; //Crea la interfaz |
Yo_Robot | 18:cf1e07d82630 | 87 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 18:cf1e07d82630 | 88 | if( ethErr ) |
Yo_Robot | 18:cf1e07d82630 | 89 | { |
Yo_Robot | 18:cf1e07d82630 | 90 | printf( "Error %d en la configuracion\n", ethErr ); |
Yo_Robot | 18:cf1e07d82630 | 91 | exit(1); |
Yo_Robot | 18:cf1e07d82630 | 92 | } |
Yo_Robot | 18:cf1e07d82630 | 93 | |
Yo_Robot | 18:cf1e07d82630 | 94 | printf("Configuracion Correcta\n\n"); |
Yo_Robot | 18:cf1e07d82630 | 95 | return eth; |
Yo_Robot | 18:cf1e07d82630 | 96 | } |
Yo_Robot | 18:cf1e07d82630 | 97 | else |
Yo_Robot | 18:cf1e07d82630 | 98 | { |
Yo_Robot | 18:cf1e07d82630 | 99 | sscanf( ip,"%*s %d.%d.%d.%d",&n_ip[0], &n_ip[1], &n_ip[2], &n_ip[3] ); |
Yo_Robot | 18:cf1e07d82630 | 100 | sscanf( mask,"%*s %d.%d.%d.%d",&n_mask[0],&n_mask[1],&n_mask[2],&n_mask[3] ); |
Yo_Robot | 18:cf1e07d82630 | 101 | sscanf( gate,"%*s %d.%d.%d.%d",&n_gate[0],&n_gate[1],&n_gate[2],&n_gate[3] ); |
Yo_Robot | 18:cf1e07d82630 | 102 | sscanf( dns,"%*s %d.%d.%d.%d",&n_dns[0], &n_dns[1], &n_dns[2], &n_dns[3] ); |
Yo_Robot | 18:cf1e07d82630 | 103 | printf(" %s %s %s %s %s\n " , isDHCP, ip, mask, gate, dns ); |
Yo_Robot | 18:cf1e07d82630 | 104 | |
Yo_Robot | 18:cf1e07d82630 | 105 | printf("\n Configurar red de manera manual\n"); |
Yo_Robot | 18:cf1e07d82630 | 106 | EthernetNetIf eth( |
Yo_Robot | 18:cf1e07d82630 | 107 | IpAddr( n_ip[0], n_ip[1], n_ip[2], n_ip[3]), //IP Address |
Yo_Robot | 18:cf1e07d82630 | 108 | IpAddr( n_mask[0],n_mask[1],n_mask[2],n_mask[3]), //Network Mask |
Yo_Robot | 18:cf1e07d82630 | 109 | IpAddr( n_gate[0],n_gate[1],n_gate[2],n_gate[3]), //Gateway |
Yo_Robot | 18:cf1e07d82630 | 110 | IpAddr( n_dns[0], n_dns[1], n_dns[2], n_dns[3] ) //DNS |
Yo_Robot | 18:cf1e07d82630 | 111 | ); |
Yo_Robot | 18:cf1e07d82630 | 112 | |
Yo_Robot | 18:cf1e07d82630 | 113 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 18:cf1e07d82630 | 114 | if( ethErr ) |
Yo_Robot | 18:cf1e07d82630 | 115 | { |
Yo_Robot | 18:cf1e07d82630 | 116 | printf( "Error %d en la configuracion\n", ethErr ); |
Yo_Robot | 18:cf1e07d82630 | 117 | exit(1); |
Yo_Robot | 18:cf1e07d82630 | 118 | } |
Yo_Robot | 18:cf1e07d82630 | 119 | |
Yo_Robot | 18:cf1e07d82630 | 120 | printf("Configuracion Correcta\n\n"); |
Yo_Robot | 18:cf1e07d82630 | 121 | return eth; |
Yo_Robot | 18:cf1e07d82630 | 122 | } |
Yo_Robot | 18:cf1e07d82630 | 123 | |
Yo_Robot | 18:cf1e07d82630 | 124 | } |
Yo_Robot | 19:c26cf8a48986 | 125 | |
Yo_Robot | 18:cf1e07d82630 | 126 | EthernetNetIf eth; |
Yo_Robot | 18:cf1e07d82630 | 127 | return eth; |
Yo_Robot | 18:cf1e07d82630 | 128 | } |
Yo_Robot | 18:cf1e07d82630 | 129 | |
Yo_Robot | 18:cf1e07d82630 | 130 | |
Yo_Robot | 4:552beeda4722 | 131 | void setTimer2() |
Yo_Robot | 3:8d5a9e3cd680 | 132 | { |
Yo_Robot | 3:8d5a9e3cd680 | 133 | // Encender Timer2 (PCONP[22]) |
Yo_Robot | 3:8d5a9e3cd680 | 134 | LPC_SC->PCONP |= 1 << 22; |
Yo_Robot | 3:8d5a9e3cd680 | 135 | |
Yo_Robot | 3:8d5a9e3cd680 | 136 | // Resetear y parar el Timer |
Yo_Robot | 3:8d5a9e3cd680 | 137 | LPC_TIM2->TCR = 0x2; |
Yo_Robot | 3:8d5a9e3cd680 | 138 | LPC_TIM2->CTCR = 0x0; |
Yo_Robot | 3:8d5a9e3cd680 | 139 | |
Yo_Robot | 4:552beeda4722 | 140 | // Establecer el Preescaler en cero |
Yo_Robot | 4:552beeda4722 | 141 | // SIn Preesclaer |
Yo_Robot | 4:552beeda4722 | 142 | LPC_TIM2->PR = 0; |
Yo_Robot | 3:8d5a9e3cd680 | 143 | |
Yo_Robot | 4:552beeda4722 | 144 | // Calcular el periodo Inicial |
Yo_Robot | 4:552beeda4722 | 145 | uint32_t periodo = ( SystemCoreClock / 400 ); |
Yo_Robot | 3:8d5a9e3cd680 | 146 | |
Yo_Robot | 3:8d5a9e3cd680 | 147 | // Establecer los Registros de Coincidencia |
Yo_Robot | 3:8d5a9e3cd680 | 148 | // ( Match Register ) |
Yo_Robot | 3:8d5a9e3cd680 | 149 | LPC_TIM2->MR2 = periodo; |
Yo_Robot | 4:552beeda4722 | 150 | LPC_TIM2->MR3 = periodo; // Legacy, salidas identicas |
Yo_Robot | 3:8d5a9e3cd680 | 151 | |
Yo_Robot | 4:552beeda4722 | 152 | LPC_TIM2->MCR |= 1 << 7; // Resetear Timer en MR2 |
Yo_Robot | 3:8d5a9e3cd680 | 153 | |
Yo_Robot | 3:8d5a9e3cd680 | 154 | LPC_TIM2->EMR |= 15UL << 8; // Alternar Pin MAT2.2 |
Yo_Robot | 3:8d5a9e3cd680 | 155 | // y MAT2.3 |
Yo_Robot | 3:8d5a9e3cd680 | 156 | |
Yo_Robot | 3:8d5a9e3cd680 | 157 | LPC_PINCON->PINSEL0 |= 15UL << 16; //Activar MAT2.2 |
Yo_Robot | 8:958dfe5052b9 | 158 | // y MAT2.3 como salidas |
Yo_Robot | 8:958dfe5052b9 | 159 | |
Yo_Robot | 6:b4dae934e1ea | 160 | } |
Yo_Robot | 6:b4dae934e1ea | 161 | |
Yo_Robot | 12:c02b08dacc45 | 162 | void ISR_Serial() |
Yo_Robot | 12:c02b08dacc45 | 163 | { |
Yo_Robot | 12:c02b08dacc45 | 164 | int value; // Nuevo Valor |
Yo_Robot | 12:c02b08dacc45 | 165 | char command; // Comando al que aplicar el nuevo valor |
Yo_Robot | 12:c02b08dacc45 | 166 | |
Yo_Robot | 19:c26cf8a48986 | 167 | if( isPC ) |
Yo_Robot | 19:c26cf8a48986 | 168 | pc.scanf( "%d-%c", &value, &command ) ; |
Yo_Robot | 19:c26cf8a48986 | 169 | else |
Yo_Robot | 19:c26cf8a48986 | 170 | RS_232.scanf( "%d-%c", &value, &command ) ; |
Yo_Robot | 19:c26cf8a48986 | 171 | |
Yo_Robot | 12:c02b08dacc45 | 172 | // Establecer nueva frecuencia |
Yo_Robot | 12:c02b08dacc45 | 173 | if( command == 'H') |
Yo_Robot | 12:c02b08dacc45 | 174 | setPTO( value ); |
Yo_Robot | 12:c02b08dacc45 | 175 | |
Yo_Robot | 12:c02b08dacc45 | 176 | else if( command == 'K' ) |
Yo_Robot | 12:c02b08dacc45 | 177 | setPTO( value * 1000 ); |
Yo_Robot | 12:c02b08dacc45 | 178 | |
Yo_Robot | 12:c02b08dacc45 | 179 | // Nuevo voltaje de salida |
Yo_Robot | 12:c02b08dacc45 | 180 | // Alguna formula para calcular el Vout necesario |
Yo_Robot | 12:c02b08dacc45 | 181 | // -100% a +100% |
Yo_Robot | 12:c02b08dacc45 | 182 | else if( command == 'A') |
Yo_Robot | 14:039d070732d5 | 183 | aout = (float)( value + 10000.0 ) / 20000.0; |
Yo_Robot | 12:c02b08dacc45 | 184 | |
Yo_Robot | 12:c02b08dacc45 | 185 | |
Yo_Robot | 12:c02b08dacc45 | 186 | // Cambiar la direccion |
Yo_Robot | 12:c02b08dacc45 | 187 | else if( command == 'D') |
Yo_Robot | 14:039d070732d5 | 188 | { |
Yo_Robot | 14:039d070732d5 | 189 | stopTimer2(); |
Yo_Robot | 12:c02b08dacc45 | 190 | pin_dir = value; |
Yo_Robot | 14:039d070732d5 | 191 | wait_us( 2 ); |
Yo_Robot | 14:039d070732d5 | 192 | startTimer2(); |
Yo_Robot | 14:039d070732d5 | 193 | } |
Yo_Robot | 14:039d070732d5 | 194 | |
Yo_Robot | 12:c02b08dacc45 | 195 | |
Yo_Robot | 12:c02b08dacc45 | 196 | //Encender el Servo |
Yo_Robot | 12:c02b08dacc45 | 197 | else if( command == 'S') |
Yo_Robot | 12:c02b08dacc45 | 198 | pin_son = value; |
Yo_Robot | 12:c02b08dacc45 | 199 | |
Yo_Robot | 18:cf1e07d82630 | 200 | else if( command == 'V') |
Yo_Robot | 18:cf1e07d82630 | 201 | fq_posicion = value; |
Yo_Robot | 18:cf1e07d82630 | 202 | |
Yo_Robot | 18:cf1e07d82630 | 203 | else if( command == 'G' ) |
Yo_Robot | 18:cf1e07d82630 | 204 | { |
Yo_Robot | 18:cf1e07d82630 | 205 | int pulsos = value; //Numero de pulsos a generar |
Yo_Robot | 18:cf1e07d82630 | 206 | float t_alto = pulsos / fq_posicion; //Tiempo que debe ser generado el tren de pulsos. |
Yo_Robot | 12:c02b08dacc45 | 207 | |
Yo_Robot | 18:cf1e07d82630 | 208 | stopTimer2(); //Deten el tren de pulsos |
Yo_Robot | 18:cf1e07d82630 | 209 | setPTO( fq_posicion ); //Nueva frecuencia de salida |
Yo_Robot | 18:cf1e07d82630 | 210 | startTimer2(); //Inicia el tren de pulsos |
Yo_Robot | 18:cf1e07d82630 | 211 | wait( t_alto ); //Espera hasta llegar a la posicion |
Yo_Robot | 18:cf1e07d82630 | 212 | stopTimer2(); //Posicion alcanzada ALTO. |
Yo_Robot | 18:cf1e07d82630 | 213 | } |
Yo_Robot | 12:c02b08dacc45 | 214 | } |
Yo_Robot | 12:c02b08dacc45 | 215 | |
Yo_Robot | 12:c02b08dacc45 | 216 | |
Yo_Robot | 12:c02b08dacc45 | 217 | void setPTO( int freq ) |
Yo_Robot | 12:c02b08dacc45 | 218 | { |
Yo_Robot | 12:c02b08dacc45 | 219 | if( freq != 0 ) |
Yo_Robot | 12:c02b08dacc45 | 220 | { |
Yo_Robot | 12:c02b08dacc45 | 221 | LPC_TIM2->TC = 0x00; //Resetear Timer |
Yo_Robot | 12:c02b08dacc45 | 222 | setMR2( getMRvalue( freq ) ); |
Yo_Robot | 12:c02b08dacc45 | 223 | startTimer2(); |
Yo_Robot | 12:c02b08dacc45 | 224 | |
Yo_Robot | 12:c02b08dacc45 | 225 | }else{ |
Yo_Robot | 12:c02b08dacc45 | 226 | |
Yo_Robot | 12:c02b08dacc45 | 227 | stopTimer2(); |
Yo_Robot | 12:c02b08dacc45 | 228 | LPC_TIM2->TC = 0x00; //Resetear Timer |
Yo_Robot | 12:c02b08dacc45 | 229 | } |
Yo_Robot | 12:c02b08dacc45 | 230 | } |
Yo_Robot | 12:c02b08dacc45 | 231 | |
Yo_Robot | 12:c02b08dacc45 | 232 | void setPTO_eth( char * input, char * output ) |
Yo_Robot | 12:c02b08dacc45 | 233 | { |
Yo_Robot | 12:c02b08dacc45 | 234 | int freq = atoi( input ); |
Yo_Robot | 12:c02b08dacc45 | 235 | |
Yo_Robot | 12:c02b08dacc45 | 236 | if( freq != 0 ){ |
Yo_Robot | 12:c02b08dacc45 | 237 | LPC_TIM2->TC = 0x00; // Resetear Timer |
Yo_Robot | 12:c02b08dacc45 | 238 | setMR2( getMRvalue( freq ) ); // Cambiar frefuencia |
Yo_Robot | 12:c02b08dacc45 | 239 | startTimer2(); // Iniciar Timer |
Yo_Robot | 14:039d070732d5 | 240 | if( pin_alm == 0 ) |
Yo_Robot | 14:039d070732d5 | 241 | sprintf( output,"Ok" ); |
Yo_Robot | 14:039d070732d5 | 242 | else |
Yo_Robot | 14:039d070732d5 | 243 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 244 | }else{ |
Yo_Robot | 12:c02b08dacc45 | 245 | stopTimer2(); |
Yo_Robot | 12:c02b08dacc45 | 246 | LPC_TIM2->TC = 0x00; // Resetear Timer |
Yo_Robot | 14:039d070732d5 | 247 | if( pin_alm == 0 ) |
Yo_Robot | 14:039d070732d5 | 248 | sprintf( output,"Ok" ); |
Yo_Robot | 14:039d070732d5 | 249 | else |
Yo_Robot | 14:039d070732d5 | 250 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 251 | } |
Yo_Robot | 12:c02b08dacc45 | 252 | } |
Yo_Robot | 12:c02b08dacc45 | 253 | |
Yo_Robot | 15:a1ffa32ce9d1 | 254 | void setANG_eth( char * input, char * output ) |
Yo_Robot | 15:a1ffa32ce9d1 | 255 | { |
Yo_Robot | 15:a1ffa32ce9d1 | 256 | long int pulsos = atol( input ); //Numero de pulsos a generar |
Yo_Robot | 15:a1ffa32ce9d1 | 257 | float t_alto = pulsos / fq_posicion; //Tiempo que debe ser generado el tren de pulsos. |
Yo_Robot | 15:a1ffa32ce9d1 | 258 | |
Yo_Robot | 15:a1ffa32ce9d1 | 259 | stopTimer2(); //Deten el tren de pulsos |
Yo_Robot | 15:a1ffa32ce9d1 | 260 | setPTO( fq_posicion ); //Nueva frecuencia de salida |
Yo_Robot | 15:a1ffa32ce9d1 | 261 | startTimer2(); //Inicia el tren de pulsos |
Yo_Robot | 15:a1ffa32ce9d1 | 262 | wait( t_alto ); //Espera hasta llegar a la posicion |
Yo_Robot | 18:cf1e07d82630 | 263 | stopTimer2(); //Posicion alcanzada ALTO. |
Yo_Robot | 15:a1ffa32ce9d1 | 264 | |
Yo_Robot | 15:a1ffa32ce9d1 | 265 | if( pin_alm == 0 ) |
Yo_Robot | 15:a1ffa32ce9d1 | 266 | sprintf( output,"Ok" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 267 | else |
Yo_Robot | 15:a1ffa32ce9d1 | 268 | sprintf( output,"AL" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 269 | |
Yo_Robot | 15:a1ffa32ce9d1 | 270 | } |
Yo_Robot | 15:a1ffa32ce9d1 | 271 | void setSPD_eth( char * input, char * output ) |
Yo_Robot | 15:a1ffa32ce9d1 | 272 | { |
Yo_Robot | 15:a1ffa32ce9d1 | 273 | fq_posicion = atoi( input ); |
Yo_Robot | 15:a1ffa32ce9d1 | 274 | // Esta funcion cambia la velocidad con la que se |
Yo_Robot | 15:a1ffa32ce9d1 | 275 | // posicionara el eje del motor en un angulo determinado |
Yo_Robot | 15:a1ffa32ce9d1 | 276 | if( pin_alm == 0 ) |
Yo_Robot | 15:a1ffa32ce9d1 | 277 | sprintf( output,"Ok" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 278 | else |
Yo_Robot | 15:a1ffa32ce9d1 | 279 | sprintf( output,"AL" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 280 | |
Yo_Robot | 15:a1ffa32ce9d1 | 281 | } |
Yo_Robot | 15:a1ffa32ce9d1 | 282 | void getENC_eth( char * input, char * output ) |
Yo_Robot | 15:a1ffa32ce9d1 | 283 | { |
Yo_Robot | 15:a1ffa32ce9d1 | 284 | //Leer el Encoder ******* F A L T A |
Yo_Robot | 15:a1ffa32ce9d1 | 285 | if( pin_alm == 0 ) |
Yo_Robot | 15:a1ffa32ce9d1 | 286 | sprintf( output,"Ok" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 287 | else |
Yo_Robot | 15:a1ffa32ce9d1 | 288 | sprintf( output,"AL" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 289 | |
Yo_Robot | 15:a1ffa32ce9d1 | 290 | } |
Yo_Robot | 15:a1ffa32ce9d1 | 291 | |
Yo_Robot | 12:c02b08dacc45 | 292 | |
Yo_Robot | 12:c02b08dacc45 | 293 | void ISR_Alarm() |
Yo_Robot | 12:c02b08dacc45 | 294 | { |
Yo_Robot | 12:c02b08dacc45 | 295 | pin_son = 0 ; |
Yo_Robot | 12:c02b08dacc45 | 296 | stopTimer2(); |
Yo_Robot | 12:c02b08dacc45 | 297 | aout = 0.5 ; |
Yo_Robot | 12:c02b08dacc45 | 298 | |
Yo_Robot | 19:c26cf8a48986 | 299 | if(isPC) |
Yo_Robot | 19:c26cf8a48986 | 300 | pc.printf( "AL" ); //ALARMA! solo es AL para que |
Yo_Robot | 19:c26cf8a48986 | 301 | //sea conciso con el modo ETH y funcione |
Yo_Robot | 19:c26cf8a48986 | 302 | //bien en LabVIEW. |
Yo_Robot | 19:c26cf8a48986 | 303 | else |
Yo_Robot | 19:c26cf8a48986 | 304 | RS_232.printf( "AL" ); |
Yo_Robot | 12:c02b08dacc45 | 305 | } |
Yo_Robot | 6:b4dae934e1ea | 306 | |
Yo_Robot | 4:552beeda4722 | 307 | int getMRvalue( int fout ) |
Yo_Robot | 3:8d5a9e3cd680 | 308 | { |
Yo_Robot | 4:552beeda4722 | 309 | int toRegister; |
Yo_Robot | 4:552beeda4722 | 310 | |
Yo_Robot | 12:c02b08dacc45 | 311 | toRegister = (24000000 /(fout*2.0) ) -1; |
Yo_Robot | 4:552beeda4722 | 312 | return toRegister; |
Yo_Robot | 3:8d5a9e3cd680 | 313 | } |
Yo_Robot | 3:8d5a9e3cd680 | 314 | |
Yo_Robot | 3:8d5a9e3cd680 | 315 | |
Yo_Robot | 3:8d5a9e3cd680 | 316 | void setMR2( int newValue ) |
Yo_Robot | 3:8d5a9e3cd680 | 317 | { |
Yo_Robot | 4:552beeda4722 | 318 | LPC_TIM2->MR2 = newValue; // Las dos salidas son identicas |
Yo_Robot | 4:552beeda4722 | 319 | LPC_TIM2->MR3 = newValue; // Para testear el programa. |
Yo_Robot | 3:8d5a9e3cd680 | 320 | } |
Yo_Robot | 3:8d5a9e3cd680 | 321 | |
Yo_Robot | 3:8d5a9e3cd680 | 322 | |
Yo_Robot | 3:8d5a9e3cd680 | 323 | |
Yo_Robot | 3:8d5a9e3cd680 | 324 | void startTimer2() |
Yo_Robot | 3:8d5a9e3cd680 | 325 | { |
Yo_Robot | 8:958dfe5052b9 | 326 | // Arrancer el Timer 2 |
Yo_Robot | 3:8d5a9e3cd680 | 327 | LPC_TIM2->TCR = 1; |
Yo_Robot | 3:8d5a9e3cd680 | 328 | } |
Yo_Robot | 3:8d5a9e3cd680 | 329 | |
Yo_Robot | 3:8d5a9e3cd680 | 330 | void stopTimer2() |
Yo_Robot | 3:8d5a9e3cd680 | 331 | { |
Yo_Robot | 4:552beeda4722 | 332 | // Detener el Timer 2 |
Yo_Robot | 3:8d5a9e3cd680 | 333 | LPC_TIM2->TCR = 0x2; |
Yo_Robot | 4:552beeda4722 | 334 | } |
Yo_Robot | 4:552beeda4722 | 335 | |
Yo_Robot | 12:c02b08dacc45 | 336 | |
Yo_Robot | 12:c02b08dacc45 | 337 | // **** Funciones Liberia Ethernet ***** // |
Yo_Robot | 12:c02b08dacc45 | 338 | |
Yo_Robot | 12:c02b08dacc45 | 339 | void setAout_eth( char * input, char * output ) |
Yo_Robot | 12:c02b08dacc45 | 340 | { |
Yo_Robot | 12:c02b08dacc45 | 341 | int vout = atoi( input ); |
Yo_Robot | 14:039d070732d5 | 342 | aout = (float)( vout + 10000 ) / 20000; |
Yo_Robot | 14:039d070732d5 | 343 | if( pin_alm == 0 ) |
Yo_Robot | 14:039d070732d5 | 344 | sprintf( output,"Ok" ); |
Yo_Robot | 14:039d070732d5 | 345 | else |
Yo_Robot | 14:039d070732d5 | 346 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 347 | } |
Yo_Robot | 12:c02b08dacc45 | 348 | |
Yo_Robot | 12:c02b08dacc45 | 349 | |
Yo_Robot | 12:c02b08dacc45 | 350 | |
Yo_Robot | 12:c02b08dacc45 | 351 | void setDir_eth ( char * input, char * output ) |
Yo_Robot | 12:c02b08dacc45 | 352 | { |
Yo_Robot | 12:c02b08dacc45 | 353 | int value = atoi( input ); |
Yo_Robot | 12:c02b08dacc45 | 354 | |
Yo_Robot | 12:c02b08dacc45 | 355 | pin_dir = value; |
Yo_Robot | 12:c02b08dacc45 | 356 | |
Yo_Robot | 14:039d070732d5 | 357 | if( pin_alm == 0 ) |
Yo_Robot | 14:039d070732d5 | 358 | sprintf( output,"Ok" ); |
Yo_Robot | 12:c02b08dacc45 | 359 | else |
Yo_Robot | 14:039d070732d5 | 360 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 361 | } |
Yo_Robot | 12:c02b08dacc45 | 362 | |
Yo_Robot | 12:c02b08dacc45 | 363 | |
Yo_Robot | 12:c02b08dacc45 | 364 | |
Yo_Robot | 12:c02b08dacc45 | 365 | void setSON_eth ( char * input, char * output ) |
Yo_Robot | 12:c02b08dacc45 | 366 | { |
Yo_Robot | 12:c02b08dacc45 | 367 | int value = atoi( input ); |
Yo_Robot | 12:c02b08dacc45 | 368 | |
Yo_Robot | 12:c02b08dacc45 | 369 | pin_son = value; |
Yo_Robot | 12:c02b08dacc45 | 370 | |
Yo_Robot | 14:039d070732d5 | 371 | if( pin_alm == 0 ) |
Yo_Robot | 14:039d070732d5 | 372 | sprintf( output,"Ok" ); |
Yo_Robot | 12:c02b08dacc45 | 373 | else |
Yo_Robot | 14:039d070732d5 | 374 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 375 | |
Yo_Robot | 12:c02b08dacc45 | 376 | } |
Yo_Robot | 12:c02b08dacc45 | 377 | |
Yo_Robot | 12:c02b08dacc45 | 378 | |
Yo_Robot | 12:c02b08dacc45 | 379 | |
Yo_Robot | 4:552beeda4722 | 380 | /* LEGACY FUNCTIONS |
Yo_Robot | 4:552beeda4722 | 381 | * |
Yo_Robot | 5:c5aea1eb10bb | 382 | * El codigo actual no hace referencia a estas funciones |
Yo_Robot | 5:c5aea1eb10bb | 383 | * sin embargo no hay problema en definirlas. |
Yo_Robot | 4:552beeda4722 | 384 | */ |
Yo_Robot | 4:552beeda4722 | 385 | void setMR3( int newValue ) |
Yo_Robot | 4:552beeda4722 | 386 | { |
Yo_Robot | 4:552beeda4722 | 387 | LPC_TIM2->MR3 = newValue; |
Yo_Robot | 4:552beeda4722 | 388 | } |
Yo_Robot | 4:552beeda4722 | 389 | |
Yo_Robot | 4:552beeda4722 | 390 | |
Yo_Robot | 4:552beeda4722 | 391 | void setPrescaler( int newValue) |
Yo_Robot | 4:552beeda4722 | 392 | { |
Yo_Robot | 4:552beeda4722 | 393 | LPC_TIM2->PR = newValue; |
Yo_Robot | 4:552beeda4722 | 394 | } |