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:
6:b4dae934e1ea
Parent:
5:c5aea1eb10bb
Child:
7:d9aca501126f
--- a/setup.cpp	Wed Mar 28 23:13:53 2012 +0000
+++ b/setup.cpp	Sun Apr 01 20:03:42 2012 +0000
@@ -15,6 +15,11 @@
 
 // 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
+
 
 
 void setTimer2()
@@ -44,11 +49,69 @@
                                 //      y MAT2.3
 
     LPC_PINCON->PINSEL0 |= 15UL << 16;  //Activar  MAT2.2 
-                                      // y MAT2.3 como salidas
-   
+                                       // 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
+
+    pc.scanf( "%c%d%c", &command, &freq, &scale ) ;
+    LPC_UART0->FCR = 0x06;
+    pc.printf("\n %c%d%c \n", command, freq, scale );
+
+    // Establecer nueva frecuencia
+    if( command == 'F')
+    {
+       if( scale == 'H' )
+            setMR2( getMRvalue( freq ) );
+       else if( scale == 'K' )
+            setMR2( getMRvalue( freq * 1000 ) );
+    }
+    
+    // INICIAR Timer
+    else if( command == 'I')
+        startTimer2( );
+        
+    // PARAR Timer    
+    else if( command == 'P')
+        stopTimer2( );
+    
+}
+
 int getMRvalue( int fout  )
 {
     float exact, error;
@@ -58,7 +121,7 @@
     toRegister = exact;  // Valor redondeado;
     error = exact - toRegister;
        
-    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;
 }
@@ -84,6 +147,10 @@
     LPC_TIM2->TCR = 0x2;
 }
 
+
+
+
+
 /*  LEGACY FUNCTIONS
  *
  *  El codigo actual no hace referencia a estas funciones
@@ -99,5 +166,3 @@
 {
     LPC_TIM2->PR = newValue; 
 }
-
-