![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Controlador PID_Botones
Dependencies: DebouncedIn TextLCD mbed
main.cpp@0:ca187d501f37, 2015-11-13 (annotated)
- Committer:
- szapataa
- Date:
- Fri Nov 13 14:07:19 2015 +0000
- Revision:
- 0:ca187d501f37
Controlador PID con botones
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
szapataa | 0:ca187d501f37 | 1 | // PID con botones |
szapataa | 0:ca187d501f37 | 2 | |
szapataa | 0:ca187d501f37 | 3 | #include "mbed.h" |
szapataa | 0:ca187d501f37 | 4 | #include "stdio.h" |
szapataa | 0:ca187d501f37 | 5 | #include "TextLCD.h" |
szapataa | 0:ca187d501f37 | 6 | #include "DebouncedIn.h" |
szapataa | 0:ca187d501f37 | 7 | |
szapataa | 0:ca187d501f37 | 8 | //Declaracion de entradas y salidas |
szapataa | 0:ca187d501f37 | 9 | DebouncedIn Boton1(PTA1); //Seleccionar |
szapataa | 0:ca187d501f37 | 10 | DebouncedIn Boton2(PTA2); //Aumentar |
szapataa | 0:ca187d501f37 | 11 | DebouncedIn Boton3(PTD4); //Disminuir |
szapataa | 0:ca187d501f37 | 12 | DebouncedIn Boton4(PTA12); //Confirmar e iniciar |
szapataa | 0:ca187d501f37 | 13 | |
szapataa | 0:ca187d501f37 | 14 | PwmOut control(PTE29); |
szapataa | 0:ca187d501f37 | 15 | AnalogIn vsal(PTB0); |
szapataa | 0:ca187d501f37 | 16 | |
szapataa | 0:ca187d501f37 | 17 | TextLCD lcd(PTB8,PTB9,PTB10,PTB11,PTE2,PTE3); // rs, e, d4-d7 |
szapataa | 0:ca187d501f37 | 18 | |
szapataa | 0:ca187d501f37 | 19 | //codigos movimiento del cursor LCD |
szapataa | 0:ca187d501f37 | 20 | int C2=0x18; // desplaza izquierda |
szapataa | 0:ca187d501f37 | 21 | int C3=0x1A; // desplaza derecha |
szapataa | 0:ca187d501f37 | 22 | int C4=0x0C; // quito cursor bajo |
szapataa | 0:ca187d501f37 | 23 | int C1=0x0F; // solo muestra el cursor |
szapataa | 0:ca187d501f37 | 24 | |
szapataa | 0:ca187d501f37 | 25 | int Kp=0,Ki=0,Kd=0,Sp=0,p,i; |
szapataa | 0:ca187d501f37 | 26 | float rT,eT,iT,dT,yT,uT,iT0=0,eT0=0,iT_1=0,eT_1=0,spf=0; |
szapataa | 0:ca187d501f37 | 27 | Timer tu; |
szapataa | 0:ca187d501f37 | 28 | Timer td; |
szapataa | 0:ca187d501f37 | 29 | |
szapataa | 0:ca187d501f37 | 30 | int main() { |
szapataa | 0:ca187d501f37 | 31 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 32 | //PRESENTACIÓN |
szapataa | 0:ca187d501f37 | 33 | lcd.locate(0,0); |
szapataa | 0:ca187d501f37 | 34 | lcd.printf("PID_BOTONES"); |
szapataa | 0:ca187d501f37 | 35 | wait(1); |
szapataa | 0:ca187d501f37 | 36 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 37 | lcd.locate(0,0); |
szapataa | 0:ca187d501f37 | 38 | lcd.printf("Omar Torres"); |
szapataa | 0:ca187d501f37 | 39 | lcd.locate(0,1); |
szapataa | 0:ca187d501f37 | 40 | lcd.printf("Sebastian Zapata"); |
szapataa | 0:ca187d501f37 | 41 | wait(2); |
szapataa | 0:ca187d501f37 | 42 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 43 | |
szapataa | 0:ca187d501f37 | 44 | //comando basado en el manual del LCD |
szapataa | 0:ca187d501f37 | 45 | lcd.locate(1,0); |
szapataa | 0:ca187d501f37 | 46 | lcd.printf("Kp=%d",Kp); |
szapataa | 0:ca187d501f37 | 47 | lcd.locate(9,0); |
szapataa | 0:ca187d501f37 | 48 | lcd.printf("Ki%d=",Ki); |
szapataa | 0:ca187d501f37 | 49 | lcd.locate(1,1); |
szapataa | 0:ca187d501f37 | 50 | lcd.printf("Kd=%d",Kd); |
szapataa | 0:ca187d501f37 | 51 | lcd.locate(9,1); |
szapataa | 0:ca187d501f37 | 52 | lcd.printf("Sp=%d",Sp); |
szapataa | 0:ca187d501f37 | 53 | |
szapataa | 0:ca187d501f37 | 54 | set_Kp: |
szapataa | 0:ca187d501f37 | 55 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 56 | lcd.locate(0,0); |
szapataa | 0:ca187d501f37 | 57 | lcd.printf("|Kp= "); |
szapataa | 0:ca187d501f37 | 58 | |
szapataa | 0:ca187d501f37 | 59 | lcd.locate(9,0); |
szapataa | 0:ca187d501f37 | 60 | lcd.printf("Ki=%d",Ki); |
szapataa | 0:ca187d501f37 | 61 | lcd.locate(1,1); |
szapataa | 0:ca187d501f37 | 62 | lcd.printf("Kd=%d",Kd); |
szapataa | 0:ca187d501f37 | 63 | lcd.locate(9,1); |
szapataa | 0:ca187d501f37 | 64 | lcd.printf("Sp=%d",Sp); |
szapataa | 0:ca187d501f37 | 65 | |
szapataa | 0:ca187d501f37 | 66 | while(1){ |
szapataa | 0:ca187d501f37 | 67 | if(Boton2.falling()){ |
szapataa | 0:ca187d501f37 | 68 | Kp++; |
szapataa | 0:ca187d501f37 | 69 | tu.start(); |
szapataa | 0:ca187d501f37 | 70 | } |
szapataa | 0:ca187d501f37 | 71 | //AUMENTO de 10 en 10 |
szapataa | 0:ca187d501f37 | 72 | if(Boton2.rising()){ |
szapataa | 0:ca187d501f37 | 73 | tu.stop(); |
szapataa | 0:ca187d501f37 | 74 | tu.reset(); |
szapataa | 0:ca187d501f37 | 75 | } |
szapataa | 0:ca187d501f37 | 76 | if(tu.read()>=2.0 && tu.read()<4.0){ |
szapataa | 0:ca187d501f37 | 77 | Kp=Kp+10; |
szapataa | 0:ca187d501f37 | 78 | wait(0.3); |
szapataa | 0:ca187d501f37 | 79 | } |
szapataa | 0:ca187d501f37 | 80 | else if(tu.read()>=4.0){ |
szapataa | 0:ca187d501f37 | 81 | Kp=Kp+100; |
szapataa | 0:ca187d501f37 | 82 | wait(0.3); |
szapataa | 0:ca187d501f37 | 83 | } |
szapataa | 0:ca187d501f37 | 84 | //-- |
szapataa | 0:ca187d501f37 | 85 | if(Boton3.falling()){ |
szapataa | 0:ca187d501f37 | 86 | Kp--; |
szapataa | 0:ca187d501f37 | 87 | td.start(); |
szapataa | 0:ca187d501f37 | 88 | } |
szapataa | 0:ca187d501f37 | 89 | //DISMINUYE de 10 en 10 |
szapataa | 0:ca187d501f37 | 90 | if(Boton3.rising()){ |
szapataa | 0:ca187d501f37 | 91 | td.stop(); |
szapataa | 0:ca187d501f37 | 92 | td.reset(); |
szapataa | 0:ca187d501f37 | 93 | } |
szapataa | 0:ca187d501f37 | 94 | if(td.read()>=2.0 && td.read()<4.0){ |
szapataa | 0:ca187d501f37 | 95 | Kp=Kp-10; |
szapataa | 0:ca187d501f37 | 96 | wait(0.3); |
szapataa | 0:ca187d501f37 | 97 | } |
szapataa | 0:ca187d501f37 | 98 | else if(td.read()>=4.0){ |
szapataa | 0:ca187d501f37 | 99 | Kp=Kp-100; |
szapataa | 0:ca187d501f37 | 100 | wait(0.3); |
szapataa | 0:ca187d501f37 | 101 | } |
szapataa | 0:ca187d501f37 | 102 | //-- |
szapataa | 0:ca187d501f37 | 103 | |
szapataa | 0:ca187d501f37 | 104 | if(Kp>=999){ |
szapataa | 0:ca187d501f37 | 105 | Kp=999; |
szapataa | 0:ca187d501f37 | 106 | } |
szapataa | 0:ca187d501f37 | 107 | else if (Kp<=0){ |
szapataa | 0:ca187d501f37 | 108 | Kp=0; |
szapataa | 0:ca187d501f37 | 109 | } |
szapataa | 0:ca187d501f37 | 110 | |
szapataa | 0:ca187d501f37 | 111 | lcd.locate(0,0); |
szapataa | 0:ca187d501f37 | 112 | lcd.printf("|Kp=%d ",Kp); |
szapataa | 0:ca187d501f37 | 113 | |
szapataa | 0:ca187d501f37 | 114 | if(Boton1.falling()){ |
szapataa | 0:ca187d501f37 | 115 | goto set_Ki; |
szapataa | 0:ca187d501f37 | 116 | } |
szapataa | 0:ca187d501f37 | 117 | |
szapataa | 0:ca187d501f37 | 118 | if(Boton4.falling()){ |
szapataa | 0:ca187d501f37 | 119 | goto PID; |
szapataa | 0:ca187d501f37 | 120 | } |
szapataa | 0:ca187d501f37 | 121 | } |
szapataa | 0:ca187d501f37 | 122 | |
szapataa | 0:ca187d501f37 | 123 | set_Ki: |
szapataa | 0:ca187d501f37 | 124 | |
szapataa | 0:ca187d501f37 | 125 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 126 | lcd.locate(8,0); |
szapataa | 0:ca187d501f37 | 127 | lcd.printf("|Ki= "); |
szapataa | 0:ca187d501f37 | 128 | |
szapataa | 0:ca187d501f37 | 129 | lcd.locate(1,0); |
szapataa | 0:ca187d501f37 | 130 | lcd.printf("Kp=%d",Kp); |
szapataa | 0:ca187d501f37 | 131 | lcd.locate(1,1); |
szapataa | 0:ca187d501f37 | 132 | lcd.printf("Kd=%d",Kd); |
szapataa | 0:ca187d501f37 | 133 | lcd.locate(9,1); |
szapataa | 0:ca187d501f37 | 134 | lcd.printf("Sp=%d",Sp); |
szapataa | 0:ca187d501f37 | 135 | |
szapataa | 0:ca187d501f37 | 136 | //Ki=0; |
szapataa | 0:ca187d501f37 | 137 | while(1){ |
szapataa | 0:ca187d501f37 | 138 | if(Boton2.falling()){ |
szapataa | 0:ca187d501f37 | 139 | Ki++; |
szapataa | 0:ca187d501f37 | 140 | tu.start(); |
szapataa | 0:ca187d501f37 | 141 | } |
szapataa | 0:ca187d501f37 | 142 | //AUMENTO de 10 en 10 |
szapataa | 0:ca187d501f37 | 143 | if(Boton2.rising()){ |
szapataa | 0:ca187d501f37 | 144 | tu.stop(); |
szapataa | 0:ca187d501f37 | 145 | tu.reset(); |
szapataa | 0:ca187d501f37 | 146 | } |
szapataa | 0:ca187d501f37 | 147 | if(tu.read()>=2.0 && tu.read()<4.0){ |
szapataa | 0:ca187d501f37 | 148 | Ki=Ki+10; |
szapataa | 0:ca187d501f37 | 149 | wait(0.3); |
szapataa | 0:ca187d501f37 | 150 | } |
szapataa | 0:ca187d501f37 | 151 | else if(tu.read()>=4.0){ |
szapataa | 0:ca187d501f37 | 152 | Ki=Ki+100; |
szapataa | 0:ca187d501f37 | 153 | wait(0.3); |
szapataa | 0:ca187d501f37 | 154 | } |
szapataa | 0:ca187d501f37 | 155 | //-- |
szapataa | 0:ca187d501f37 | 156 | if(Boton3.falling()){ |
szapataa | 0:ca187d501f37 | 157 | Ki--; |
szapataa | 0:ca187d501f37 | 158 | td.start(); |
szapataa | 0:ca187d501f37 | 159 | } |
szapataa | 0:ca187d501f37 | 160 | //DISMINUYE de 10 en 10 |
szapataa | 0:ca187d501f37 | 161 | if(Boton3.rising()){ |
szapataa | 0:ca187d501f37 | 162 | td.stop(); |
szapataa | 0:ca187d501f37 | 163 | td.reset(); |
szapataa | 0:ca187d501f37 | 164 | } |
szapataa | 0:ca187d501f37 | 165 | if(td.read()>=2.0 && td.read()<4.0){ |
szapataa | 0:ca187d501f37 | 166 | Ki=Ki-10; |
szapataa | 0:ca187d501f37 | 167 | wait(0.3); |
szapataa | 0:ca187d501f37 | 168 | } |
szapataa | 0:ca187d501f37 | 169 | else if(td.read()>=4.0){ |
szapataa | 0:ca187d501f37 | 170 | Ki=Ki-100; |
szapataa | 0:ca187d501f37 | 171 | wait(0.3); |
szapataa | 0:ca187d501f37 | 172 | } |
szapataa | 0:ca187d501f37 | 173 | //-- |
szapataa | 0:ca187d501f37 | 174 | if(Ki>=999){ |
szapataa | 0:ca187d501f37 | 175 | Ki=999; |
szapataa | 0:ca187d501f37 | 176 | } |
szapataa | 0:ca187d501f37 | 177 | else if (Ki<=0){ |
szapataa | 0:ca187d501f37 | 178 | Ki=0; |
szapataa | 0:ca187d501f37 | 179 | } |
szapataa | 0:ca187d501f37 | 180 | |
szapataa | 0:ca187d501f37 | 181 | lcd.locate(8,0); |
szapataa | 0:ca187d501f37 | 182 | lcd.printf("|Ki=%d ",Ki); |
szapataa | 0:ca187d501f37 | 183 | |
szapataa | 0:ca187d501f37 | 184 | if(Boton1.falling()){ |
szapataa | 0:ca187d501f37 | 185 | goto set_Kd; |
szapataa | 0:ca187d501f37 | 186 | } |
szapataa | 0:ca187d501f37 | 187 | |
szapataa | 0:ca187d501f37 | 188 | if(Boton4.falling()){ |
szapataa | 0:ca187d501f37 | 189 | goto PID; |
szapataa | 0:ca187d501f37 | 190 | } |
szapataa | 0:ca187d501f37 | 191 | } |
szapataa | 0:ca187d501f37 | 192 | |
szapataa | 0:ca187d501f37 | 193 | set_Kd: |
szapataa | 0:ca187d501f37 | 194 | |
szapataa | 0:ca187d501f37 | 195 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 196 | lcd.locate(0,1); |
szapataa | 0:ca187d501f37 | 197 | lcd.printf("|Kd= "); |
szapataa | 0:ca187d501f37 | 198 | |
szapataa | 0:ca187d501f37 | 199 | lcd.locate(1,0); |
szapataa | 0:ca187d501f37 | 200 | lcd.printf("Kp=%d",Kp); |
szapataa | 0:ca187d501f37 | 201 | lcd.locate(9,0); |
szapataa | 0:ca187d501f37 | 202 | lcd.printf("Ki=%d",Ki); |
szapataa | 0:ca187d501f37 | 203 | lcd.locate(9,1); |
szapataa | 0:ca187d501f37 | 204 | lcd.printf("Sp=%d",Sp); |
szapataa | 0:ca187d501f37 | 205 | |
szapataa | 0:ca187d501f37 | 206 | //Kd=0; |
szapataa | 0:ca187d501f37 | 207 | while(1){ |
szapataa | 0:ca187d501f37 | 208 | |
szapataa | 0:ca187d501f37 | 209 | if(Boton2.falling()){ |
szapataa | 0:ca187d501f37 | 210 | Kd++; |
szapataa | 0:ca187d501f37 | 211 | tu.start(); |
szapataa | 0:ca187d501f37 | 212 | } |
szapataa | 0:ca187d501f37 | 213 | //AUMENTO de 10 en 10 |
szapataa | 0:ca187d501f37 | 214 | if(Boton2.rising()){ |
szapataa | 0:ca187d501f37 | 215 | tu.stop(); |
szapataa | 0:ca187d501f37 | 216 | tu.reset(); |
szapataa | 0:ca187d501f37 | 217 | } |
szapataa | 0:ca187d501f37 | 218 | if(tu.read()>=2.0 && tu.read()<4.0){ |
szapataa | 0:ca187d501f37 | 219 | Kd=Kd+10; |
szapataa | 0:ca187d501f37 | 220 | wait(0.3); |
szapataa | 0:ca187d501f37 | 221 | } |
szapataa | 0:ca187d501f37 | 222 | else if(tu.read()>=4.0){ |
szapataa | 0:ca187d501f37 | 223 | Kd=Kd+100; |
szapataa | 0:ca187d501f37 | 224 | wait(0.3); |
szapataa | 0:ca187d501f37 | 225 | } |
szapataa | 0:ca187d501f37 | 226 | //-- |
szapataa | 0:ca187d501f37 | 227 | if(Boton3.falling()){ |
szapataa | 0:ca187d501f37 | 228 | Kd--; |
szapataa | 0:ca187d501f37 | 229 | td.start(); |
szapataa | 0:ca187d501f37 | 230 | } |
szapataa | 0:ca187d501f37 | 231 | //DISMINUYE de 10 en 10 |
szapataa | 0:ca187d501f37 | 232 | if(Boton3.rising()){ |
szapataa | 0:ca187d501f37 | 233 | td.stop(); |
szapataa | 0:ca187d501f37 | 234 | td.reset(); |
szapataa | 0:ca187d501f37 | 235 | } |
szapataa | 0:ca187d501f37 | 236 | if(td.read()>=2.0 && td.read()<4.0){ |
szapataa | 0:ca187d501f37 | 237 | Kd=Kd-10; |
szapataa | 0:ca187d501f37 | 238 | wait(0.3); |
szapataa | 0:ca187d501f37 | 239 | } |
szapataa | 0:ca187d501f37 | 240 | else if(td.read()>=4.0){ |
szapataa | 0:ca187d501f37 | 241 | Kd=Kd-100; |
szapataa | 0:ca187d501f37 | 242 | wait(0.3); |
szapataa | 0:ca187d501f37 | 243 | } |
szapataa | 0:ca187d501f37 | 244 | //-- |
szapataa | 0:ca187d501f37 | 245 | |
szapataa | 0:ca187d501f37 | 246 | if(Kd>=999){ |
szapataa | 0:ca187d501f37 | 247 | Kd=999; |
szapataa | 0:ca187d501f37 | 248 | } |
szapataa | 0:ca187d501f37 | 249 | else if (Kd<=0){ |
szapataa | 0:ca187d501f37 | 250 | Kd=0; |
szapataa | 0:ca187d501f37 | 251 | } |
szapataa | 0:ca187d501f37 | 252 | |
szapataa | 0:ca187d501f37 | 253 | lcd.locate(0,1); |
szapataa | 0:ca187d501f37 | 254 | lcd.printf("|Kd=%d ",Kd); |
szapataa | 0:ca187d501f37 | 255 | |
szapataa | 0:ca187d501f37 | 256 | if(Boton1.falling()){ |
szapataa | 0:ca187d501f37 | 257 | goto set_Sp; |
szapataa | 0:ca187d501f37 | 258 | } |
szapataa | 0:ca187d501f37 | 259 | |
szapataa | 0:ca187d501f37 | 260 | if(Boton4.falling()){ |
szapataa | 0:ca187d501f37 | 261 | goto PID; |
szapataa | 0:ca187d501f37 | 262 | } |
szapataa | 0:ca187d501f37 | 263 | } |
szapataa | 0:ca187d501f37 | 264 | |
szapataa | 0:ca187d501f37 | 265 | set_Sp: |
szapataa | 0:ca187d501f37 | 266 | |
szapataa | 0:ca187d501f37 | 267 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 268 | lcd.locate(8,1); |
szapataa | 0:ca187d501f37 | 269 | lcd.printf("|Sp= "); |
szapataa | 0:ca187d501f37 | 270 | |
szapataa | 0:ca187d501f37 | 271 | lcd.locate(1,0); |
szapataa | 0:ca187d501f37 | 272 | lcd.printf("Kp=%d",Kp); |
szapataa | 0:ca187d501f37 | 273 | lcd.locate(9,0); |
szapataa | 0:ca187d501f37 | 274 | lcd.printf("Ki=%d",Ki); |
szapataa | 0:ca187d501f37 | 275 | lcd.locate(1,1); |
szapataa | 0:ca187d501f37 | 276 | lcd.printf("Kd=%d",Kd); |
szapataa | 0:ca187d501f37 | 277 | |
szapataa | 0:ca187d501f37 | 278 | //Sp=0; |
szapataa | 0:ca187d501f37 | 279 | while(1){ |
szapataa | 0:ca187d501f37 | 280 | |
szapataa | 0:ca187d501f37 | 281 | if(Boton2.falling()){ |
szapataa | 0:ca187d501f37 | 282 | Sp++; |
szapataa | 0:ca187d501f37 | 283 | tu.start(); |
szapataa | 0:ca187d501f37 | 284 | } |
szapataa | 0:ca187d501f37 | 285 | //AUMENTO de 10 en 10 |
szapataa | 0:ca187d501f37 | 286 | if(Boton2.rising()){ |
szapataa | 0:ca187d501f37 | 287 | tu.stop(); |
szapataa | 0:ca187d501f37 | 288 | tu.reset(); |
szapataa | 0:ca187d501f37 | 289 | } |
szapataa | 0:ca187d501f37 | 290 | if(tu.read()>=2.0 && tu.read()<4.0){ |
szapataa | 0:ca187d501f37 | 291 | Sp=Sp+10; |
szapataa | 0:ca187d501f37 | 292 | wait(0.3); |
szapataa | 0:ca187d501f37 | 293 | } |
szapataa | 0:ca187d501f37 | 294 | else if(tu.read()>=4.0){ |
szapataa | 0:ca187d501f37 | 295 | Sp=Sp+100; |
szapataa | 0:ca187d501f37 | 296 | wait(0.3); |
szapataa | 0:ca187d501f37 | 297 | } |
szapataa | 0:ca187d501f37 | 298 | //-- |
szapataa | 0:ca187d501f37 | 299 | if(Boton3.falling()){ |
szapataa | 0:ca187d501f37 | 300 | Sp--; |
szapataa | 0:ca187d501f37 | 301 | td.start(); |
szapataa | 0:ca187d501f37 | 302 | } |
szapataa | 0:ca187d501f37 | 303 | //DISMINUYE de 10 en 10 |
szapataa | 0:ca187d501f37 | 304 | if(Boton3.rising()){ |
szapataa | 0:ca187d501f37 | 305 | td.stop(); |
szapataa | 0:ca187d501f37 | 306 | td.reset(); |
szapataa | 0:ca187d501f37 | 307 | } |
szapataa | 0:ca187d501f37 | 308 | if(td.read()>=2.0 && td.read()<4.0){ |
szapataa | 0:ca187d501f37 | 309 | Sp=Sp-10; |
szapataa | 0:ca187d501f37 | 310 | wait(0.3); |
szapataa | 0:ca187d501f37 | 311 | } |
szapataa | 0:ca187d501f37 | 312 | else if(td.read()>=4.0){ |
szapataa | 0:ca187d501f37 | 313 | Sp=Sp-100; |
szapataa | 0:ca187d501f37 | 314 | wait(0.3); |
szapataa | 0:ca187d501f37 | 315 | } |
szapataa | 0:ca187d501f37 | 316 | //-- |
szapataa | 0:ca187d501f37 | 317 | if(Sp>=330){ |
szapataa | 0:ca187d501f37 | 318 | Sp=330; |
szapataa | 0:ca187d501f37 | 319 | } |
szapataa | 0:ca187d501f37 | 320 | else if (Sp<=0){ |
szapataa | 0:ca187d501f37 | 321 | Sp=0; |
szapataa | 0:ca187d501f37 | 322 | } |
szapataa | 0:ca187d501f37 | 323 | |
szapataa | 0:ca187d501f37 | 324 | lcd.locate(8,1); |
szapataa | 0:ca187d501f37 | 325 | lcd.printf("|Sp=%d ",Sp); |
szapataa | 0:ca187d501f37 | 326 | |
szapataa | 0:ca187d501f37 | 327 | if(Boton1.falling()){ |
szapataa | 0:ca187d501f37 | 328 | goto set_Kp; |
szapataa | 0:ca187d501f37 | 329 | } |
szapataa | 0:ca187d501f37 | 330 | |
szapataa | 0:ca187d501f37 | 331 | if(Boton4.falling()){ |
szapataa | 0:ca187d501f37 | 332 | goto PID; |
szapataa | 0:ca187d501f37 | 333 | } |
szapataa | 0:ca187d501f37 | 334 | } |
szapataa | 0:ca187d501f37 | 335 | |
szapataa | 0:ca187d501f37 | 336 | PID: |
szapataa | 0:ca187d501f37 | 337 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 338 | |
szapataa | 0:ca187d501f37 | 339 | lcd.locate(0,0); |
szapataa | 0:ca187d501f37 | 340 | lcd.printf("Guardando.."); |
szapataa | 0:ca187d501f37 | 341 | wait(0.6); |
szapataa | 0:ca187d501f37 | 342 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 343 | lcd.locate(0,0); |
szapataa | 0:ca187d501f37 | 344 | lcd.printf("Guardando...."); |
szapataa | 0:ca187d501f37 | 345 | wait(0.6); |
szapataa | 0:ca187d501f37 | 346 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 347 | lcd.locate(0,0); |
szapataa | 0:ca187d501f37 | 348 | lcd.printf("Guardando......"); |
szapataa | 0:ca187d501f37 | 349 | wait(0.6); |
szapataa | 0:ca187d501f37 | 350 | lcd.cls(); |
szapataa | 0:ca187d501f37 | 351 | |
szapataa | 0:ca187d501f37 | 352 | spf=(float)Sp/100; //convirtiendo de decivoltios a voltios |
szapataa | 0:ca187d501f37 | 353 | while(1){ |
szapataa | 0:ca187d501f37 | 354 | |
szapataa | 0:ca187d501f37 | 355 | yT=vsal.read()*3.3; |
szapataa | 0:ca187d501f37 | 356 | eT=spf-yT; |
szapataa | 0:ca187d501f37 | 357 | iT=Ki*eT+iT0; //Accion Integral |
szapataa | 0:ca187d501f37 | 358 | dT=Kd*(eT-eT0); //Accion Derivativa |
szapataa | 0:ca187d501f37 | 359 | uT=iT+Kp*eT+dT; |
szapataa | 0:ca187d501f37 | 360 | if (uT>3.3) { //Salida PID si es mayor que el MAX |
szapataa | 0:ca187d501f37 | 361 | uT=3.3;} |
szapataa | 0:ca187d501f37 | 362 | else if (uT<0){ //Salida PID si es menor que el MIN |
szapataa | 0:ca187d501f37 | 363 | uT=0; |
szapataa | 0:ca187d501f37 | 364 | } |
szapataa | 0:ca187d501f37 | 365 | iT0=iT; //Guarda las variables |
szapataa | 0:ca187d501f37 | 366 | eT0=eT; |
szapataa | 0:ca187d501f37 | 367 | control=(float)uT/3.3; |
szapataa | 0:ca187d501f37 | 368 | |
szapataa | 0:ca187d501f37 | 369 | lcd.locate(0,0); |
szapataa | 0:ca187d501f37 | 370 | lcd.printf("Err=%.2f ",eT); |
szapataa | 0:ca187d501f37 | 371 | lcd.locate(0,1); |
szapataa | 0:ca187d501f37 | 372 | lcd.printf("Sal=%.2f",yT); |
szapataa | 0:ca187d501f37 | 373 | wait(0.2); |
szapataa | 0:ca187d501f37 | 374 | } |
szapataa | 0:ca187d501f37 | 375 | } |
szapataa | 0:ca187d501f37 | 376 |