Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>
Dependencies: EthernetNetIf HTTPServer QEI_hw RPCInterface mbed
Revision 11:30408c8f722a, committed 2012-04-06
- Comitter:
- Yo_Robot
- Date:
- Fri Apr 06 02:15:47 2012 +0000
- Parent:
- 10:0ebc4955cbe7
- Commit message:
- v0.3 Serial No RPC. Se igualan los archivos setup.h y setup.cpp para serial y ethernet
Changed in this revision
setup.cpp | Show annotated file Show diff for this revision Revisions of this file |
setup.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/setup.cpp Tue Apr 03 01:08:11 2012 +0000 +++ b/setup.cpp Fri Apr 06 02:15:47 2012 +0000 @@ -21,7 +21,6 @@ extern AnalogOut aout; // +-10V - void setTimer2() { // Encender Timer2 (PCONP[22]) @@ -49,10 +48,10 @@ // y MAT2.3 LPC_PINCON->PINSEL0 |= 15UL << 16; //Activar MAT2.2 - // y MAT2.3 como salidas + // y MAT2.3 como salidas + } - void ISR_Serial() { int value; // Nuevo Valor @@ -105,6 +104,24 @@ } } +void setPTO_eth( char * input, char * output ) +{ + int freq = atoi( input ); + + if( freq != 0 ){ + LPC_TIM2->TC = 0x00; // Resetear Timer + setMR2( getMRvalue( freq ) ); // Cambiar frefuencia + startTimer2(); // Iniciar Timer + sprintf( output, "Ok, Freq = %d", freq ); + + }else{ + stopTimer2(); + LPC_TIM2->TC = 0x00; // Resetear Timer + sprintf( output, "Ok, ALTO" ); + } +} + + void ISR_Alarm() { pin_son = 0 ; @@ -117,15 +134,9 @@ int getMRvalue( int fout ) { - float exact, error; int toRegister; - exact = (24000000 /(fout*2) ) -1; - toRegister = exact; // Valor redondeado; - //error = exact - toRegister; - - //pc.printf( "\n\n MR value: %d\n error: %f\n" ,toRegister ,error ); - + toRegister = (24000000 /(fout*2.0) ) -1; return toRegister; } @@ -140,7 +151,7 @@ void startTimer2() { - // Arrancar el Timer 2 + // Arrancer el Timer 2 LPC_TIM2->TCR = 1; } @@ -151,6 +162,43 @@ } +// **** Funciones Liberia Ethernet ***** // + +void setAout_eth( char * input, char * output ) +{ + int vout = atoi( input ); + aout = (float)( vout + 100 ) / 200; + sprintf( output, " Ok, Aout = %f ", aout.read() ); +} + + + +void setDir_eth ( char * input, char * output ) +{ + int value = atoi( input ); + + pin_dir = value; + + if( value == 0 ) + sprintf( output,"Derecha" ); + else + sprintf( output,"Izquierda" ); +} + + + +void setSON_eth ( char * input, char * output ) +{ + int value = atoi( input ); + + pin_son = value; + + if( value == 0 ) + sprintf( output,"Servo OFF" ); + else + sprintf( output,"Servo ON" ); + +}
--- a/setup.h Tue Apr 03 01:08:11 2012 +0000 +++ b/setup.h Fri Apr 06 02:15:47 2012 +0000 @@ -13,12 +13,23 @@ void setTimer2(); +/** @brief: Esta es la rutina que maneja las interrupciones + * seriales, al recibir un caracter. + */ +void ISR_Serial(); + + /** @brief: Esta es la rutina que cambia la frecuencia - * de salida del Micro + * de salida del Micro en Serial */ void setPTO( int freq ); +/** @brief: Esta es la rutina que cambia la frecuencia + * de salida del Micro en comunicacion Ethernet + */ +void setPTO_eth ( char * input, char * output ); + /** @brief: Esta es la rutina que maneja la interrupcion * de alarma @@ -26,28 +37,6 @@ void ISR_Alarm(); - -/** @brief: Esta es la rutina que maneja las interrupciones - * seriales, al recibir un caracter. - */ -void ISR_Serial(); - - -/** @brief: Esta Funcion cambia el valor del Registro 2 - */ -void setMR2( int newValue ); - - -/** @brief: Esta Funcion detiene el timer - */ -void stopTimer2(); - - -/** @brief: Esta Funcion arranca el timer - */ -void startTimer2(); - - /** @brief: Esta Funcion calcula el valor necesario * en el MatchRegister para obtener una frecuencia * de salida. @@ -57,6 +46,41 @@ int getMRvalue( int fout ); +/** @brief: Esta Funcion cambia el valor del Registro 2 + */ +void setMR2( int newValue ); + + +/** @brief: Esta Funcion arranca el timer + */ +void startTimer2(); + + +/** @brief: Esta Funcion detiene el timer + */ +void stopTimer2(); + + +/** @brief: Esta Funcion cambia el voltaje de salida el + * valor ingresado debe ser en porcentaje. + * Desde -100% hasta +100% dependiendo de la velocidad + * y el sentido de giro + */ +void setAout_eth( char * input, char * output ); + + +/** @brief: Cambiar Direccion @ PTO + */ +void setDir_eth ( char * input, char * output ); + + +/** @brief: Cambiar Direccion @ PTO + */ +void setSON_eth ( char * input, char * output ); + + + + // Legacy void setMR3( int newValue ); void setPrescaler( int newValue );