Diego Carvajal / Mbed 2 deprecated Tarea_Encoder

Dependencies:   Debounced QEI TextLCD mbed

Revision:
0:a7b349b8861d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 04 16:57:20 2014 +0000
@@ -0,0 +1,156 @@
+/* Tarea No. 4
+                Diego Fernando Carvajal Castrillón
+                    Santiago Lopez Restrepo
+                    Ingeniería de Control
+
+
+Practica realizada para aprendizaje de manejo de Encoder. El desarrollo
+de esta esta dado por el aumento y disminución de los datos del 
+controlador PID, además que al presionar el boton del Encoder suene
+mediante un PWM.
+*/
+
+
+#include "mbed.h"
+#include "DebouncedIn.h"
+#include "TextLCD.h"
+#include "QEI.h"
+
+
+QEI wheel (PTA16, PTA17, NC, 48);
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
+
+
+DebouncedIn botonEncoder(PTC5);
+PwmOut Pwm(PTA5);
+
+ 
+float periodo=0.001;
+float dureza=0.1;
+int Spbias=0,Sp=0,Kpbias=0,Kp=0,Ki=0,Kibias=0,Kd=0,Kdbias=0,Enc;
+int C1=0x0E; // solo muestra el curzor
+int i; // indice de la variable
+
+int PWMmodule(float pp,float Dd)
+{
+        Pwm.period(periodo);
+        Pwm.write(dureza);
+        wait(0.3);
+        Pwm.write(0); 
+        return 0;
+} 
+
+int main() 
+
+{
+    lcd.writeCommand(C1);
+    lcd.locate(0,0);
+    lcd.printf("Sp=0");
+    lcd.locate(8,0);
+    lcd.printf("Kp=0");
+    lcd.locate(0,1);
+    lcd.printf("Ki=0");
+    lcd.locate(8,1);
+    lcd.printf("Kd=0");
+
+    while(1) 
+    {  
+     Enc=wheel.getPulses();
+       
+                                                
+            switch(i) {
+            
+                case 0:
+                    Kdbias=Kd;
+                    
+                    lcd.locate(3,0);
+                    lcd.printf("%d",Sp);
+                    
+                    Sp=Spbias+Enc;  
+                    if(Sp<0)
+                    {
+                        Sp=0; 
+                        wheel.reset();  
+                        Enc=0; 
+                    }                
+                    break;
+                case 1:
+                    Spbias=Sp;
+                    lcd.locate(11,0);
+                    lcd.printf("%d",Kp);
+                    
+                    Kp=Kpbias+Enc;  
+                    if(Kp<0)
+                    {
+                        Kp=0; 
+                        wheel.reset();  
+                        Enc=0; 
+                    }  
+                    break;
+                case 2:
+                    Kpbias=Kp;
+                    lcd.locate(3,1);
+                    lcd.printf("%d",Ki);
+                    
+                    Ki=Kibias+Enc;  
+                    if(Ki<0)
+                    {
+                        Ki=0; 
+                        wheel.reset();  
+                        Enc=0; 
+                    } 
+                    
+                    break;
+                case 3:
+                    Kibias=Ki;
+                    
+                    lcd.locate(11,1);
+                    lcd.printf("%d",Kd);
+                    Kd=Kdbias+Enc;
+                    if(Kd<0)
+                    {
+                        Kd=0; 
+                        wheel.reset();  
+                        Enc=0; 
+                    } 
+                    
+                    break;
+            }
+        
+        
+                  
+        
+        if(botonEncoder.falling()) 
+        {
+            PWMmodule(periodo,dureza);
+            wait(0.2);
+            wheel.reset();
+            i++;
+            if(i>3) 
+            {
+                i=0;
+            }
+            switch (i) 
+            {
+                case 0:
+                    lcd.locate(2,0);
+                    lcd.printf("=");
+                    break;
+                case 1:
+                    lcd.locate(10,0);
+                    lcd.printf("=");
+                    break;
+                case 2:
+                    lcd.locate(2,1);
+                    lcd.printf("=");
+                    break;
+                case 3:
+                    lcd.locate(10,1);
+                    lcd.printf("=");
+                    break;
+                    
+                    
+            }
+        } 
+    }
+}       
\ No newline at end of file