Changeset 33 for trunk/Arduino/projects/OT_boiler
- Timestamp:
- Oct 23, 2019, 12:27:30 AM (7 years ago)
- File:
-
- 1 edited
-
trunk/Arduino/projects/OT_boiler/OT_boiler.ino (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Arduino/projects/OT_boiler/OT_boiler.ino
r32 r33 2 2 #include <Ethernet.h> 3 3 #include <OT_Slave.h> 4 5 #include "BoilerDefinition.h" 4 #include <OT_Boiler.h> 6 5 7 6 //#define ACTIVITY_LED_PIN LED_BUILTIN … … 27 26 28 27 protected: 29 long a2; 30 long a3; 31 long a4; 32 long a5; 33 long cnt; 34 long cntVal; 28 SMA<int,float> a2; 29 SMA<int,float> a3; 30 SMA<int,float> a4; 31 SMA<int,float> a5; 32 33 SMA<float,float> a2Trend; 34 bool a2Rising; // Boiler (VC-506E) active detection 35 35 36 36 float qRequest; … … 39 39 int pwmCurrent; 40 40 41 long a2Val;42 long a2Dir; // Boiler (VC-506E) active detection43 bool a2Rising;44 45 41 void ReadData (); 46 void CalcData (); 47 48 static double Func_T_of_A ( int a, int pin);42 43 static double Func_T_of_A (int a, int pin) { return Func_T_of_A(float(a), pin); } 44 static double Func_T_of_A (float a, int pin); 49 45 static double Func_Q789_of_T (double t); 50 46 static double Func_PWM_of_Q789 (double q); … … 54 50 55 51 virtual void maintain (); 52 virtual void periodic (); 56 53 57 54 virtual bool IsActive (); … … 117 114 periode += 1; 118 115 int led = (periode & 1) ? HIGH : LOW; 116 boiler.periodic(); 119 117 if (Serial) { 120 boiler.CalcData();121 118 Serial.print("Time: "); 122 119 Serial.print(msTicks); 123 120 Serial.print("\tPeriode: "); 124 121 Serial.print(periode); 125 /*126 Serial.print("\tLED: ");127 Serial.print(led);128 */129 Serial.print("\tCnt: ");130 Serial.print(boiler.cntVal);131 float tBoiler = boiler.GetBoilerTemperature();132 122 Serial.print("\tA2: "); 133 Serial.print(boiler.a2); 123 Serial.print(boiler.a2.mean()); 124 Serial.print("\tA2.Trend: "); 125 Serial.print(boiler.a2Trend.slope()); 126 Serial.print("\tA2.Rising: "); 127 Serial.print(boiler.a2Rising); 134 128 Serial.print("\tT(A2): "); 135 Serial.print(tBoiler); 136 Serial.print("\tDir(A2): "); 137 Serial.print(boiler.a2Dir); 138 Serial.print("\tRising(A2): "); 139 Serial.print(boiler.a2Rising); 140 float tReturn = boiler.GetReturnTemperature(); 141 Serial.print("\tA3: "); 142 Serial.print(boiler.a3); 129 Serial.print(boiler.GetBoilerTemperature()); 130 Serial.print("\tA3: "); 131 Serial.print(boiler.a3.mean()); 143 132 Serial.print("\tT(A3): "); 144 Serial.print( tReturn);133 Serial.print(boiler.GetReturnTemperature()); 145 134 Serial.print("\tA4: "); 146 Serial.print(boiler.a4 );135 Serial.print(boiler.a4.mean()); 147 136 Serial.print("\tA5: "); 148 Serial.print(boiler.a5 );137 Serial.print(boiler.a5.mean()); 149 138 Serial.print("\tPWM: "); 150 139 Serial.print(boiler.pwmCurrent); … … 223 212 void OT_Boiler::ReadData () 224 213 { 225 long a2Prev = a2Val; 226 a2Val = analogRead(A2); 227 a2 += a2Val; 228 a3 += analogRead(A3); 229 a4 += analogRead(A4); 230 a5 += analogRead(A5); 231 cnt++; 232 // Calc A2 direction... 233 if (a2Val != a2Prev) { 234 if (a2Val < a2Prev) { 235 if (a2Dir > 0) { 236 a2Dir = -1; 237 } else { 238 a2Dir -= 1; 239 if (a2Dir < -5) { 240 a2Rising = false; 241 } 242 } 243 } else { 244 if (a2Dir < 0) { 245 a2Dir = 1; 246 } else { 247 a2Dir += 1; 248 if (a2Dir > 5) { 249 a2Rising = true; 250 } 251 } 252 } 253 } 254 } 255 256 void OT_Boiler::CalcData () 257 { 258 if (cnt > 1) { 259 cntVal = cnt; 260 a2 /= cnt; 261 a3 /= cnt; 262 a4 /= cnt; 263 a5 /= cnt; 264 cnt = 1; 265 } 266 } 267 268 double OT_Boiler::Func_T_of_A (int a, int pin) 214 a2.push(analogRead(A2)); 215 a3.push(analogRead(A3)); 216 a4.push(analogRead(A4)); 217 a5.push(analogRead(A5)); 218 } 219 220 double OT_Boiler::Func_T_of_A (float a, int pin) 269 221 { 270 222 double x(a); 271 // 'Messung.xlsx'::Messung-3.1.3M223 // 'Messung.xlsx'::Messung-3.1.3M 272 224 const double a0(-19.234); 273 225 const double a1(0.1816); … … 295 247 OT_Boiler::OT_Boiler () 296 248 : 297 a2( 0),298 a3( 0),299 a4( 0),300 a5( 0),301 cnt(0),302 cntVal(0),249 a2(13), 250 a3(13), 251 a4(13), 252 a5(13), 253 a2Trend(7), 254 a2Rising(false), 303 255 qRequest(0), 304 256 qCurrent(0), 305 257 pwmRequest(0), 306 pwmCurrent(0), 307 a2Val(0), 308 a2Dir(0), 309 a2Rising(false) 310 { 258 pwmCurrent(0) 259 { 260 analogRead(A2); 261 analogRead(A3); 262 analogRead(A4); 263 analogRead(A5); 311 264 } 312 265 … … 315 268 ReadData(); 316 269 OT_Slave::maintain(); 270 } 271 272 void OT_Boiler::periodic () 273 { 274 a2Trend.push(a2.mean()); 275 if (a2Rising) { 276 // a2Rising = (a2Trend.slope() > (0.00025 * a2Trend.mean())); 277 a2Rising = (a2Trend.slope() >= 0.0); 278 } else { 279 // a2Rising = a2Trend.loaded() && (a2Trend.slope() > (0.0025 * a2Trend.mean())); 280 a2Rising = a2Trend.loaded() && (a2Trend.slope() > 0.1); 281 } 317 282 } 318 283 … … 328 293 qRequest = Func_Q789_of_T(tRequest); 329 294 pwmRequest = Func_PWM_of_Q789(qRequest); 330 CalcData();331 295 qCurrent = a5/a4; 332 296 int diff = round(100.0 * (qCurrent - qRequest)); … … 343 307 float OT_Boiler::GetBoilerTemperature () 344 308 { 345 CalcData(); 346 tBoiler = Func_T_of_A(a2,A2); 309 tBoiler = Func_T_of_A(a2.mean(), A2); 347 310 return tBoiler; 348 311 } … … 350 313 float OT_Boiler::GetReturnTemperature () 351 314 { 352 CalcData(); 353 tBoiler = Func_T_of_A(a3,A3); 315 tReturn = Func_T_of_A(a3.mean(), A3); 354 316 return tReturn; 355 317 }
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/trac/Paradigma/chrome/site/paradigma.png)