PID para el control de voltaje de un capacitor en un circuito RC

Dependencies:   Debounced TextLCD mbed

Fork of pid_teclas by Gustavo Ramirez

/media/uploads/PabloViana/general.jpg

Committer:
lcorralesc1
Date:
Wed Oct 16 17:10:11 2013 +0000
Revision:
0:9aa80672eb3d
Child:
1:19ecfc5a15c7
kfjvgjkfnvjfdng

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lcorralesc1 0:9aa80672eb3d 1 #include "mbed.h"
lcorralesc1 0:9aa80672eb3d 2 #include "DebouncedIn.h"
lcorralesc1 0:9aa80672eb3d 3 #include "TextLCD.h"
lcorralesc1 0:9aa80672eb3d 4
lcorralesc1 0:9aa80672eb3d 5 AnalogIn Vin(PTC2);
lcorralesc1 0:9aa80672eb3d 6 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
lcorralesc1 0:9aa80672eb3d 7
lcorralesc1 0:9aa80672eb3d 8 DigitalOut led1(LED1);
lcorralesc1 0:9aa80672eb3d 9 DigitalOut led2(LED2);
lcorralesc1 0:9aa80672eb3d 10 DigitalOut led3(LED3);
lcorralesc1 0:9aa80672eb3d 11 DebouncedIn button1(PTC12);
lcorralesc1 0:9aa80672eb3d 12 DebouncedIn button2(PTC13);
lcorralesc1 0:9aa80672eb3d 13 DebouncedIn button3(PTC16);
lcorralesc1 0:9aa80672eb3d 14
lcorralesc1 0:9aa80672eb3d 15 int C1=0x0F;
lcorralesc1 0:9aa80672eb3d 16 int sp=0,kp=0,kd=0,ki=0,p=1;
lcorralesc1 0:9aa80672eb3d 17 int main()
lcorralesc1 0:9aa80672eb3d 18 {
lcorralesc1 0:9aa80672eb3d 19 lcd.cls();
lcorralesc1 0:9aa80672eb3d 20 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
lcorralesc1 0:9aa80672eb3d 21 lcd.locate(8,0);
lcorralesc1 0:9aa80672eb3d 22 lcd.printf("kp=%d", kp);
lcorralesc1 0:9aa80672eb3d 23 lcd.locate(0,1);
lcorralesc1 0:9aa80672eb3d 24 lcd.printf("Ki=%d", ki);
lcorralesc1 0:9aa80672eb3d 25 lcd.locate(8,1);
lcorralesc1 0:9aa80672eb3d 26 lcd.printf("Kd=%d", kd);
lcorralesc1 0:9aa80672eb3d 27 lcd.locate(0,0);
lcorralesc1 0:9aa80672eb3d 28 lcd.printf("Sp=%d", sp);
lcorralesc1 0:9aa80672eb3d 29
lcorralesc1 0:9aa80672eb3d 30 while(1)
lcorralesc1 0:9aa80672eb3d 31 {
lcorralesc1 0:9aa80672eb3d 32 if (button1.falling())
lcorralesc1 0:9aa80672eb3d 33 {
lcorralesc1 0:9aa80672eb3d 34 led1 =!led1;
lcorralesc1 0:9aa80672eb3d 35 if (p==1)
lcorralesc1 0:9aa80672eb3d 36 {
lcorralesc1 0:9aa80672eb3d 37 ++sp;
lcorralesc1 0:9aa80672eb3d 38 lcd.locate(3,0);
lcorralesc1 0:9aa80672eb3d 39 lcd.printf(" ");
lcorralesc1 0:9aa80672eb3d 40 lcd.locate(3,0);
lcorralesc1 0:9aa80672eb3d 41 lcd.printf("%d", sp);
lcorralesc1 0:9aa80672eb3d 42 }
lcorralesc1 0:9aa80672eb3d 43 else if (p==2)
lcorralesc1 0:9aa80672eb3d 44 {
lcorralesc1 0:9aa80672eb3d 45 ++kp;
lcorralesc1 0:9aa80672eb3d 46 lcd.locate(11,0);
lcorralesc1 0:9aa80672eb3d 47 lcd.printf(" ");
lcorralesc1 0:9aa80672eb3d 48 lcd.locate(11,0);
lcorralesc1 0:9aa80672eb3d 49 lcd.printf("%d", kp);
lcorralesc1 0:9aa80672eb3d 50 }
lcorralesc1 0:9aa80672eb3d 51 else if (p==3)
lcorralesc1 0:9aa80672eb3d 52 {
lcorralesc1 0:9aa80672eb3d 53 ++ki;
lcorralesc1 0:9aa80672eb3d 54 lcd.locate(3,1);
lcorralesc1 0:9aa80672eb3d 55 lcd.printf(" ");
lcorralesc1 0:9aa80672eb3d 56 lcd.locate(3,1);
lcorralesc1 0:9aa80672eb3d 57 lcd.printf("%d", ki);
lcorralesc1 0:9aa80672eb3d 58 }
lcorralesc1 0:9aa80672eb3d 59 else if (p==4)
lcorralesc1 0:9aa80672eb3d 60 {
lcorralesc1 0:9aa80672eb3d 61 ++kd;
lcorralesc1 0:9aa80672eb3d 62 lcd.locate(11,1);
lcorralesc1 0:9aa80672eb3d 63 lcd.printf(" ");
lcorralesc1 0:9aa80672eb3d 64 lcd.locate(11,1);
lcorralesc1 0:9aa80672eb3d 65 lcd.printf("%d", kd);
lcorralesc1 0:9aa80672eb3d 66 }
lcorralesc1 0:9aa80672eb3d 67 }
lcorralesc1 0:9aa80672eb3d 68 if (button2.falling())
lcorralesc1 0:9aa80672eb3d 69 {
lcorralesc1 0:9aa80672eb3d 70 led2 =!led2;
lcorralesc1 0:9aa80672eb3d 71 if (p==1)
lcorralesc1 0:9aa80672eb3d 72 {
lcorralesc1 0:9aa80672eb3d 73 if (sp==0) // no mostrar nada
lcorralesc1 0:9aa80672eb3d 74 {
lcorralesc1 0:9aa80672eb3d 75 }
lcorralesc1 0:9aa80672eb3d 76 else
lcorralesc1 0:9aa80672eb3d 77 {
lcorralesc1 0:9aa80672eb3d 78 --sp;
lcorralesc1 0:9aa80672eb3d 79 lcd.locate(3,0);
lcorralesc1 0:9aa80672eb3d 80 lcd.printf(" ");
lcorralesc1 0:9aa80672eb3d 81 lcd.locate(3,0);
lcorralesc1 0:9aa80672eb3d 82 lcd.printf("%d", sp);
lcorralesc1 0:9aa80672eb3d 83 }
lcorralesc1 0:9aa80672eb3d 84 }
lcorralesc1 0:9aa80672eb3d 85 if (p==2)
lcorralesc1 0:9aa80672eb3d 86 {
lcorralesc1 0:9aa80672eb3d 87 if (kp==0) // no mostrar nada
lcorralesc1 0:9aa80672eb3d 88 {
lcorralesc1 0:9aa80672eb3d 89 }
lcorralesc1 0:9aa80672eb3d 90 else
lcorralesc1 0:9aa80672eb3d 91 {
lcorralesc1 0:9aa80672eb3d 92 --kp;
lcorralesc1 0:9aa80672eb3d 93 lcd.locate(11,0);
lcorralesc1 0:9aa80672eb3d 94 lcd.printf(" ");
lcorralesc1 0:9aa80672eb3d 95 lcd.locate(11,0);
lcorralesc1 0:9aa80672eb3d 96 lcd.printf("%d", kp);
lcorralesc1 0:9aa80672eb3d 97 }
lcorralesc1 0:9aa80672eb3d 98 }
lcorralesc1 0:9aa80672eb3d 99 if (p==3)
lcorralesc1 0:9aa80672eb3d 100 {
lcorralesc1 0:9aa80672eb3d 101 if (ki==0) // no mostrar nada
lcorralesc1 0:9aa80672eb3d 102 {
lcorralesc1 0:9aa80672eb3d 103 }
lcorralesc1 0:9aa80672eb3d 104 else
lcorralesc1 0:9aa80672eb3d 105 {
lcorralesc1 0:9aa80672eb3d 106 --ki;
lcorralesc1 0:9aa80672eb3d 107 lcd.locate(3,1);
lcorralesc1 0:9aa80672eb3d 108 lcd.printf(" ");
lcorralesc1 0:9aa80672eb3d 109 lcd.locate(3,1);
lcorralesc1 0:9aa80672eb3d 110 lcd.printf("%d", ki);
lcorralesc1 0:9aa80672eb3d 111 }
lcorralesc1 0:9aa80672eb3d 112 }
lcorralesc1 0:9aa80672eb3d 113 if (p==4)
lcorralesc1 0:9aa80672eb3d 114 {
lcorralesc1 0:9aa80672eb3d 115 if (kd==0) // no mostrar nada
lcorralesc1 0:9aa80672eb3d 116 {
lcorralesc1 0:9aa80672eb3d 117 }
lcorralesc1 0:9aa80672eb3d 118 else
lcorralesc1 0:9aa80672eb3d 119 {
lcorralesc1 0:9aa80672eb3d 120 --kd;
lcorralesc1 0:9aa80672eb3d 121 lcd.locate(11,1);
lcorralesc1 0:9aa80672eb3d 122 lcd.printf(" ");
lcorralesc1 0:9aa80672eb3d 123 lcd.locate(11,1);
lcorralesc1 0:9aa80672eb3d 124 lcd.printf("%d", kd);
lcorralesc1 0:9aa80672eb3d 125 }
lcorralesc1 0:9aa80672eb3d 126 }
lcorralesc1 0:9aa80672eb3d 127 }
lcorralesc1 0:9aa80672eb3d 128 if (button3.falling())
lcorralesc1 0:9aa80672eb3d 129 {
lcorralesc1 0:9aa80672eb3d 130 led3 =!led3;
lcorralesc1 0:9aa80672eb3d 131 if (p==1)
lcorralesc1 0:9aa80672eb3d 132 {
lcorralesc1 0:9aa80672eb3d 133 ++p;
lcorralesc1 0:9aa80672eb3d 134 lcd.locate(11,0);
lcorralesc1 0:9aa80672eb3d 135 lcd.printf("%d", kp);
lcorralesc1 0:9aa80672eb3d 136
lcorralesc1 0:9aa80672eb3d 137
lcorralesc1 0:9aa80672eb3d 138 }
lcorralesc1 0:9aa80672eb3d 139 else if (p==2)
lcorralesc1 0:9aa80672eb3d 140 {
lcorralesc1 0:9aa80672eb3d 141 ++p;
lcorralesc1 0:9aa80672eb3d 142 lcd.locate(3,1);
lcorralesc1 0:9aa80672eb3d 143 lcd.printf("%d", ki);
lcorralesc1 0:9aa80672eb3d 144 lcd.locate(3,1);
lcorralesc1 0:9aa80672eb3d 145
lcorralesc1 0:9aa80672eb3d 146 }
lcorralesc1 0:9aa80672eb3d 147 else if (p==3)
lcorralesc1 0:9aa80672eb3d 148 {
lcorralesc1 0:9aa80672eb3d 149 ++p;
lcorralesc1 0:9aa80672eb3d 150 lcd.locate(11,1);
lcorralesc1 0:9aa80672eb3d 151 lcd.printf("%d", kd);
lcorralesc1 0:9aa80672eb3d 152
lcorralesc1 0:9aa80672eb3d 153
lcorralesc1 0:9aa80672eb3d 154 }
lcorralesc1 0:9aa80672eb3d 155 else if (p==4)
lcorralesc1 0:9aa80672eb3d 156 {
lcorralesc1 0:9aa80672eb3d 157 p=1;
lcorralesc1 0:9aa80672eb3d 158 lcd.locate(3,0);
lcorralesc1 0:9aa80672eb3d 159 lcd.printf("%d", sp);
lcorralesc1 0:9aa80672eb3d 160
lcorralesc1 0:9aa80672eb3d 161
lcorralesc1 0:9aa80672eb3d 162 }
lcorralesc1 0:9aa80672eb3d 163 }
lcorralesc1 0:9aa80672eb3d 164 }
lcorralesc1 0:9aa80672eb3d 165 }