Mauricio Peña / Mbed 2 deprecated exercise_two

Dependencies:   Debounced TextLCDa mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "DebouncedIn.h"
00004  
00005 Timer timer1;
00006 TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7
00007 DigitalOut myled(LED1);
00008 AnalogOut Aout(PTE30);
00009 AnalogIn Ain(PTC2);
00010 DebouncedIn Arriba(PTE2);
00011 DebouncedIn Abajo(PTE3);
00012 DebouncedIn Ganancia(PTE4);
00013  
00014 float i=0.7; // set point
00015 float j=0; // salida planta
00016 float k=0; // entrada planta
00017 float m=3.4; // ganancia
00018 float js=0;
00019 float ji=1; 
00020 float re=0;
00021 float jo=0;
00022 float jd=0;
00023 float t=0; //tiempo
00024  
00025 int main() {
00026 //float Setpoint=0.6;
00027     while(1) {
00028         
00029         if(Arriba.falling()){
00030         i+=0.01;
00031         }
00032         
00033         if(Abajo.falling()){
00034         i-=0.01;
00035         }
00036         
00037         if(Ganancia.falling()){
00038         m+=0.01;
00039         }
00040                 
00041         if(i<0.999){
00042        
00043         j=Ain;
00044         k=m*(i-j);
00045         Aout=k;
00046         wait(0.1);
00047         jo=j-jo;
00048         lcd.locate(0,0);
00049         lcd.printf("y:%.3f jd:%.2f", j, jd);
00050         lcd.locate(0,1);
00051         lcd.printf("t:%f",t);
00052         lcd.locate(10,1);
00053         lcd.printf("K:%.2f",m);
00054         }
00055         
00056         if(j>js){
00057         js=j;
00058         }
00059         
00060         if(j<ji){
00061         ji=j;
00062         }
00063         //wait(0.2);
00064         jo=j;
00065         re=js-ji;
00066         jd=ji+(re/2);
00067         
00068         if(abs(jd-j)<=0.001){
00069         
00070         t=timer1.read();
00071         timer1.stop();
00072         timer1.reset();
00073         timer1.start();
00074         
00075         } 
00076   
00077     }
00078     
00079 }