Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>
Dependencies: EthernetNetIf HTTPServer QEI_hw RPCInterface mbed
Diff: setup.cpp
- Revision:
- 8:958dfe5052b9
- Parent:
- 7:d9aca501126f
- Child:
- 9:6976ac1a430e
--- a/setup.cpp Mon Apr 02 19:47:49 2012 +0000 +++ b/setup.cpp Tue Apr 03 00:31:03 2012 +0000 @@ -15,11 +15,6 @@ // Salida Serial de mbed extern Serial pc; -extern DigitalOut pin_son; // SON -extern DigitalOut pin_dir; // SIGN+ -extern InterruptIn pin_alm; // ALM -extern AnalogOut aout; // +-10V - void setTimer2() @@ -49,74 +44,11 @@ // 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 - char command; // Comando al que aplicar el nuevo valor - - pc.scanf( "%d-%c", &value, &command ) ; - pc.printf("\n %d-%c \n", value, command ); - - // Establecer nueva frecuencia - if( command == 'H') - setPTO( value ); - - else if( command == 'K' ) - setPTO( value * 1000 ); - - - - // Nuevo voltaje de salida - // Alguna formula para calcular el Vout necesario - // -100% a +100% - else if( command == 'A') - aout = ( value + 100 ) / 200; - - - // Cambiar la direccion - else if( command == 'D') - pin_dir = value; - - - //Encender el Servo - else if( command == 'S') - pin_son = value; - - //else if( command == 'E') - // setDir( value ); - -} - - -void setPTO( int freq ) -{ - if( freq != 0 ) - { - LPC_TIM2->TC = 0x00; //Resetear Timer - setMR2( getMRvalue( freq ) ); - startTimer2(); - - }else{ - - stopTimer2(); - LPC_TIM2->TC = 0x00; //Resetear Timer - } -} - -void ISR_Alarm() -{ - pin_son = 0 ; - stopTimer2(); - aout = 0.5 ; - - pc.printf( "\n\n ERROR: ALARMA \n\n " ); - -} - int getMRvalue( int fout ) { float exact, error; @@ -124,9 +56,9 @@ exact = (24000000 /(fout*2) ) -1; toRegister = exact; // Valor redondeado; - //error = exact - toRegister; + error = exact - toRegister; - //pc.printf( "\n\n MR value: %d\n error: %f\n" ,toRegister ,error ); + printf( "\n\n MR value: %d\n error: %f\n" ,toRegister ,error ); return toRegister; } @@ -142,7 +74,7 @@ void startTimer2() { - // Arrancar el Timer 2 + // Arrancer el Timer 2 LPC_TIM2->TCR = 1; } @@ -152,10 +84,6 @@ LPC_TIM2->TCR = 0x2; } - - - - /* LEGACY FUNCTIONS * * El codigo actual no hace referencia a estas funciones @@ -171,3 +99,5 @@ { LPC_TIM2->PR = newValue; } + +