Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Debounced TextLCD mbed
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 #include "DebouncedIn.h" 00004 00005 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 up(PTE3); 00011 DebouncedIn down(PTE4); 00012 DebouncedIn Gain(PTE2); 00013 int ap,n,ai,ad; 00014 00015 float i; // set point 00016 float j=0; // salida planta 00017 float ji=0; //variable proceso interno 00018 float spi=0; //variable proceso interno 00019 float h=0; // entrada planta 00020 float m=0; // Error 00021 float mv=0; 00022 float g=0; 00023 00024 int sp=500; 00025 int kp=3; 00026 int ki=15; 00027 int kd=1; 00028 00029 00030 int main(){ 00031 00032 //float Setpoint=0.6; 00033 00034 i=sp/999; 00035 lcd.cls(); 00036 lcd.printf("Er:%.2f",m); 00037 lcd.locate(8,0); 00038 lcd.printf("Me:%.2f",j); 00039 lcd.locate(0,1); 00040 lcd.printf("Sp:%d",sp); 00041 lcd.locate(8,1); 00042 lcd.printf("Co:%.1f",h); 00043 wait(2); 00044 00045 // 00046 while(1) { 00047 00048 spi=sp*(3.3/999); 00049 00050 //wait(0.3); 00051 i=sp/999; 00052 if(i<=1){ 00053 00054 j=Ain; 00055 ji=j*3.3; 00056 m=(spi-ji); 00057 //n=m*100; 00058 ap=kp*m; 00059 ai=(ki*m)+ai; 00060 00061 ad=kd*(m-mv); 00062 h=ap+ai+ad; 00063 00064 if (h>999){ 00065 h=999; 00066 } 00067 if (h<0){ 00068 h=0; 00069 } 00070 00071 g=(h/999); 00072 00073 Aout=g; 00074 wait(0.22); 00075 00076 00077 lcd.cls(); 00078 lcd.printf("Er:%.2f",m); 00079 lcd.locate(8,0); 00080 lcd.printf("Me:%.2f",j); 00081 lcd.locate(0,1); 00082 lcd.printf("Sp:%d",sp); 00083 lcd.locate(8,1); 00084 lcd.printf("Co:%.1f",h); 00085 } 00086 00087 00088 mv=m; 00089 } //While 00090 00091 }
Generated on Tue Jul 19 2022 01:00:25 by
1.7.2