DAS  3.1.6 - 18/09/2017
Chktemp.c
Go to the documentation of this file.
1 
2 #include <windows.h>
3 #include <stdio.h>
4 #include <math.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include "mgui.h"
8 #include "DAS_Spatram.h"
9 #include "dcl.h"
10 #include "dxl.h"
11 
18 int D_readtemp(void);
19 
21 //cpl CPL; //Control Panel
22 //lis LIS; //LIS
23 //paramini PARAM; //Param.ini
24 //marc MARC; // Marconi struct
25 //omu OMU; //OMU temperature structure
28 
29 //Gains for actual temp near to target temp (5 > delta temp > 0=°C)
30 #define P_GAIN 0.9
31 #define D_GAIN 0.9
32 #define I_GAIN 0.5
33 
34 //Gains for actual temp far from target temp ( 15 > delta temp >= 5°C)
35 //#define P_GAIN 1.9
36 //#define D_GAIN 1.9
37 //#define I_GAIN 1.5
38 
39 //Gains for actual temp very far from target temp (delta temp >= 15°C)
40 //#define P_GAIN_F 3.9
41 //#define D_GAIN_F 3.9
42 //#define I_GAIN_F 4.5
43 
44 //#define P_GAIN 3.9
45 //#define D_GAIN 3.9
46 //#define I_GAIN 4.5
47 
48 
49 
50 #define I_COUNT_MAX 2 //-- # of intervals before increasing I
51 #define I_COUNT_DEC 4 //-- # times longer to wait b4 decrementing
52 #define I_VALUE_MAX 40 //-- Max Integral Value - Limits overshoot
53 
54 
55 
56 #define CONTROLED_BAND 15 //-- Temperature band around Target that
57  // is controlled (2 units per degree!!)
58 
59 #define MAX_TEMP (50 * 2) //-- Max Temperature of 50 Degrees
60 
61 
62 unsigned char Intergral = 0;
63 unsigned char I_Counter;
64 unsigned int FirstTimeP = 0;
65 
66 
67 
68 //****************************************************************
69 // Calculate POWER
70 //****************************************************************
71 
72 
73 
74 
75 //mod = 1 --> Aumenta Power
76 //mod = 0 --> Diminuisce Power
77 
78 int PID_Calc(int mod, int pow)
79 {
80 
81 // int temp;
82  const double pgain = 30;//1.9;
83  const double dgain =0;// 0.1;
84  float igain = 0;//3;//1.5;
85  double fac_dgain=0;
86  double fac_pgain=0;
87  float kp = 50;
88  float kd = 5;//0.3;
89  double ki = 0.005;
90  double epsilon = 0.01, i_inst;
91  float dt = LISTEMP_TASK_TIME/1000;
92 
93 
94  static float pre_error = 0;
95  static float old_error = 0;
96  static float integral;// = 0;
97  float error, delta;
98  float derivative;
99  float output;
100  float PID_P, PID_D;
101  static float PID_I;
102  //integral =0;
103  char buff[64];
104 
105  //dt = 0.5; //(float)(OMUTHR.CoolCnt*500);
106 
107  delta = (float)(OMUTHR.CoolTT - OMUTHR.CoolAT);
108  sprintf(buff, "%.2lf", delta/10);
109  //error = (float)atof(buff);
110  error = delta/10;
111 
112 //integral = 0;
113 //output = 0;
114  if ((fabs(error)> 0.5))
115  {
116  integral = integral + (error * dt);
117  if (fabs(integral) > 100)
118  integral = 0;
119  }
120 /* else
121  integral=0;
122 */
123  derivative = (error - pre_error) / dt;
124 
125 // output = 1100 * error+ 0.005*integral;//+ 150*derivative;
126 
127  output = OMUTHR.PID_kp * error+ OMUTHR.PID_ki*integral + OMUTHR.PID_kd*derivative;
128 
129  //output = OMUTHR.PID_kp/1000 * error - OMUTHR.PID_ki * integral + OMUTHR.PID_kd * derivative;
130 
131  //sprintf(buff, "%.2lf %.2lf %.2lf %.2lf", output, 1000*error, 0.5*integral, 500*derivative);
132  //sprintf(buff, "%.2lf %.2lf %.2lf", output, 1000*error, 1400*derivative);
133 // sprintf(buff, "%.2lf %.2lf %.2lf %.2lf", output, OMUTHR.PID_kp*error,OMUTHR.PID_ki*integral, OMUTHR.PID_kd*derivative);
134 // Status(buff);
135 
136 
137  if (output > 0)
138  {
139  pow = (int)output;
140  }
141  if (output < 0 )
142  {
143  pow = (int) -output;
144  }
145 
146  pre_error = error;
147 
148  return (pow);
149 
150  //DTA Algorithm
151  PID_P = error;
152  if (OMUTHR.PID_ki>0)
153  {
154  i_inst = error * OMUTHR.PID_ki;
155  PID_I += (float)i_inst;
156  //if (PID_I > 1000) PID_I = 1000;
157  //if (PID_I < -1000) PID_I = -1000;
158  if (PID_I >= 100) PID_I = 100;
159  if (PID_I <= -100) PID_I = -100;
160  }
161  else
162  PID_I = 0;
163 
164  if(OMUTHR.PID_kd > 0)
165  {
166  PID_D = (OMUTHR.PID_kd * ((error - pre_error)*2));
167  pre_error = error;
168  }
169  else
170  PID_D = 0;
171 
172 
173  output = OMUTHR.PID_kp *(PID_P + PID_I - PID_D);
174 
175 
176  sprintf(buff, "%.2lf %.2lf %.2lf %.2lf", output, PID_P, PID_I, PID_D);
177  Status(buff);
178 
179  if (output > 0)
180  {
181 
182  pow = (int)output;
183 
184  }
185  if (output < 0 )
186  {
187 
188 
189  pow = (int) -output;
190  }
191 
192  pre_error = error;
193 
194  return (pow);
195 
196 
197  /*********************************/
198  //DTA Algorithm
199  /*********************************/
200 /* PID_P = error;
201  if (ki>0)
202  {
203  i_inst = error * ki;
204  PID_I += i_inst;
205  if (PID_I > 10) PID_I = 10;
206  if (PID_I < -10) PID_I = -10;
207  }
208  else
209  PID_I = 0;
210 
211  if(kd > 0)
212  {
213  PID_D = kd * ((error - old_error));
214  old_error = error;
215  }
216  else
217  PID_D = 0;
218 
219  output = kp*(PID_P + PID_I - PID_D);
220 
221 
222 
223  pow = (int) output;
224 
225 
226 
227 //}
228  return pow;
229 */
230 /******************************************/
231 
232 /*
233 
234  fac_dgain = fabs( (float)(OMUTHR.CoolTT - OMUTHR.CoolTmp));
235  fac_pgain = (OMUTHR.CoolTT / OMUTHR.CoolTmp);
236 
237  if (mod)
238  {
239  if(I_Counter++ > I_COUNT_MAX)
240  {
241  I_Counter=0; //-- Counter slows the response of I
242  Intergral++; //-- Only Increase Integral if less than target
243  if(Intergral > I_VALUE_MAX) Intergral=I_VALUE_MAX;
244  }
245  //pow = pow+((OMU.CoolTT / OMU.CoolTmp) * (float) P_GAIN) + (Intergral * (float) I_GAIN) + (((float)fabs(OMU.CoolTT - OMU.CoolTmp)) * (float) D_GAIN) ;
246  pow = pow + (int)(fac_pgain * pgain) + ((float)Intergral * igain)+(fac_dgain * dgain) ;
247  }
248  else
249  {
250  if(I_Counter++ > (I_COUNT_MAX*I_COUNT_DEC)) //-- Slower decrease of value
251  {
252  I_Counter=0; //-- Counter slows the response of I
253  if(Intergral !=0)Intergral--;
254  }
255  //temp= ((OMUTHR.CoolTT / OMUTHR.CoolTmp) * (float) P_GAIN) + (Intergral * (float) I_GAIN) + (((float)fabs(OMUTHR.CoolTT - OMUTHR.CoolTmp)) * (float) D_GAIN) ;
256  temp = (int)(fac_pgain * pgain) + (Intergral * igain) + (fac_dgain * dgain);
257  pow = pow - temp;
258 
259  }
260 
261  return (pow);
262 */
263 }
264 
265 
266 
267 float Calculate(float TARGET,float CURRENT, float POWER)
268 {
269 // float POWER;
270 
271 
272 // if(TARGET <= CURRENT)
273  if( (CURRENT - TARGET) >= 0.2 )
274  {
275  if(CURRENT < (TARGET - CONTROLED_BAND))
276  {
277  POWER=90;
278  Intergral=0;
279  }
280  else
281  {
282  if(CURRENT != TARGET)
283  {
284  if(I_Counter++ > I_COUNT_MAX)
285  {
286  I_Counter=0; //-- Counter slows the response of I
287  Intergral++; //-- Only Increase Integral if less than target
289  }
290  }
292  //-- P.I.D Proportional Integral Derivative
293  POWER = ((TARGET / CURRENT) * ((float) P_GAIN/4)) + (Intergral * (float) I_GAIN/4) + (((float)fabs(TARGET - CURRENT)) * ((float) D_GAIN/4)) ;
294  else
295  POWER = ((TARGET / CURRENT) * (float) P_GAIN) + (Intergral * (float) I_GAIN) + (((float)fabs(TARGET - CURRENT)) * (float) D_GAIN) ;
296  }
297  }
298  else
299  {
300 
301  //if(TARGET > CURRENT)
302  if( (CURRENT - TARGET) <= -0.2 )
303  POWER=POWER - (float) 0.1;
304  else
305  POWER = POWER;
306  if(I_Counter++ > (I_COUNT_MAX*I_COUNT_DEC)) //-- Slower decrease of value
307  {
308  I_Counter=0; //-- Counter slows the response of I
309  if(Intergral !=0)Intergral--;
310  }
311  }
312 
313  if(POWER > 90) POWER = 90;
314 
315  if(POWER <= 0) POWER = 0;
316 
317  if(CURRENT > MAX_TEMP) POWER=0;
318 
319  return(POWER);
320 }
321 
322 
323 /*
324  switch Peltier Rele'
325  param: int mod: 0 -> Peltier Heat; 1 -> Peltier Cold
326 
327 */
328 void OMU_ChooseDir(int mod)
329 {
330 
331 
332  switch (mod)
333  {
334  case 0 :
335  if(DAS.Paramini.EqType == SPATRAM2 )
336  {
337 
338  Peltier(0);
339  PeltFlg = 1; //Raffredda per SPATRAM2
340  FANPeltier(1);
341  FANFlg = 1;
342  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[0], "SYS\\pltcool.bmp");
343  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[1], "SYS\\pltoff.bmp");
344 
345  }
346  else
347  {
348  Peltier(0);
349  PeltFlg = 0; //Scalda
350  FANPeltier(0);
351  FANFlg = 0;
352  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[0], "SYS\\pltoff.bmp");
353  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[1], "SYS\\pltheat.bmp");
354  }
355  break;
356  case 1:
357  if(DAS.Paramini.EqType == SPATRAM2 )
358  {
359  Peltier(1);
360  PeltFlg = 0; //Scalda per SPATRAM2
361  FANPeltier(0);
362  FANFlg = 0;
363  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[0], "SYS\\pltcool.bmp");
364  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[1], "SYS\\pltoff.bmp");
365 
366  }
367  else
368  {
369  Peltier(1);
370  PeltFlg = 1; //Raffredda
371  FANPeltier(1);
372  FANFlg = 1;
373  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[0], "SYS\\pltcool.bmp");
374  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[1], "SYS\\pltoff.bmp");
375  }
376  break;
377  }
378 /*
379  if(DAS.Paramini.EqType == SPATRAM2)
380  {
381  mod =! mod;
382  }
383 
384 
385  Peltier(mod);
386  PeltFlg = mod; //Scalda (0) per SPATRAMPLUS, NG1,2,3, TropoGAS, LIS o Raffredda(1) per SPATRAM2
387  FANPeltier(mod);
388  FANFlg = mod;
389 
390  if(DAS.Paramini.EqType == SPATRAM2 & mod == 0)
391  {
392  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[0], "SYS\\pltcool.bmp");
393  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[1], "SYS\\pltoff.bmp");
394 
395  }
396  else if(DAS.Paramini.EqType == SPATRAM2 & mod == 1)
397  {
398  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[0], "SYS\\pltoff.bmp");
399  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[1], "SYS\\pltheat.bmp");
400  }
401  else
402  {
403  if (mod==0)
404  {
405  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[0], "SYS\\pltoff.bmp");
406  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[1], "SYS\\pltheat.bmp");
407  }
408  if (mod==1)
409  {
410  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[0], "SYS\\pltcool.bmp");
411  MPixmapSetImageFile(DAS.Gui.ContrPanel.ledpelt[1], "SYS\\pltoff.bmp");
412  }
413 
414  }
415 
416 */
417 
418 }
419 
420 /*
421  Assign power to peltier
422  param: int pow: Power (for Heating or cooling) to be assigned to the peltier
423 
424 */
425 void OMU_AssignPow(int pow)
426 {
427 
428  char buff[80];
429  float PowerOn, PowerOff;
430 
431  AMS_PWM(AMS2, 0, 0);
432 
433  if(pow>LIM_PELTPOW)
434  pow = LIM_PELTPOW;
435  if(pow<0)
436  pow = 0;
437 
438  PowerOn = (LISTEMP_TASK_TIME * (float)((double) pow / MAX_PELTPOW) );// * OMUTHR.CoolCnt;
439  PowerOff = LISTEMP_TASK_TIME * OMUTHR.CoolCnt - PowerOn;
440  if (PowerOn == 0)
441  {
442  PowerOn += 1;
443  PowerOff -= 1;
444  }
445  if (PowerOff == 0)
446  {
447  PowerOff += 1;
448  PowerOn -= 1;
449  }
450 
451  AMS_PWM(AMS2, (int)PowerOn, (int)PowerOff); //scalda
452  //Label della percentuale
453  if(PeltFlg) // = 1 Raffredda
454  sprintf(buff,"-%.1lf%%",(double) (PowerOn/LISTEMP_TASK_TIME*100));
455  else //Riscalda
456  sprintf(buff,"+%.1lf%%",(double) (PowerOn/LISTEMP_TASK_TIME*100));
457 
458  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[7], buff);
459 
460 
461 }
462 
463 /*
464  switch Peltier Rele' and assign power to peltier
465  param:
466  int mod: 0 -> Peltier Heat; 1 -> Peltier Cold
467  int pow: Power (for Heating or colding) to be assigned to the peltier
468 
469 */
470 void OMU_DoPeltPow(int mod, int pow)
471 {
472 
473  int c = mod;
474  int p = pow;
475  static int olddir = 1;
476 
477 // if(FlgSM_Stop)
478 // {
479 
480 
481 
482  if(DAS.Paramini.EqType == SPATRAM2)
483  {
484  c =! c;
485  olddir=0;
486  }
487 
488 
489 /* if(c == olddir)
490  {
491  OMU_ChooseDir(c);
492  olddir = c;
493  }
494  else
495  {
496 */
497  AMS_PWM_OFF(AMS2);
498  AMS_PWM_Zero(0);
499  olddir = c;
500  OMU_ChooseDir(c);
501 
502 // }
503 
504  //olddir = c;
505 
506  OMU_AssignPow(p);
507 
508 // }
509 
510 
511 
512 }
513 int OMU_ColdOnly(void)
514 {
515 
516 
517  // Esegue questo blocco se la target temp e minore di quella letta
518  if(OMUTHR.CoolTT < OMUTHR.CoolTmp)
519  {
520  // Incrementa il power solo se la temperatura letta e' >= della precedente
521  if(OMUTHR.CoolTmp >= OMUTHR.CoolPT)
522  {
523  if(OMUTHR.PCPower < LIM_PELTPOW)
524  {
525 
526  if(OMUTHR.PID_On) //PID Algorithm
527  {
528  OMUTHR.PCPower = PID_Calc(1, OMUTHR.PCPower);
529  }
530  else //Progressive algorithm
531  {
532  OMUTHR.PCPower++;
533  }
534  OMU_DoPeltPow(1, OMUTHR.PCPower);
535  }
536  }
537  }
538  // Esegue questo blocco se la target temp e maggiore di quella letta
539  if(OMUTHR.CoolTT > OMUTHR.CoolTmp)
540  {
541  // Decrementa il power solo se la temperatura letta e' <= della precedente
542  if(OMUTHR.CoolTmp <= OMUTHR.CoolPT)
543  {
544  if(OMUTHR.PCPower > 0)
545  {
546 
547  if(OMUTHR.PID_On) //PID Algorithm
548  {
549  OMUTHR.PCPower = PID_Calc(0, OMUTHR.PCPower);
550  }
551  else //Progressive algorithm
552  {
553  OMUTHR.PCPower--;
554  }
555  OMU_DoPeltPow(1, OMUTHR.PCPower);
556  }
557  }
558  }
559  return 0;
560 }
561 
562 int OMU_HeatOnly(void)
563 {
564 
565 
566  // Esegue questo blocco se la target temp e maggiore di quella letta
567  if(OMUTHR.CoolTT > OMUTHR.CoolTmp)
568  {
569  // Incrementa il power solo se la temperatura letta e' <= della precedente
570  if(OMUTHR.CoolTmp <= OMUTHR.CoolPT)
571  {
572  if(OMUTHR.PCPower < LIM_PELTPOW)
573  {
574  OMUTHR.PHPower++;
575  OMU_DoPeltPow(0, OMUTHR.PHPower);
576 
577  }
578  }
579  }
580  // Esegue questo blocco se la target temp e minore di quella letta
581  if(OMUTHR.CoolTT < OMUTHR.CoolTmp)
582  {
583  // Decrementa il power solo se la temperatura letta e' >= della precedente
584  if(OMUTHR.CoolTmp >= OMUTHR.CoolPT)
585  {
586  if(OMUTHR.PHPower > 0)
587  {
588  OMUTHR.PHPower--;
589  OMU_DoPeltPow(0, OMUTHR.PHPower);
590 
591  }
592  }
593  }
594  return 0;
595 }
596 
597 int OMU_HC(void)
598 {
599 // PID_Calc
600 //mod = 1 --> Aumenta Power
601 //mod = 0 --> Diminuisce Power
602 
603 
604 
605 
606 
607  int TLimit = 0;//limite di soglia della temp (decimi di grado)
608  /*-------------------------------------------------------------*/
609 
610 
611 
612  if((OMUTHR.CoolTmp - OMUTHR.CoolTT) > TLimit )
613  {
614  OMUTHR.PCPower = PID_Calc(1, OMUTHR.PCPower);
615  if(OMUTHR.PCPower >= LIM_PELTPOW)
616  OMUTHR.PCPower = LIM_PELTPOW;
617  OMU_DoPeltPow(1, OMUTHR.PCPower);
618  OMUTHR.PHPower =0;
619  }
620  else if((OMUTHR.CoolTmp - OMUTHR.CoolTT) < -TLimit )
621 
622  {
623  OMUTHR.PHPower = PID_Calc(0, OMUTHR.PHPower);
624  if(OMUTHR.PHPower >= LIM_PELTPOW)
625  OMUTHR.PHPower = LIM_PELTPOW;
626  OMU_DoPeltPow(0, OMUTHR.PHPower);
627  OMUTHR.PCPower =0;
628  }
629 
630 
631 
632 /*
633  //Raffredda
634  // Esegue questo blocco se la target temp e minore di quella letta + Tlimit
635  if((OMUTHR.CoolTmp - OMUTHR.CoolTT) > TLimit )
636  {
637  // Incrementa il power x COLD solo se la temperatura letta e' >= della precedente
638 // if( ( ((OMUTHR.CoolPT - OMUTHR.CoolTT) > 0) & ((OMUTHR.CoolPT - OMUTHR.CoolTmp) >= 0) )
639 // |
640 // ( ((OMUTHR.CoolPT - OMUTHR.CoolTT) > 0) & ((OMUTHR.CoolPT - OMUTHR.CoolTmp) < 0) ) )
641  if( ((OMUTHR.CoolTmp - OMUTHR.CoolPT) > 0 ))
642  {
643 
644  if(OMUTHR.PCPower < LIM_PELTPOW)
645  {
646  if(OMUTHR.PID_On) //PID Algorithm
647  OMUTHR.PCPower = PID_Calc(1, OMUTHR.PCPower);
648  else //Progressive algorithm
649  OMUTHR.PCPower++;
650  }
651  }
652  else if( ((OMUTHR.CoolTmp - OMUTHR.CoolPT) == 0 )) //if the temperature is the same as the previous check, apply only the power
653  {
654 
655  }
656  else
657  {
658  if(OMUTHR.PCPower > 0)
659  {
660  if(OMUTHR.PID_On) //PID Algorithm
661  OMUTHR.PCPower = PID_Calc(0, OMUTHR.PCPower);
662  else //Progressive algorithm
663  OMUTHR.PCPower--;
664  }
665 
666  }
667 
668  OMUTHR.PCPower = PID_Calc(1, OMUTHR.PCPower);
669  if(OMUTHR.PCPower >= LIM_PELTPOW)
670  OMUTHR.PCPower = LIM_PELTPOW;
671 
672  OMU_DoPeltPow(1, OMUTHR.PCPower);
673  }
674 
675  /*-------------------------------------------------------------*/
676 /*
677  // Esegue questo blocco se la target temp e maggiore di quella letta
678  if((OMUTHR.CoolTmp - OMUTHR.CoolTT) < -TLimit)
679  {
680  // Incrementa il power X HEAT solo se la temperatura letta e' <= della precedente
681  // if(OMUTHR.CoolTmp <= OMUTHR.CoolPT)
682  if( ( ((OMUTHR.CoolPT - OMUTHR.CoolTT) < 0) & ((OMUTHR.CoolPT - OMUTHR.CoolTmp) <= 0) )
683  |
684  ( ((OMUTHR.CoolPT - OMUTHR.CoolTT) < 0) & ((OMUTHR.CoolPT - OMUTHR.CoolTmp) > 0) ) )
685 
686  {
687  if(OMUTHR.PHPower <= LIM_PELTPOW)
688  {
689  if(OMUTHR.PID_On) //PID Algorithm
690  OMUTHR.PHPower = PID_Calc(1, OMUTHR.PHPower);
691  else //Progressive algorithm
692  OMUTHR.PHPower++;
693  }
694  }
695  else
696  {
697  if(OMUTHR.PHPower >= 0)
698  {
699  if(OMUTHR.PID_On) //PID Algorithm
700  OMUTHR.PHPower = PID_Calc(0, OMUTHR.PHPower);
701  else //Progressive algorithm
702  OMUTHR.PHPower--;
703  }
704  }
705  OMU_DoPeltPow(0, OMUTHR.PHPower);
706  }
707 
708  // Esegue questo blocco se la temperatura letta e' tra i limiti
709  if((OMUTHR.CoolTmp - OMUTHR.CoolTT) <= TLimit && (OMUTHR.CoolTmp - OMUTHR.CoolTT) >= -TLimit)
710  {
711  if((OMUTHR.CoolTmp - OMUTHR.CoolTT) > 0) //temp letta maggiore di temp target
712  {
713  if((OMUTHR.CoolPT - OMUTHR.CoolTmp) >= 0) //caso 1
714  {
715  if(OMUTHR.PCPower > 0)
716  {
717  if(OMUTHR.PID_On) //PID Algorithm
718  OMUTHR.PCPower = PID_Calc(0, OMUTHR.PCPower); // 0 = Diminuisce, 1 = Aumenta Power
719  else //Progressive algorithm
720  OMUTHR.PCPower--;
721  }
722  }
723  if((OMUTHR.CoolPT - OMUTHR.CoolTmp) < 0) //caso 4
724  {
725  if(OMUTHR.PCPower <= LIM_PELTPOW)
726  {
727  if(OMUTHR.PID_On) //PID Algorithm
728  OMUTHR.PCPower = PID_Calc(1, OMUTHR.PCPower);
729  else //Progressive algorithm
730  OMUTHR.PCPower++;
731  }
732  }
733 
734  OMU_DoPeltPow(1, OMUTHR.PCPower); // 1 = Raffredda
735  }
736  if((OMUTHR.CoolTmp - OMUTHR.CoolTT) < 0) //temp letta minore di temp target
737  {
738  if((OMUTHR.CoolPT - OMUTHR.CoolTmp) >= 0) //caso 3
739  {
740  if(OMUTHR.PHPower <= LIM_PELTPOW)
741  {
742  if(OMUTHR.PID_On) //PID Algorithm
743  OMUTHR.PHPower = PID_Calc(1, OMUTHR.PHPower); // 0 = Diminuisce, 1 = Aumenta Power
744  else //Progressive algorithm
745  OMUTHR.PHPower++;
746  }
747  }
748  if((OMUTHR.CoolPT - OMUTHR.CoolTmp) < 0) //caso 4
749  {
750  if(OMUTHR.PHPower > 0)
751  {
752  if(OMUTHR.PID_On) //PID Algorithm
753  OMUTHR.PHPower = PID_Calc(0, OMUTHR.PHPower);
754  else //Progressive algorithm
755  OMUTHR.PHPower--;
756  }
757  }
758 
759  OMU_DoPeltPow(0, OMUTHR.PHPower); // 0 = Riscalda
760  }
761 
762  }
763 
764 */
765 
766  return 0;
767 
768 }
769 
770 
771 
772 
774 {
775  int c;
776 
777 
778 
779  OMUTHR.CoolCnt--;
780  if(OMUTHR.CoolCnt == 0)
781  {
782  // Calcola il numero di interventi in funzione del salto
783  // termico che deve effettuare
784  // DANBO ADDENDA
785  // Ricorda che nella funzione chiamante bisogna mettere un blocco del tipo:
786  //***************************
787  // if(OMUTHR.CoolCnt == 1)
788  // OMU_TemperatureHandle();
789  // else
790  // OMUTHR.CoolCnt--;
791  //***************************
792  // In questo modo se Coolcnt = 1, si esegue la routine, in caso contrario si
793  // decrementa il contatore fino a quando e' 1 (quindi si ritarda l'applicazione
794  // di eventuali modifiche di un certo intervallo di tempo
795  // (Es. coolCnt = 4, delay di 2 secondi - 0.500ms x 4 = 2 sec)
796  // (Es. coolCnt = 5, delay di 2.5 secondi - 0.500ms x 5 = 2.5 sec)
797 
798 
799  OMUTHR.CoolCnt = (int) fabs(OMUTHR.CoolTT - OMUTHR.CoolAT);
800  if(OMUTHR.CoolCnt >= 40) //4°
801  OMUTHR.CoolCnt = 1;//20; //1; // 0.5 s
802  else
803  {
804  if(OMUTHR.CoolCnt >= 20) //2°
805  OMUTHR.CoolCnt = 1;//10;//2; // 1 s
806  else
807  {
808  if(OMUTHR.CoolCnt >= 10) //1°
809  OMUTHR.CoolCnt = 1;//3;//3; // 1.5 s
810  else
811  {
812  if (DAS.DOption.refertemp == 0) // Internal Peltier
813  {
814  if(OMUTHR.CoolCnt >= 2) //0.5°
815  OMUTHR.CoolCnt = 2; //4; // 2 s
816  else
817  OMUTHR.CoolCnt = 1; //5; // 2.5 s
818  }
819  if (DAS.DOption.refertemp == 1) // OPTIC
820  {
821  if(OMUTHR.CoolCnt >= 5) //0.5°
822  OMUTHR.CoolCnt = 20; // 10 s
823  else
824  OMUTHR.CoolCnt = 40; // 20 s
825  }
826  if (DAS.DOption.refertemp == 2) // Grating
827  {
828  if(OMUTHR.CoolCnt >= 5) //0.5°
829  OMUTHR.CoolCnt = 1;//4;//10; // 10 s
830  else
831  OMUTHR.CoolCnt = 1;//2;//20; // 40 s
832  }
833 
834  }
835  }
836  }
837  // Flush dei decimali oltre il decimo di grado
838  c = (int) (OMUTHR.CoolAT * 10);
839  OMUTHR.CoolTmp = (float) c;
840  OMUTHR.CoolTmp /= 10;
841 
842  switch(OMUTHR.TRType)
843  {
844  case TRTCOOL :
845  OMU_ColdOnly();
846  break;
847  case TRTHEAT:
848  OMU_HeatOnly();
849  break;
850  case TRTBOTH:
851  OMU_HC();
852  //D_PID();
853  break;
854  }
855  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
856  if(OMUTHR.CoolTT == OMUTHR.CoolTmp)
857  {
858  OMUTHR.ReachTemp = 1;
859  OMUTHR.CoolSts = 3;
860  }
861  else
862  {
863  OMUTHR.ReachTemp = 0;
864  OMUTHR.CoolSts = 2;
865  }
866  OMUTHR.CoolPT = OMUTHR.CoolTmp;
867  }
868 
869  return 0;
870 }
871 
872 
874 
875 {
876  static float power;
877  double DeltaT;
878  extern int FirstTime;
879  extern int DeltaTPrec;
880  extern int Incr_Read_Temp;
881  char Label[30];
882  int DeltaTMax = 300;
883  int DeltaTMin = 0;
884  int stopplt = 0;
885  char str[64];
886 
887  extern char PrgFile[_MAX_PATH];// Nome della tabella da eseguire
888 
889  /**********************************************************************/
890  /********** for OMU Thermoregulation ****************************/
891  //Target temperature
892  OMUTHR.CoolTT = (float)DAS.Paramini.TPelt * 10;
893 
894  // Read Temperatures
895  D_readtemp();
896 
897  //Actual temperature (Reference)
898  switch (DAS.DOption.refertemp)
899  {
900  case 0:
901  if(DAS.Paramini.EqType == LIS_)
902  OMUTHR.CoolAT = (OMUTHR.Temperature[9] + OMUTHR.Temperature[13]) * 10 / 2; //Average internal Peltier
903  else
904  OMUTHR.CoolAT = (OMUTHR.Temperature[12] + OMUTHR.Temperature[14]) * 10 / 2; //Average internal Peltier
905  break;
906  case 1:
907  if(DAS.Paramini.EqType == LIS_)
908  OMUTHR.CoolAT = OMUTHR.Temperature[11] * 10; //Optic LIS
909  else
910  OMUTHR.CoolAT = OMUTHR.Temperature[15] * 10; //Optic
911  break;
912  case 2:
913  OMUTHR.CoolAT = OMUTHR.Temperature[10] * 10; //Grating
914  break;
915  }
916 
917 
918  DeltaT = OMUTHR.CoolAT - OMUTHR.CoolTT;
919 
920  if(FirstTimeP == 0)
921  {
922  FirstTimeP = 1;
923  //OMUTHR.PCPower = 550;
924  OMUTHR.PHPower = OMUTHR.PCPower;// / 3;
925  }
926 
927 
928  //Security control
929  //Ccontrollo sulle temperature esterne
930  //Se una o l'altra temperatura ext sono maggiori di 55 gradi
931  // bisogna spegnere le peltier!!!!!!
932  if(DAS.Paramini.EqType == LIS_)
933  {
934  if( (OMUTHR.Temperature[8] > 55) | (OMUTHR.Temperature[12] > 55) )
935  stopplt = 1;
936  }
937  else
938  {
939  if( (OMUTHR.Temperature[11] > 55) | (OMUTHR.Temperature[13] > 55) )
940  stopplt = 1;
941  }
942 
943  if(stopplt)
944  {
945  if(FlgSM_Stop)
946  {
947  OMU_ChooseDir(1);
948  OMU_AssignPow(0); //Peltier OFF
949  }
950  }
951  else
952  {
953  //OMU Thermo Regulation
954  if(OMUTHR.CoolCnt == 1)
956  else
957  OMUTHR.CoolCnt--;
958  }
959  //Label deltaT
960  sprintf(Label,"%.02lf", DeltaT/10);
961  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[6], Label);
962  /**********************************************************************/
963 /************************************************************************************/
964 // Procedura per scegliere la temperatura di esercizio del CCD a diversi SZA
965 // se si sta eseguendo una tabella di misure.
966 
967  if((PrgFile[0] != 0) | (Master == 1)) // Se si esegue una tabella
968  {
969  if(FLAG.settempvar) //Se il flag per la temperatura variabiele è attivo
970  {
971  if( (S_zenetr >= 80) & (S_zenetr <= 95))
972  {
973  if(FLAG.settemp8095)
974  {
975  // Imposta la temperatura di esercizio CCDTemp
976  DC_SetTemp( -15.0, CELSIUS, 0);
977  // Imposta la potenza del cooler del CCD
978  DC_SetPower((double)35.0, 0);
979  sprintf(str, "%.1lf", -15.00);
980  MObjectSetText(DAS.Gui.ContrPanel.lbl_Par[0], str);
981  sprintf(str,"%.1lf%%",35.00);
982  MObjectSetText(DAS.Gui.ContrPanel.lbl_Par[1], str);
983  FLAG.settemp8095 = 0;
984  FLAG.settemp7080 = 1;
985  FLAG.settemp070 = 1;
986  }
987  }
988  else if( (S_zenetr >= 70) & (S_zenetr < 80))
989  {
990  if(FLAG.settemp7080)
991  {
992  // Imposta la temperatura di esercizio CCDTemp
993  DC_SetTemp( -5.0, CELSIUS, 0);
994  // Imposta la potenza del cooler del CCD
995  DC_SetPower((double)35.0, 0);
996  sprintf(str, "%.1lf", -5.00);
997  MObjectSetText(DAS.Gui.ContrPanel.lbl_Par[0], str);
998  sprintf(str,"%.1lf%%",35.00);
999  MObjectSetText(DAS.Gui.ContrPanel.lbl_Par[1], str);
1000  FLAG.settemp8095 = 1;
1001  FLAG.settemp7080 = 0;
1002  FLAG.settemp070 = 1;
1003  }
1004  }
1005  else if( ((S_zenetr >= 0) & (S_zenetr < 70)) | (S_zenetr > 95))
1006  {
1007  if(FLAG.settemp070)
1008  {
1009  // Imposta la temperatura di esercizio CCDTemp
1010  DC_SetTemp( 5.0, CELSIUS, 0);
1011  // Imposta la potenza del cooler del CCD
1012  DC_SetPower(DAS.Paramini.CoolPw/10, 0);
1013  sprintf(str, "%.1lf", 5.00);
1014  MObjectSetText(DAS.Gui.ContrPanel.lbl_Par[0], str);
1015  sprintf(str,"%.1lf%%",DAS.Paramini.CoolPw/10.00);
1016  MObjectSetText(DAS.Gui.ContrPanel.lbl_Par[1], str);
1017  FLAG.settemp8095 = 1;
1018  FLAG.settemp7080 = 1;
1019  FLAG.settemp070 = 0;
1020  }
1021  }
1022 
1023  }
1024  }
1025 
1026  /******************************************************/
1027  //Fan ECU
1028 
1029  if (OMUTHR.Temperature[8] >= 22)
1030  FANECU(1);
1031  else
1032  FANECU(0);
1033 
1034 
1035 
1036 /************************************************************************************/
1037 
1038  if((FLAG.ADPC104 == 0) | (FLAG.ADTempTest == 0))
1039 // if(!FLAG.AMS_H)
1040  MAddTimeout(LISTEMP_TASK_TIME, Task_LIS_Temp, data); // rilancia il task
1041 
1042  DeltaTPrec = (int) DeltaT;
1043 
1044 }
1045 
1046 /********************************************************************/
1047 void Task_AMSH(TIMEOUT_ID id, void *data)
1048 {
1049 
1050  int d,er;
1051 
1052 
1053 
1054  // Read input
1055  d = AMS_chkbitsts(AMS1, 3);
1056  FLAG.AMS_H = 1;
1057  if (d==0)
1058  {
1059 
1060  er = AMS_TrackOff(AMS1, 1, 0);
1061  FLAG.AMS_H = 0;
1062  }
1063 
1064  if(FLAG.AMS_H)
1065  MAddTimeout(AMSH_TASK_TIME, Task_AMSH, data); // rilancia il task
1066 }
1067 
1069 {
1070  char ActTemp[16], buf[16];
1071  char buff[128];
1072  int er = 0;
1073  double CCD_Pwr;
1074  unsigned long et;
1075  static unsigned long starttime;
1076  double tout,x;
1077  SYSTEM_POWER_STATUS status;
1078 
1079  //Read the CCD Temperature
1080  DC_GetTemp(ActTemp, CELSIUS, 0);
1081 
1082  /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
1083  /******************************************************************************************/
1084  /* These few line of code are necessary because for the period 00:00:00-01:00:00
1085  sometimes the DC_GetTemp procedure returns an empty string, so the code check if
1086  the second character of the returned string is not 0 (normally it has to be + or -)
1087  and in this case assign the temperature to the DAS.Marconi.CCDTemp variable, otherwhise
1088  it mantain the previous value
1089  */
1090  /******************************************************************************************/
1091  if (ActTemp[1] != 0)
1092  {
1093  DAS.Marconi.CCDTemp = (float) atof(ActTemp);
1094  sprintf(buf, "%0.1lf", DAS.Marconi.CCDTemp);
1095  MObjectSetText(DAS.Gui.ContrPanel.Albl_CS[0], buf);
1096  }
1097  /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
1098 
1099  /* If the temperature is -273.15 the USB connection is lost and the camera have to be reinitializied */
1100  if (DAS.Marconi.CCDTemp < -250)
1101  {
1104  if(FLAG.exec)
1105  {
1106  FLAG.exec = 0;
1107  FLAG.REINITCCD = 0;
1108  starttime = GetTickCount()-1000;
1109 
1110  Status("Camera Re-Init in 60 sec");
1111 
1112  if(DAS.Flag.DeltaSZA == 1)
1113  {
1114  DAS.Flag.ExeDSZA = 0; //Stop PRG Execution
1115 
1116  // SZADelta.LastMSZA = S_zenetr;
1117  // D_FixSZA();
1118  }
1119 
1120  }
1121 
1122  if(FLAG.exec == 0 && FLAG.REINITCCD == 0)
1123  {
1124  et = GetTickCount();
1125  x = labs(et - starttime)/1000.0;
1126  if(x <60)
1127  {
1128 
1129  tout = 60.0 - x;
1130  sprintf (buff,"Camera Init in %.1lf sec", tout);
1131  Status(buff);
1132  }
1133  else
1134  FLAG.REINITCCD = 1;
1135 
1136  }
1137 
1138 
1139  if(FlgSM_Stop && FLAG.REINITCCD)
1140  {
1141  er = DB_InitCamera(1);
1142 
1143  FLAG.exec = 1;
1144  FLAG.REINITCCD = 0;
1145  Status("Ready");
1146  // If a SZAPRG or a *.PRG file is in execution with the DeltaSZA Mode activated
1147  // the next SZA has to be recalculated
1148 
1149 
1150  if(DAS.Flag.DeltaSZA == 1)
1151  {
1152  DAS.Flag.ExeDSZA = 1; //PRG Execution
1153 
1155  D_FixSZA();
1156 
1157  }
1158 
1159 
1160  }
1161 
1162 
1163 
1164  }
1165 
1166 
1167  /******************************************************************************************/
1168 
1169  if( DAS.Marconi.CCDTemp <= DAS.Paramini.ITemp)
1170  //if( fabs(DAS.Marconi.CCDTemp - DAS.Paramini.ITemp) <= 1.00)
1171  {
1172  OMUTHR.ReachTemp = 1;
1173 // Status("CCD Temp Reached");
1174 
1175  }
1176 // else
1177 // {
1178 // OMUTHR.ReachTemp = 0;
1179 
1180 // }
1181 
1182  er = DC_CoolerStatus(0);
1183 
1184  switch (er)
1185  {
1186  case 0:
1187 // Status("Cooler Not Activated");
1188  break;
1189 // case 1:
1190 // Status("Cooler Active without temp. control");
1191 // break;
1192  case 1:
1193 // Status("Cooler Active, waiting for equilibrium");
1194  break;
1195  case 2:
1196 // Status("Equilibrium Reached");
1197 // LIS.ReachTemp = 1;
1198  break;
1199  case 3:
1200 // Status("Equilibrium Reached");
1201  // OMUTHR.ReachTemp = 1;
1202  break;
1203 
1204  case 4:
1205 // Status("ShutDown in Progress");
1206  break;
1207  case 5:
1208 // Status("ShutDown Done");
1209  break;
1210 
1211  }
1212 
1213  CCD_Pwr = DC_GetPower(0);
1214  sprintf(buf, "%.1lf%%", CCD_Pwr);
1215  MObjectSetText(DAS.Gui.ContrPanel.Albl_CS[1], buf);
1216 
1217 /*******************************************************************************************/
1218  // These lines of code are related to the possibility of a UPS linked to the
1219  // instrument:
1220  // 1) The UPS is a serial one (recognized by the Operating System) therefore DAS
1221  // uses the windows API to be adviced about the battery utilization
1222  // 2) The UPS utilize a open collector/open emitter technology, so DAS knows about the
1223  // utilization of the battery with the inputs port of the mainboard I/O
1224 
1225  // 1)
1226  //Check the Supply status
1227  GetSystemPowerStatus( &status );
1228 
1229  switch (status.ACLineStatus)
1230  {
1231  case 1: // Power On Line
1232  if(DAS.Flag.UPS_Battery == 1)
1233  DAS.Flag.UPS_Battery = 2;
1234  else
1235  DAS.Flag.UPS_Battery = 0;
1236  break;
1237  case 0: //Battery on line
1238  DAS.Flag.UPS_Battery = 1;
1239  break;
1240  }
1241 
1242  // 2)
1243  //Check the Supply status
1244 /* er = NOVA_In(DAS.Nova.type, DAS.Nova.DigIn);
1245  er = ChkDigIO(DAS.Nova.DigIn, 0);
1246  if(er==1)
1247  DAS.Flag.UPS_Battery = 1;
1248  if (er == 0 & DAS.Flag.UPS_Battery == 1)
1249  DAS.Flag.UPS_Battery = 2;
1250 */
1251 
1252 
1253 
1254  // Common
1255  if (DAS.Flag.UPS_Battery == 1) // UPS battery ON
1256  {
1257  //Shutdown CCD sensor
1258  DC_SetTemp(25.0, CELSIUS, 0);
1259 
1260  //Switch off the Peltier
1261 
1262  }
1263  else if (DAS.Flag.UPS_Battery == 2)
1264  {
1265  DAS.Flag.UPS_Battery = 0;
1266  // Set CCD Temperature
1267  DC_SetTemp(DAS.Paramini.ITemp, CELSIUS, 0);
1268  // Set CCD Cooler Power
1269  DC_SetPower((double) ((double)DAS.Paramini.CoolPw / 10),0);
1270 
1271  //Switch on the Peltier
1272 
1273 
1274  }
1275 /*******************************************************************************************/
1276 
1277  MAddTimeout(CCDTEMP_TASK_TIME, Task_CCD_Temp, data); // rilancia il task
1278 
1279 
1280 
1281 
1282 }
1283 
1284 int D_readtemp(void)
1285 {
1286 
1287  extern int Incr_Read_Temp;
1288  int i;
1289  char buf[24];
1290  double t, TRef, DeltaT;
1291  double temp;
1292  int NumSamples, x, KUP = 4096;
1293  float AVGTemp;
1294 
1295  // TEMPERATURES READING
1296  if(FLAG.ADPC104 == 0)
1297  {
1298  D_rt();
1299 
1300  for (i=0; i<16; i++)
1301  {
1302  if(FLAG.ADTempTest == 0)
1303  {
1304 // temp = Tmp[i][AD_SAMPLING/2];
1305  temp = OMUTHR.ADVolt[i];
1306 // Tmp[i][AD_SAMPLING/2] = (66.66666666666666666 * (temp) - 273.16);
1307  OMUTHR.ADVolt[i] = (66.66666666666666666 * (temp) - 273.16);
1308 
1309  //Shift of the Temperature Buffer
1310  for(x= KUP-1;x>0;x--)
1311  {
1312  OMUTHR.Temptemp[i*KUP+x]= OMUTHR.Temptemp[i*KUP+x-1];
1313  }
1314  // Put the last retrieved temperature in the first place of the register
1315  //LIS.Temptemp[i*KUP]= Tmp[i][AD_SAMPLING/2];
1316  OMUTHR.Temptemp[i*KUP]= (float) OMUTHR.ADVolt[i];
1317 
1318  AVGTemp = 0;
1319  NumSamples = 1;
1320 
1321  //Calc the average temperature considering
1322  //(if the register is full)only the firsts
1323  //KUP/8 (4096/8=512) values (about 7 Minutes of sampling)
1324  //KUP/16 (4096/16=256) values (about 3.5 Minutes of sampling)
1325  for(x=0;x<KUP/64;x++)
1326  {
1327  if(OMUTHR.Temptemp[i*KUP+x] != 0)
1328  {
1329  AVGTemp += OMUTHR.Temptemp[i*KUP+x];
1330  NumSamples++;
1331  }
1332 
1333 
1334  }
1335  AVGTemp =AVGTemp / (NumSamples-1);
1336 
1337 
1338  //sprintf(str, "Channel %d", i);
1339  //sprintf(buf, "%.1f", (float)Tmp[i][AD_SAMPLING/2]);
1340  sprintf(buf, "%.1f", (float)AVGTemp);
1341 
1342 
1343 
1344  //LIS.LisT[i] = (float) Tmp[i][AD_SAMPLING/2];
1345  OMUTHR.Temperature[i] = (float) AVGTemp;
1346 
1347  if(DAS.Paramini.EqType == LIS_)
1348  {
1349  switch(i)
1350  {
1351  case 0:
1352  break;
1353  case 1:
1354  break;
1355  case 2:
1356  break;
1357  case 3:
1358  break;
1359  case 4:
1360  break;
1361  case 5:
1362  break;
1363  case 6:
1364  break;
1365  case 7:
1366  break;
1367  case 8:
1368  //Temp Out DX
1369  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[1], buf);
1370  break;
1371  case 9:
1372  //Temp Int DX
1373  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[3], buf);
1374  break;
1375  case 10:
1376  //Temp GRATING
1377  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[5], buf);
1378  break;
1379  case 11:
1380  //Temp Optic
1381  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[0], buf);
1382  break;
1383  case 12:
1384  //Temp Out SX
1385  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[2], buf);
1386  break;
1387  case 13:
1388  //Temp Int SX
1389  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[4], buf);
1390  break;
1391 
1392  case 14:
1393 
1394  break;
1395 
1396  case 15:
1397  //Temp ELET
1398  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[6], buf);
1399  break;
1400  }
1401 
1402 
1403  }
1404 
1405  else if (DAS.Paramini.EqType == GASCODNG4 || DAS.Paramini.EqType == SPATRAM3)
1406  {
1407  switch(i)
1408  {
1409  case 0:
1410  break;
1411  case 1:
1412  break;
1413  case 2:
1414  break;
1415  case 3:
1416  break;
1417  case 4:
1418  break;
1419  case 5:
1420  break;
1421  case 6:
1422  break;
1423  case 7:
1424  break;
1425  case 8:
1426  //Temp ELET
1427  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[6], buf);
1428  break;
1429  case 9:
1430  //Temp MIGE
1431  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[7], buf);
1432 
1433  break;
1434  case 10:
1435  //Temp GRATING
1436  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[2], buf);
1437  break;
1438  case 11:
1439  //Temp Out DX
1440  sprintf(buf, "%s", "NA");
1441  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[1], buf);
1442  break;
1443  case 12:
1444  //Temp Int DX
1445  sprintf(buf, "%s", "NA");
1446  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[3], buf);
1447  break;
1448  case 13:
1449  //Temp Out SX
1450  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[5], buf);
1451  break;
1452  case 14:
1453  //Temp Int SX
1454  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[4], buf);
1455  break;
1456  case 15:
1457  //Temp Optic
1458  sprintf(buf, "%s", "NA");
1459  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[0], buf);
1460  break;
1461  }
1462 
1463  }
1464  else
1465  {
1466  switch(i)
1467  {
1468  case 0:
1469  break;
1470  case 1:
1471  break;
1472  case 2:
1473  break;
1474  case 3:
1475  break;
1476  case 4:
1477  break;
1478  case 5:
1479  break;
1480  case 6:
1481  break;
1482  case 7:
1483  break;
1484  case 8:
1485  //Temp ELET
1486  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[6], buf);
1487  break;
1488  case 9:
1489  //Temp MIGE
1490  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[7], buf);
1491 
1492  break;
1493  case 10:
1494  //Temp GRATING
1495  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[5], buf);
1496  break;
1497  case 11:
1498  //Temp Out DX
1499  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[1], buf);
1500  break;
1501  case 12:
1502  //Temp Int DX
1503  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[3], buf);
1504  break;
1505  case 13:
1506  //Temp Out SX
1507  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[2], buf);
1508  break;
1509  case 14:
1510  //Temp Int SX
1511  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[4], buf);
1512  break;
1513  case 15:
1514  //Temp Optic
1515  MObjectSetText(DAS.Gui.ContrPanel.Albl_LT[0], buf);
1516  break;
1517  }
1518  }
1519  }
1520 
1521 
1522 
1523  if(FLAG.ADTempTest == 1)
1524  {
1525 
1526  if(ADTESTER.OutputMode) //Temperature in gradi celsius
1527  {
1528  temp = OMUTHR.ADVolt[i];
1529  OMUTHR.ADVolt[i] = (66.66666666666666666 * (temp) - 273.16);
1530  sprintf(buf, "%.1f", OMUTHR.ADVolt[i]);
1531  MObjectSetText(ADTESTER.lblADvalue[i], buf);
1532  }
1533  else
1534  {
1535  sprintf(buf, "%.3f", OMUTHR.ADVolt[i]);// Temperature in Volts
1536  MObjectSetText(ADTESTER.lblADvalue[i], buf);
1537  }
1538 
1539  }
1540 
1541  }
1542  for(i=0;i<16;i++)
1543  OMUTHR.ADVolt[i] = 0;
1544 
1545  //Temperatura di Riferimento
1546  TRef = DAS.Paramini.TPelt * 10;
1547  //Target temperature
1548  switch (DAS.DOption.refertemp)
1549  {
1550  case 0:
1551  t = (OMUTHR.Temperature[12] + OMUTHR.Temperature[14]) *10 / 2; //Average internal Peltier
1552  break;
1553  case 1:
1554  t = OMUTHR.Temperature[15]*10; //Optic
1555  break;
1556  case 2:
1557  t = OMUTHR.Temperature[10] * 10; //Grating
1558  break;
1559  }
1560 
1561  DeltaT = t - TRef;
1562 
1563  //Label deltaT
1564  sprintf(buf,"%.2lf", DeltaT/10);
1565  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[6], buf);
1566 
1567  }
1568 
1569 
1570 
1571  return 0;
1572 
1573 }
1574 
1575 
1576 
1577 
1578 
1580 {
1581 
1582  D_readtemp();
1583 // if (DAS.DOption.aaopmode == 0)
1584 // AASunTrack();
1585 
1586  if(!FLAG.AMS_H)
1587  //MRefreshTimeout(&IDS.REFRTEMP, REFRESHTEMP_TASK_TIME, Task_REFRESH_Temp, NULL);
1588 
1589  MAddTimeout(REFRESHTEMP_TASK_TIME, Task_REFRESH_Temp, data); // rilancia il task
1590 
1591 }
1592 
int settemp070
char PrgFile[16]
Name of the PRG file.
Definition: DAS_Spat.c:91
#define D_GAIN
Definition: Chktemp.c:31
flag FLAG
Definition: CreateForms.c:84
int D_readtemp(void)
Definition: Chktemp.c:1284
void FANPeltier(int mod)
FAN ON/OFF .
Definition: Spat_Device.c:2652
gui Gui
Graphic User Interface Structure.
int settemp7080
MOBJECT Albl_LS[8]
Active Control Panel Labels for LIS status.
double S_zenetr
Definition: SOLPOS.C:92
unsigned int FirstTimeP
Definition: Chktemp.c:64
int DB_InitCamera(int mod)
Initialize Camera Parameters. Procedure that initialize the CCD Camera.
Definition: Init.c:170
int OMU_HeatOnly(void)
Definition: Chktemp.c:562
#define I_COUNT_DEC
Definition: Chktemp.c:51
optionini DOption
Options for DAS execution.
#define AMS2
AMS2 address.
#define MAX_TEMP
Definition: Chktemp.c:59
dsza SZADelta
Definition: DAS_Spat.c:76
int CoolSts
Cool status.
int Master
Definition: DAS_Spat.c:100
int TRType
Type of thermo regulation (0=TRTCOOL, 1 = TRTHEAT, 2= TRTBOTH)
double LastMSZA
SZA of the previous measurement.
int PCPower
Power to the Peltier for Cooling.
void Task_AMSH(TIMEOUT_ID id, void *data)
AMS Home Task. Refresh the temperatures during DAS execution.
Definition: Chktemp.c:1047
void AMS_PWM_OFF(int id)
Definition: Dxl.c:584
int FirstTime
Definition: DAS_Spat.c:110
void MPixmapSetImageFile(MOBJECT pixmap, const char *fname)
das structure (contain all the previous structures) .
int REINITCCD
Flag for CCD re-Initialization: =0 - wait for countdown, =1 - Ready for re-init camera.
int OMU_HC(void)
Definition: Chktemp.c:597
short OMU_TempReached
OMU presetted temperature reached -> = 1.
flag Flag
Structure for different flags.
#define MAX_PELTPOW
Max Power to the Peltier.
das DAS
Definition: Chktemp.c:26
MOBJECT lbl_Par[11]
Parametric Labels of the Control Panel.
void AMS_PWM(int id, int on, int off)
set the on/off time on the PWM set the on/off time on the PWM.
Definition: Dxl.c:492
void OMU_ChooseDir(int mod)
Definition: Chktemp.c:328
float Temperature[16]
Temperatures.
MOBJECT Albl_CS[4]
Active Control Panel Labels for Camera Status 4.
void Peltier(int mod)
Peltier ON/OFF .
Definition: Spat_Device.c:2597
#define AMSH_TASK_TIME
AMS Home.
void MObjectSetText(MOBJECT obj, const char *text)
int OMU_TemperatureHandle(void)
Definition: Chktemp.c:773
float CoolPT
Previous Temperature (DTA -> DC_CoolPT)
void Task_REFRESH_Temp(TIMEOUT_ID id, void *data)
Temperatures Task. Refresh the temperatures during DAS execution.
Definition: Chktemp.c:1579
int PID_Calc(int mod, int pow)
Definition: Chktemp.c:78
int FlgSM_Stop
Steppers Motor Activity: 0 = Motors moving; 1 = Motors stopped.
Definition: DAS_Spat.c:140
#define LIM_PELTPOW
Limited Power to the Peltier.
float Calculate(float TARGET, float CURRENT, float POWER)
Definition: Chktemp.c:267
#define LIS_
Lampedusa Island Spectrometer - ENEA.
float CoolTT
Target Temperature (DTA -> DC_CoolTT)
int exec
= 0 -> PRG Execution Paused; = 1 -> PRG Execution Resumed
CTYPE double DLL DC_GetTemp(char *CurrentTemperature, int Scale, int Camera)
Procedure that allows you to read the temperature of the sensor. Procedure that allows you to read th...
static double delta
Definition: SOLPOS.C:129
int PeltFlg
Definition: DAS_Spatram.h:2971
void Task_LIS_Temp(TIMEOUT_ID id, void *data)
OMU Thermoregulation Task. Provide the thermoregulation of the Optical Mechanical Unit In addition al...
Definition: Chktemp.c:873
void OMU_DoPeltPow(int mod, int pow)
Definition: Chktemp.c:470
MOBJECT lblADvalue[16]
unsigned int data[576]
Conversion data buffer 64 samples * 8 channels * 2 bytes.
#define I_VALUE_MAX
Definition: Chktemp.c:52
float CCDTemp
Actual CCD Temperature.
unsigned char I_Counter
Definition: Chktemp.c:63
int ADTempTest
= 0 -> AD Converter results on the Control Panel; = 1 -> AD Converter Testing Phase(results on the co...
CTYPE void DLL DC_SetTemp(double TargetTemperature, int Scale, int Camera)
Procedure that turns the camera cooler on and allows you to set an operative temperature of the CCD...
float PID_ki
int CoolCnt
Time Counter.
#define TRTHEAT
Thermoregulation mode: heat only.
MOBJECT ledpelt[2]
Control Panel Leds for Peltier Activity.
#define TRTCOOL
Thermoregulation mode: cool only.
int DeltaTPrec
Definition: DAS_Spat.c:111
int settemp8095
int PHPower
Power to the Peltier for Heating.
int PID_On
PID activation.
#define SPATRAM2
SPATRAM2 (with ATX power supply & HiresV)
int CoolPw
CCD Init Power.
float * Temptemp
Buffer for lis temperature.
int UPS_Battery
flag for UPS Battery: = 0 Normal Operation, 1 = working on UPS battery
void Status(char *tit)
Writes information&#39;s on the Status label .
Definition: Load.c:1556
#define I_COUNT_MAX
Definition: Chktemp.c:50
int DeltaSZA
= 1 Delta SZA measurements activated, = 0 Continous measurements
int Incr_Read_Temp
Definition: DAS_Spat.c:101
float CoolTmp
Temporary temperature.
#define LISTEMP_TASK_TIME
spectrometer termoregulation
#define P_GAIN
Definition: Chktemp.c:30
int ADPC104
0 –> Device PC104 exist, 1 –> PC104 DOESN&#39;T exist
Function prototypes.
#define GASCODNG4
GASCODNG 4.
#define _MAX_PATH
Definition: Dildef.h:202
#define SPATRAM3
SPATRAM3.
MOBJECT Albl_LT[16]
Active Control Panel Labels for LIS Temperature 16.
int OMU_ColdOnly(void)
Definition: Chktemp.c:513
Function prototypes.
structure for AD Tester
#define I_GAIN
Definition: Chktemp.c:32
#define CELSIUS
Return CCD temperature in Celsius.
Definition: dcldef.h:449
void D_FixSZA(void)
Definition: RTC_Time.c:467
static double p
Definition: SOLPOS.C:131
CTYPE void DLL DC_SetPower(double CoolerPower, int Camera)
Procedure that allows you to set the cooler power. Procedure that allows you to set the power (%) of ...
unsigned char Intergral
Definition: Chktemp.c:62
int AMS_H
Home AMS.
#define TRTBOTH
Thermoregulation mode: cool and heat.
omuthr OMUTHR
Definition: Chktemp.c:27
#define REFRESHTEMP_TASK_TIME
refresh of the spectrometer&#39;s temperatures.
controlpanel ContrPanel
Control Panel Structure.
int AMS_TrackOff(int id, int amot, int bmot)
tracking off Procedure for Stepper Motor tracking de-activation
Definition: Dxl.c:422
float CoolAT
Actual Temperature (DTA -> DC_Temp)
void FANECU(int mod)
FAN ON/OFF .
Definition: Spat_Device.c:2619
#define AMS1
AMS1 address.
int AMS_chkbitsts(int id, int bitn)
check bit status Procedure for the determination of the bit number status.
Definition: Dxl.c:192
#define CONTROLED_BAND
Definition: Chktemp.c:56
CARD32 TIMEOUT_ID
Definition: Mguidefs.h:1421
int settempvar
float PID_kp
int ExeDSZA
= 1 the measurements are performed, = 0 waiting for the next deltasza.
void OMU_AssignPow(int pow)
Definition: Chktemp.c:425
#define CCDTEMP_TASK_TIME
CCD temperature.
void D_rt(void)
D_readtemp_int callback .
Definition: Dscad.c:64
CTYPE int DLL DC_CoolerStatus(int Camera)
Procedure that reports the activity status of the cooler.
int EqType
Spectrometer Type.
CTYPE double DLL DC_GetPower(int Camera)
Return current cooler power. Procedure that allows you to read the power (%) of the cooler currently ...
void AMS_PWM_Zero(int mod)
Definition: Spat_Device.c:2570
int refertemp
Flag to set the reference temp for thermo-regulation: 0 = AVGPINT; 1 = OPTIC; 2 = GRATING...
adtester ADTESTER
Definition: Chktemp.c:20
TIMEOUT_ID MAddTimeout(CARD32 tmout, TIMEOUT_CB cb, void *ud)
double ITemp
CCD Target Temperature.
double ADVolt[16]
PC104 AD samples reading array.
double TPelt
OMU Target Temperature.
OMU Thermoregulation structure .
int FANFlg
Definition: DAS_Spatram.h:2970
int ReachTemp
Target Temperature status.
float PID_kd
marconi Marconi
CCD Sensor struct.
void Task_CCD_Temp(TIMEOUT_ID id, void *data)
CCD Temperature Task. Provide the thermoregulation of the CCD sensor during DAS execution.
Definition: Chktemp.c:1068
paramini Paramini
structure for the parameters defined in param.ini configuration file
______________________________________________________________________________________
Generated on Mon Sep 18 2017 11:44:06 for DAS - Rel. 3.1.6 - 18/09/2017.