![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Dryer timer with analogue input from a dew point sensor.
main.cpp@3:559e8c72212a, 2019-11-29 (annotated)
- Committer:
- koosvanderwat
- Date:
- Fri Nov 29 09:27:44 2019 +0000
- Revision:
- 3:559e8c72212a
- Parent:
- 2:ad0b044d0a10
- Child:
- 4:e8ba2070b69e
Dryer timer with analogue input signal from dew point sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:334327d1a416 | 1 | #include "mbed.h" |
simon | 0:334327d1a416 | 2 | #include "TextLCD.h" |
koosvanderwat | 3:559e8c72212a | 3 | #include "Watchdog.h" |
koosvanderwat | 3:559e8c72212a | 4 | #include "millis.h" |
simon | 0:334327d1a416 | 5 | |
koosvanderwat | 3:559e8c72212a | 6 | //Dryer Cycle |
koosvanderwat | 3:559e8c72212a | 7 | int PT = 120; // Purge time in seconds |
koosvanderwat | 3:559e8c72212a | 8 | int RT = 60; // Repressurisation time in seconds |
koosvanderwat | 3:559e8c72212a | 9 | |
koosvanderwat | 3:559e8c72212a | 10 | //Dew Point Setpoint |
koosvanderwat | 3:559e8c72212a | 11 | float SetPoint = -3; // Dew Point Set Point |
koosvanderwat | 3:559e8c72212a | 12 | |
koosvanderwat | 3:559e8c72212a | 13 | //Watchdog |
koosvanderwat | 3:559e8c72212a | 14 | Watchdog wd; |
koosvanderwat | 3:559e8c72212a | 15 | |
koosvanderwat | 3:559e8c72212a | 16 | //Screen Setup |
koosvanderwat | 3:559e8c72212a | 17 | TextLCD lcd(D6, D9, D2, D3, D4, D5); // rs, e, d4-d7 |
koosvanderwat | 3:559e8c72212a | 18 | |
koosvanderwat | 3:559e8c72212a | 19 | Ticker timeKeeping; |
koosvanderwat | 3:559e8c72212a | 20 | |
koosvanderwat | 3:559e8c72212a | 21 | //Pin Allocation |
koosvanderwat | 3:559e8c72212a | 22 | DigitalOut my_RHPV(A0); |
koosvanderwat | 3:559e8c72212a | 23 | DigitalOut my_RHMV(A1); |
koosvanderwat | 3:559e8c72212a | 24 | DigitalOut my_RV(A2); |
koosvanderwat | 3:559e8c72212a | 25 | DigitalOut my_LHMV(A6); |
koosvanderwat | 3:559e8c72212a | 26 | DigitalOut my_LHPV(A7); |
koosvanderwat | 3:559e8c72212a | 27 | DigitalOut my_led(D13); |
koosvanderwat | 3:559e8c72212a | 28 | DigitalIn my_Dip2(D11); //Dip 2 |
koosvanderwat | 3:559e8c72212a | 29 | DigitalIn my_Dip1(D12); //Dip 1 |
koosvanderwat | 3:559e8c72212a | 30 | AnalogIn DP_In(A3); |
koosvanderwat | 3:559e8c72212a | 31 | |
koosvanderwat | 3:559e8c72212a | 32 | unsigned long previousMillis = 0; // will store last time LED was updated |
koosvanderwat | 3:559e8c72212a | 33 | long OnTime = 1000; // milliseconds of on-time |
koosvanderwat | 3:559e8c72212a | 34 | int secondscounter = 0; |
koosvanderwat | 3:559e8c72212a | 35 | int Counter = 0; |
koosvanderwat | 3:559e8c72212a | 36 | int sensorbroken =0; |
koosvanderwat | 3:559e8c72212a | 37 | |
koosvanderwat | 3:559e8c72212a | 38 | int LHCT = PT + RT; // LH cycle time |
koosvanderwat | 3:559e8c72212a | 39 | int LHPT = PT + RT + PT; // LH purge time |
koosvanderwat | 3:559e8c72212a | 40 | int CT = PT + RT + PT + RT; // Cycle Time |
koosvanderwat | 3:559e8c72212a | 41 | |
koosvanderwat | 3:559e8c72212a | 42 | float RHValue = 0; |
koosvanderwat | 3:559e8c72212a | 43 | float TempValue = 0; |
koosvanderwat | 3:559e8c72212a | 44 | float A = 0; |
koosvanderwat | 3:559e8c72212a | 45 | float DewPoint = 0; |
koosvanderwat | 3:559e8c72212a | 46 | float Value1 = 0; |
koosvanderwat | 3:559e8c72212a | 47 | float Value2 = 0; |
koosvanderwat | 3:559e8c72212a | 48 | float Value3 = 0; |
koosvanderwat | 3:559e8c72212a | 49 | |
koosvanderwat | 3:559e8c72212a | 50 | int Valuecounter = 0; |
koosvanderwat | 3:559e8c72212a | 51 | |
koosvanderwat | 3:559e8c72212a | 52 | int main() |
koosvanderwat | 3:559e8c72212a | 53 | { |
koosvanderwat | 3:559e8c72212a | 54 | |
koosvanderwat | 3:559e8c72212a | 55 | my_RHMV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 56 | my_LHMV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 57 | my_RHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 58 | my_LHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 59 | my_RHPV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 60 | my_LHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 61 | my_RV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 62 | |
koosvanderwat | 3:559e8c72212a | 63 | wd.Configure(4.0); |
koosvanderwat | 3:559e8c72212a | 64 | |
koosvanderwat | 3:559e8c72212a | 65 | wait_ms(100); |
koosvanderwat | 3:559e8c72212a | 66 | lcd.printf("TegnonEfficiency\n"); |
koosvanderwat | 3:559e8c72212a | 67 | lcd.locate(0,1); |
koosvanderwat | 3:559e8c72212a | 68 | lcd.printf(" DP Control \n"); |
koosvanderwat | 3:559e8c72212a | 69 | |
koosvanderwat | 3:559e8c72212a | 70 | wait_ms(1000); |
koosvanderwat | 3:559e8c72212a | 71 | lcd.cls(); |
koosvanderwat | 3:559e8c72212a | 72 | lcd.printf("Dew Point:"); |
koosvanderwat | 3:559e8c72212a | 73 | lcd.locate(0,1); |
koosvanderwat | 3:559e8c72212a | 74 | lcd.printf("Set Point:"); |
koosvanderwat | 3:559e8c72212a | 75 | |
koosvanderwat | 3:559e8c72212a | 76 | millisStart(); |
koosvanderwat | 3:559e8c72212a | 77 | |
koosvanderwat | 3:559e8c72212a | 78 | while(1) { |
koosvanderwat | 3:559e8c72212a | 79 | unsigned long currentMillis = millis(); // Get current time |
koosvanderwat | 3:559e8c72212a | 80 | |
koosvanderwat | 3:559e8c72212a | 81 | if(my_Dip2 ==0) { |
koosvanderwat | 3:559e8c72212a | 82 | if(my_Dip1 ==0) { |
koosvanderwat | 3:559e8c72212a | 83 | SetPoint = -3; |
koosvanderwat | 3:559e8c72212a | 84 | } |
koosvanderwat | 3:559e8c72212a | 85 | if(my_Dip1 ==1) { |
koosvanderwat | 3:559e8c72212a | 86 | SetPoint = -20; |
koosvanderwat | 3:559e8c72212a | 87 | } |
koosvanderwat | 3:559e8c72212a | 88 | } |
koosvanderwat | 3:559e8c72212a | 89 | if(my_Dip2 ==1) { |
koosvanderwat | 3:559e8c72212a | 90 | if(my_Dip1 ==0) { |
koosvanderwat | 3:559e8c72212a | 91 | SetPoint = -40; |
koosvanderwat | 3:559e8c72212a | 92 | } |
koosvanderwat | 3:559e8c72212a | 93 | if(my_Dip1 ==1) { |
koosvanderwat | 3:559e8c72212a | 94 | SetPoint = -60; |
koosvanderwat | 3:559e8c72212a | 95 | } |
koosvanderwat | 3:559e8c72212a | 96 | } |
simon | 0:334327d1a416 | 97 | |
koosvanderwat | 3:559e8c72212a | 98 | if ((currentMillis - previousMillis) >= OnTime) { |
koosvanderwat | 3:559e8c72212a | 99 | previousMillis = currentMillis; |
koosvanderwat | 3:559e8c72212a | 100 | wd.Service(); |
koosvanderwat | 3:559e8c72212a | 101 | my_led = !my_led; |
koosvanderwat | 3:559e8c72212a | 102 | |
koosvanderwat | 3:559e8c72212a | 103 | secondscounter = secondscounter + 1; |
koosvanderwat | 3:559e8c72212a | 104 | Counter = Counter + 1; |
koosvanderwat | 3:559e8c72212a | 105 | |
koosvanderwat | 3:559e8c72212a | 106 | if(Counter == 10) { |
koosvanderwat | 3:559e8c72212a | 107 | lcd.cls(); |
koosvanderwat | 3:559e8c72212a | 108 | lcd.printf("Dew Point:"); |
koosvanderwat | 3:559e8c72212a | 109 | lcd.locate(0,1); |
koosvanderwat | 3:559e8c72212a | 110 | lcd.printf("Set Point:"); |
koosvanderwat | 3:559e8c72212a | 111 | Counter = 0; |
koosvanderwat | 3:559e8c72212a | 112 | } |
koosvanderwat | 3:559e8c72212a | 113 | |
koosvanderwat | 3:559e8c72212a | 114 | |
koosvanderwat | 3:559e8c72212a | 115 | if(Valuecounter ==0) { |
koosvanderwat | 3:559e8c72212a | 116 | Value1 = DP_In.read()*100 - 80; |
koosvanderwat | 3:559e8c72212a | 117 | } |
koosvanderwat | 3:559e8c72212a | 118 | if(Valuecounter ==1) { |
koosvanderwat | 3:559e8c72212a | 119 | Value2 = DP_In.read()*100 - 80; |
koosvanderwat | 3:559e8c72212a | 120 | } |
koosvanderwat | 3:559e8c72212a | 121 | if(Valuecounter ==2) { |
koosvanderwat | 3:559e8c72212a | 122 | Value3 = DP_In.read()*100 - 80; |
koosvanderwat | 3:559e8c72212a | 123 | Valuecounter=0; |
koosvanderwat | 3:559e8c72212a | 124 | } |
koosvanderwat | 3:559e8c72212a | 125 | |
koosvanderwat | 3:559e8c72212a | 126 | Valuecounter = Valuecounter + 1; |
koosvanderwat | 3:559e8c72212a | 127 | |
koosvanderwat | 3:559e8c72212a | 128 | DewPoint = (Value1+Value2+Value3)/3; |
koosvanderwat | 3:559e8c72212a | 129 | |
koosvanderwat | 3:559e8c72212a | 130 | //DewPoint = DP_In.read()*100.0f; |
koosvanderwat | 3:559e8c72212a | 131 | |
koosvanderwat | 3:559e8c72212a | 132 | lcd.locate(10,0); |
koosvanderwat | 3:559e8c72212a | 133 | lcd.printf(" "); |
koosvanderwat | 3:559e8c72212a | 134 | lcd.locate(10,0); |
koosvanderwat | 3:559e8c72212a | 135 | lcd.printf("%3.1f%", DewPoint); |
koosvanderwat | 3:559e8c72212a | 136 | lcd.locate(10,1); |
koosvanderwat | 3:559e8c72212a | 137 | lcd.printf(" "); |
koosvanderwat | 3:559e8c72212a | 138 | lcd.locate(10,1); |
koosvanderwat | 3:559e8c72212a | 139 | lcd.printf("%3.1f%", SetPoint); |
koosvanderwat | 3:559e8c72212a | 140 | |
koosvanderwat | 3:559e8c72212a | 141 | |
koosvanderwat | 3:559e8c72212a | 142 | if ((DewPoint < SetPoint) && (secondscounter == LHCT)) { |
koosvanderwat | 3:559e8c72212a | 143 | secondscounter = secondscounter - 1; |
koosvanderwat | 3:559e8c72212a | 144 | } |
koosvanderwat | 3:559e8c72212a | 145 | |
koosvanderwat | 3:559e8c72212a | 146 | if ((DewPoint < SetPoint) && (secondscounter == CT)) { |
koosvanderwat | 3:559e8c72212a | 147 | secondscounter = secondscounter - 1; |
koosvanderwat | 3:559e8c72212a | 148 | } |
koosvanderwat | 3:559e8c72212a | 149 | |
koosvanderwat | 3:559e8c72212a | 150 | //} else { |
koosvanderwat | 3:559e8c72212a | 151 | // lcd.locate(0,0); |
koosvanderwat | 3:559e8c72212a | 152 | // lcd.printf(" Standard "); |
koosvanderwat | 3:559e8c72212a | 153 | // lcd.locate(0,1); |
koosvanderwat | 3:559e8c72212a | 154 | // lcd.printf(" Cycle "); |
koosvanderwat | 3:559e8c72212a | 155 | //} |
koosvanderwat | 3:559e8c72212a | 156 | } |
koosvanderwat | 3:559e8c72212a | 157 | |
koosvanderwat | 3:559e8c72212a | 158 | if (secondscounter < PT) { |
koosvanderwat | 3:559e8c72212a | 159 | my_RHMV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 160 | my_LHMV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 161 | my_RHPV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 162 | my_LHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 163 | my_RV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 164 | } |
koosvanderwat | 3:559e8c72212a | 165 | if (secondscounter >= PT && secondscounter < LHCT) { |
koosvanderwat | 3:559e8c72212a | 166 | my_RHMV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 167 | my_LHMV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 168 | my_RHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 169 | my_LHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 170 | my_RV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 171 | |
koosvanderwat | 3:559e8c72212a | 172 | } |
koosvanderwat | 3:559e8c72212a | 173 | |
koosvanderwat | 3:559e8c72212a | 174 | if ((secondscounter > LHCT) && (secondscounter < LHPT)) { |
koosvanderwat | 3:559e8c72212a | 175 | my_RHMV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 176 | my_LHMV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 177 | my_RHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 178 | my_LHPV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 179 | my_RV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 180 | } |
koosvanderwat | 3:559e8c72212a | 181 | if (secondscounter >= LHPT && (secondscounter < CT)) { |
koosvanderwat | 3:559e8c72212a | 182 | my_RHMV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 183 | my_LHMV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 184 | my_RHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 185 | my_LHPV = 0;//1 |
koosvanderwat | 3:559e8c72212a | 186 | my_RV = 1;//0 |
koosvanderwat | 3:559e8c72212a | 187 | } |
koosvanderwat | 3:559e8c72212a | 188 | |
koosvanderwat | 3:559e8c72212a | 189 | if (secondscounter == (CT + 1)) { |
koosvanderwat | 3:559e8c72212a | 190 | secondscounter = 0; |
koosvanderwat | 3:559e8c72212a | 191 | } |
koosvanderwat | 3:559e8c72212a | 192 | } // While(1) |
koosvanderwat | 3:559e8c72212a | 193 | } //Void Main |