Changeset 32 for trunk/Arduino/projects/OT_boiler
- Timestamp:
- Oct 21, 2019, 9:57:34 AM (7 years ago)
- File:
-
- 1 edited
-
trunk/Arduino/projects/OT_boiler/OT_boiler.ino (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Arduino/projects/OT_boiler/OT_boiler.ino
r31 r32 2 2 #include <Ethernet.h> 3 3 #include <OT_Slave.h> 4 5 #include "BoilerDefinition.h" 4 6 5 7 //#define ACTIVITY_LED_PIN LED_BUILTIN … … 32 34 long cntVal; 33 35 34 long pwm; 35 36 long a2Val; 37 long a2Dir; // Boiler (VC-40) active detection 38 bool a2Rising; 36 float qRequest; 37 float qCurrent; // debug only ??? 38 int pwmRequest; 39 int pwmCurrent; 40 41 long a2Val; 42 long a2Dir; // Boiler (VC-506E) active detection 43 bool a2Rising; 39 44 40 45 void ReadData (); 41 46 void CalcData (); 42 47 43 virtual double AD2Temperature (int); 48 static double Func_T_of_A (int a, int pin); 49 static double Func_Q789_of_T (double t); 50 static double Func_PWM_of_Q789 (double q); 44 51 45 52 public: … … 100 107 #endif 101 108 boiler.maintain(); 102 #ifdef _NEVER_ 103 // unsigned long periode = msTicks / (boiler.IsActive() ? 500 : 2000); 104 unsigned long periode = msTicks / (boiler.IsActive() ? 2000 : 2000); 105 static unsigned long prev = 0; 106 if (prev != periode) { 107 prev = periode; 108 #else 109 static unsigned long limit = 0; 110 if (!limit) { 111 unsigned long interval = boiler.IsActive() ? 500 : 2000; 112 limit = ((msTicks / interval) + 1 ) * interval; 113 } 114 static unsigned long periode = 0; 115 if (msTicks >= limit) { 116 limit = 0; 117 periode += 1; 118 #endif 109 static unsigned long limit = 0; 110 if (!limit) { 111 unsigned long interval = boiler.IsActive() ? 500 : 2000; 112 limit = ((msTicks / interval) + 1 ) * interval; 113 } 114 static unsigned long periode = 0; 115 if (msTicks >= limit) { 116 limit = 0; 117 periode += 1; 119 118 int led = (periode & 1) ? HIGH : LOW; 120 119 if (Serial) { … … 137 136 Serial.print("\tDir(A2): "); 138 137 Serial.print(boiler.a2Dir); 139 Serial.print("\tRising(A2): ");140 Serial.print(boiler.a2Rising);138 Serial.print("\tRising(A2): "); 139 Serial.print(boiler.a2Rising); 141 140 float tReturn = boiler.GetReturnTemperature(); 142 141 Serial.print("\tA3: "); … … 149 148 Serial.print(boiler.a5); 150 149 Serial.print("\tPWM: "); 151 // long _pwm = (msTicks / 20000) % 256; 152 // long _pwm = long(0.9097+164.44*(0.4283+boiler.tRequest*(0.0009+boiler.tRequest*(0.00006-boiler.tRequest*0.0000003)))); 153 // analogWrite(PWM_PIN, _pwm); 154 Serial.print(boiler.pwm); 150 Serial.print(boiler.pwmCurrent); 155 151 Serial.print("\tReq: "); 156 152 Serial.print(boiler.tRequest); 157 153 Serial.print("\tQ(A): "); 158 Serial.println( double(boiler.a5)/double(boiler.a4));154 Serial.println(boiler.qCurrent); 159 155 } 160 156 digitalWrite(ACTIVITY_LED_PIN, led); … … 225 221 } 226 222 227 OT_Boiler::OT_Boiler ()228 :229 a2(0),230 a3(0),231 a4(0),232 a5(0),233 cnt(0),234 cntVal(0),235 a2Val(0),236 a2Dir(0),237 a2Rising(false)238 {239 }240 241 void OT_Boiler::maintain ()242 {243 ReadData();244 OT_Slave::maintain();245 }246 247 223 void OT_Boiler::ReadData () 248 224 { 249 225 long a2Prev = a2Val; 250 a2Val = analogRead(A2);226 a2Val = analogRead(A2); 251 227 a2 += a2Val; 252 228 a3 += analogRead(A3); … … 261 237 } else { 262 238 a2Dir -= 1; 263 if (a2Dir < -5) {264 a2Rising = false;265 }239 if (a2Dir < -5) { 240 a2Rising = false; 241 } 266 242 } 267 243 } else { … … 270 246 } else { 271 247 a2Dir += 1; 272 if (a2Dir > 5) {273 a2Rising = true;274 }248 if (a2Dir > 5) { 249 a2Rising = true; 250 } 275 251 } 276 252 } … … 290 266 } 291 267 292 double OT_Boiler::AD2Temperature (int x) 293 { 294 const double m = 0.1816; 295 const double b = -19.234; 296 return m*double(x)+b; 268 double OT_Boiler::Func_T_of_A (int a, int pin) 269 { 270 double x(a); 271 // 'Messung.xlsx'::Messung-3.1.3M 272 const double a0(-19.234); 273 const double a1(0.1816); 274 return a0 + x * a1; 275 } 276 277 double OT_Boiler::Func_Q789_of_T (double t) 278 { 279 // 'Heizung.xlsx'::'789-Calc' 280 const double a0(0.4283); 281 const double a1(0.0009); 282 const double a2(0.00006); 283 const double a3(-0.0000003); 284 return a0 + t * (a1 + t * (a2 + t * a3)); 285 } 286 287 double OT_Boiler::Func_PWM_of_Q789 (double q) 288 { 289 // 'Heizung.xlsx'::'789-Mess' 290 const double a0(-0.9097); 291 const double a1(164.44); 292 return a0 + q * a1; 293 } 294 295 OT_Boiler::OT_Boiler () 296 : 297 a2(0), 298 a3(0), 299 a4(0), 300 a5(0), 301 cnt(0), 302 cntVal(0), 303 qRequest(0), 304 qCurrent(0), 305 pwmRequest(0), 306 pwmCurrent(0), 307 a2Val(0), 308 a2Dir(0), 309 a2Rising(false) 310 { 311 } 312 313 void OT_Boiler::maintain () 314 { 315 ReadData(); 316 OT_Slave::maintain(); 297 317 } 298 318 … … 304 324 void OT_Boiler::SetRequestTemperature (float t) 305 325 { 306 bool update (t != tRequest);326 bool update = (t != tRequest); 307 327 OT_Slave::SetRequestTemperature(t); 308 if (update) { 309 pwm = long(0.9097+164.44*(0.4283+boiler.tRequest*(0.0009+boiler.tRequest*(0.00006-boiler.tRequest*0.0000003)))); 310 analogWrite(PWM_PIN, pwm); 328 qRequest = Func_Q789_of_T(tRequest); 329 pwmRequest = Func_PWM_of_Q789(qRequest); 330 CalcData(); 331 qCurrent = a5/a4; 332 int diff = round(100.0 * (qCurrent - qRequest)); 333 if (diff) { 334 if (update) { 335 pwmCurrent = pwmRequest; 336 } else { 337 pwmCurrent += ((diff > 0) ? -1 : 1); 338 } 339 analogWrite(PWM_PIN, pwmCurrent); 311 340 } 312 341 } … … 315 344 { 316 345 CalcData(); 317 tBoiler = AD2Temperature(a2);346 tBoiler = Func_T_of_A(a2,A2); 318 347 return tBoiler; 319 348 } … … 322 351 { 323 352 CalcData(); 324 t Return = AD2Temperature(a3);353 tBoiler = Func_T_of_A(a3,A3); 325 354 return tReturn; 326 355 }
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)