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