Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>

Dependencies:   EthernetNetIf HTTPServer QEI_hw RPCInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
Yo_Robot
Date:
Mon Apr 02 19:47:49 2012 +0000
Parent:
6:b4dae934e1ea
Child:
8:958dfe5052b9
Child:
10:0ebc4955cbe7
Commit message:
v0.2 Serial no RPC. PTO funciona bien, Aout falta revisar.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
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/main.cpp	Sun Apr 01 20:03:42 2012 +0000
+++ b/main.cpp	Mon Apr 02 19:47:49 2012 +0000
@@ -5,15 +5,16 @@
 
 Serial     pc( USBTX, USBRX );
 
-DigitalOut pin_son( p30 );   // SON
-DigitalOut pin_dir( p29 );   // SIGN+
-DigitalIn  pin_alm( p14 );   // ALM 
-AnalogOut  aout( p18 );      // +-10V
+DigitalOut      pin_son( p30 );   // SON
+DigitalOut      pin_dir( p29 );   // SIGN+
+InterruptIn     pin_alm( p14 );   // ALM 
+AnalogOut       aout( p18 );      // 0.0 a 1.0 float
 
 int main() {
         
     setTimer2();
     pc.attach( &ISR_Serial );
+    pin_alm.rise( &ISR_Alarm );
     
     pin_son = 0;     //Inicia apagado
     aout =  0.5;  //Salida en la Mitad.
--- a/setup.cpp	Sun Apr 01 20:03:42 2012 +0000
+++ b/setup.cpp	Mon Apr 02 19:47:49 2012 +0000
@@ -15,10 +15,10 @@
 
 // Salida Serial de mbed
 extern Serial pc;
-extern DigitalOut pin_son;   // SON
-extern DigitalOut pin_dir;   // SIGN+
-extern DigitalIn  pin_alm;   // ALM 
-extern AnalogOut  aout;      // +-10V
+extern DigitalOut   pin_son;   // SON
+extern DigitalOut   pin_dir;   // SIGN+
+extern InterruptIn  pin_alm;   // ALM 
+extern AnalogOut    aout;      // +-10V
 
 
 
@@ -50,66 +50,71 @@
 
     LPC_PINCON->PINSEL0 |= 15UL << 16;  //Activar  MAT2.2 
                                        // y MAT2.3 como salidas
-    
-}
-
-
-void setSON( int onOff )
-{
-    pin_son = onOff;
-}
-
-
-void setDir( int dir )
-{
-    pin_dir = dir;
-}
-
-
-void setAout( float value )
-{
-    aout = value;
-}
-
-
-void ISR_Alarm()
-{
-    pc.printf( "\n\n ERROR: ALARMA \n\n " );
-    
-    setSON( 0 );
-    stopTimer2();
-    setAout( 0.5 );
-    
 }
 
 
 void ISR_Serial()
 {
-    int freq;        //Frecuencia del PTO
-    char command;    //Comando a ejecutar
-    char scale;      //Escala de la frecuencia
+    int value;        // Nuevo Valor
+    char command;     // Comando al que aplicar el nuevo valor
 
-    pc.scanf( "%c%d%c", &command, &freq, &scale ) ;
-    LPC_UART0->FCR = 0x06;
-    pc.printf("\n %c%d%c \n", command, freq, scale );
+    pc.scanf( "%d-%c", &value, &command ) ;
+    pc.printf("\n %d-%c \n", value, command );
 
     // Establecer nueva frecuencia
-    if( command == 'F')
-    {
-       if( scale == 'H' )
-            setMR2( getMRvalue( freq ) );
-       else if( scale == 'K' )
-            setMR2( getMRvalue( freq * 1000 ) );
-    }
+    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 );
     
-    // INICIAR Timer
-    else if( command == 'I')
-        startTimer2( );
+}
+
+
+void setPTO( int freq )
+{
+    if( freq != 0 )
+    {
+        LPC_TIM2->TC = 0x00;  //Resetear Timer
+        setMR2( getMRvalue( freq ) ); 
+        startTimer2();
+    
+    }else{
         
-    // PARAR Timer    
-    else if( command == 'P')
-        stopTimer2( );
-    
+        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  )
@@ -119,9 +124,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 );
+    //pc.printf( "\n\n MR value: %d\n error: %f\n" ,toRegister ,error );
     
     return toRegister;
 }
@@ -137,7 +142,7 @@
 
 void startTimer2()
 {
-    // Arrancer el Timer 2
+    // Arrancar el Timer 2
     LPC_TIM2->TCR = 1;
 }
 
--- a/setup.h	Sun Apr 01 20:03:42 2012 +0000
+++ b/setup.h	Mon Apr 02 19:47:49 2012 +0000
@@ -13,22 +13,10 @@
 void setTimer2();
 
 
-/*@brief: Esta Funcion enciende el pin conectado a la
- *  salida ServoOn.
+/** @brief: Esta es la rutina que cambia la frecuencia
+ *  de salida del Micro
  */
-void setSON( int onOff);
-
-
-/*@brief: Esta Funcion enciende el pin conectado a la
- *  salida de dirección del Servo SIGN+.
- */
-void setDir( int dir );
-
-
-/*@brief: Esta Funcion cambia el valor de la salida 
- *  analógica del mbed
- */
-void setAout( float value );
+void setPTO( int freq );