Rev 1703 Rev 1705
Line 1... Line 1...
1 /**** IR Mrakomer 4 ****/ 1 /**** IR Mrakomer 4 ****/
2 #define VERSION "4.1" 2 #define VERSION "4.1"
3 #define ID "$Id: irmrak4.c 1703 2010-12-05 12:43:15Z kakl $" 3 #define ID "$Id: irmrak4.c 1705 2010-12-05 19:24:34Z kakl $"
4   4  
5 #include "irmrak4.h" 5 #include "irmrak4.h"
6 #include <TOUCH.C> -  
7   6  
8 #bit CREN = 0x18.4 // USART registers 7 #bit CREN = 0x18.4 // USART registers
9 #bit SPEN = 0x18.7 8 #bit SPEN = 0x18.7
10 #bit OERR = 0x18.1 9 #bit OERR = 0x18.1
11 #bit FERR = 0x18.2 10 #bit FERR = 0x18.2
Line 18... Line 17...
18 #define MAXOPEN 20 // Number of cycles for dome open 17 #define MAXOPEN 20 // Number of cycles for dome open
19 #define MEASURE_DELAY 6000 // Delay to a next measurement 18 #define MEASURE_DELAY 6000 // Delay to a next measurement
20 #define RESPONSE_DELAY 100 // Reaction time after receiving a command 19 #define RESPONSE_DELAY 100 // Reaction time after receiving a command
21 #define SAFETY_COUNT 90 // Time of one emergency cycle 20 #define SAFETY_COUNT 90 // Time of one emergency cycle
22 #define SEND_DELAY 50 // Time between two characters on RS232 21 #define SEND_DELAY 50 // Time between two characters on RS232
23 #define ERROR -32000 // Error flag -  
24   22  
25 #define DOME PIN_B4 // Dome controll port 23 #define DOME PIN_B4 // Dome controll port
26 #define HEATING PIN_B3 // Heating for defrosting 24 #define HEATING PIN_B3 // Heating for defrosting
27   25  
28   26  
Line 49... Line 47...
49 void welcome(void) // Welcome message 47 void welcome(void) // Welcome message
50 { 48 {
51 char REV[50]=ID; // Buffer for concatenate of a version string 49 char REV[50]=ID; // Buffer for concatenate of a version string
52   50  
53 if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; 51 if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0;
54 printf("\n\r\n\r# Mrakomer %s (C) 2007 KAKL\n\r",VER); // Welcome message 52 printf("\r\n\r\n# Mrakomer %s (C) 2007 UST\n\r",VER); // Welcome message
55 printf("#%s\n\r",&REV[4]); 53 printf("#%s\r\n",&REV[4]);
56 printf("#\n\r"); 54 printf("#\r\n");
57 printf("# h - Switch On Heating for 20s.\n\r"); -  
58 printf("# c - Need Colder. Switch Off Heating.\n\r"); -  
59 printf("# o - Open the Dome for 20s.\n\r"); -  
60 printf("# l - Lock the Dome.\n\r"); 55 printf("# commands:\r\n");
61 printf("# x - Open the Dome and switch On Heating.\n\r"); -  
62 printf("# i - Print this Information.\n\r"); 56 printf("# h_eat, c_old, o_pen, l_ock, x_open, ");
63 printf("# r - Repeat measure every second.\n\r"); 57 printf("i_nfo, r_epeat, a_uto, s_single, u_pdate\r\n");
64 printf("# s - Single measure.\n\r"); -  
65 printf("# u - Update firmware. Go to the Boot Loader.\n\r"); -  
66 printf("#\n\r"); 58 printf("#\r\n");
67 printf("# <ver> <sequence> <inside[1/100 C]> <sky[1/100 C]> <sky[1/100 C]> "); 59 printf("# <ver> <sequence> <inside[1/100 C]> <sky[1/100 C]> <sky[1/100 C]> ");
68 printf("<ambient[1/100 C]> <heating[s]> <dome[s]> <check>\n\r\n\r"); 60 printf("<ambient[1/100 C]> <heating[s]> <dome[s]> <check>\r\n\r\n");
-   61  
69 //---WDT 62 //---WDT
70 restart_wdt(); 63 restart_wdt();
71 } 64 }
72   65  
73   66  
74 #include "smb.c" // System Management Bus driver 67 #include "smb.c" // System Management Bus driver
-   68 #include "TOUCH.C"
75   69  
76   70  
77 // Read sensor's RAM 71 // Read sensor's RAM
78 // Returns temperature in °K 72 // Returns temperature in °K
79 int16 ReadTemp(int8 addr, int8 select) 73 int16 ReadTemp(int8 addr, int8 select)
Line 143... Line 137...
143 { 137 {
144 unsigned int16 seq, temp, tempa; 138 unsigned int16 seq, temp, tempa;
145 signed int16 ta, to1, to2, tTouch; 139 signed int16 ta, to1, to2, tTouch;
146 int8 tLSB,tMSB; // Temperatures from TouchMemory 140 int8 tLSB,tMSB; // Temperatures from TouchMemory
147 int8 safety_counter; 141 int8 safety_counter;
-   142 int1 repeat; // Status flags
148 int1 repeat; 143 int1 automatic;
149   144  
150 output_high(DOME); // Close Dome 145 output_high(DOME); // Close Dome
151 output_low(HEATING); // Heating off 146 output_low(HEATING); // Heating off
152   147  
153 delay_ms(1000); 148 delay_ms(1000);
Line 201... Line 196...
201   196  
202 switch (ch) 197 switch (ch)
203 { 198 {
204 case 'h': 199 case 'h':
205 heat=MAXHEAT; // Need heating 200 heat=MAXHEAT; // Need heating
-   201 automatic=FALSE;
206 break; 202 break;
207   203  
208 case 'c': 204 case 'c':
209 heat=0; // Need colder 205 heat=0; // Need colder
-   206 automatic=FALSE;
210 break; 207 break;
211   208  
212 case 'o': 209 case 'o':
213 open=MAXOPEN; // Open the dome 210 open=MAXOPEN; // Open the dome
-   211 automatic=FALSE;
214 break; 212 break;
215   213  
216 case 'x': 214 case 'x':
217 open=MAXOPEN; // Open the dome 215 open=MAXOPEN; // Open the dome
218 heat=MAXHEAT; // Need heating 216 heat=MAXHEAT; // Need heating
-   217 automatic=FALSE;
219 break; 218 break;
220   219  
221 case 'l': 220 case 'l':
222 open=0; // Lock the dome 221 open=0; // Lock the dome
-   222 automatic=FALSE;
223 break; 223 break;
224   224  
225 case 'i': 225 case 'i':
226 if (open==0) welcome(); // Information about version, etc... 226 if (open==0) welcome(); // Information about version, etc...
227 break; // Only when dome is closed 227 break; // Only when dome is closed
228   228  
229 case 'r': 229 case 'r':
230 repeat=TRUE; // Repeated measure mode 230 repeat=TRUE; // Repeated measure mode
-   231 automatic=FALSE;
231 break; 232 break;
232   233  
233 case 's': 234 case 's':
234 repeat=FALSE; // Single measure mode 235 repeat=FALSE; // Single measure mode
-   236 automatic=FALSE;
-   237 break;
-   238  
-   239 case 'a':
-   240 repeat=TRUE; // Automatic mode
-   241 automatic=TRUE;
235 break; 242 break;
236   243  
237 case 'u': 244 case 'u':
238 reset_cpu(); // Update firmware 245 reset_cpu(); // Update firmware
239 } 246 }
Line 270... Line 277...
270 tLSB=SN[0]; 277 tLSB=SN[0];
271 tMSB=SN[1]; 278 tMSB=SN[1];
272 if ((SN[8]==TM_check_CRC(SN,8))&&(SN[7]==0x10)) // Check CRC and family code to prevent O's error 279 if ((SN[8]==TM_check_CRC(SN,8))&&(SN[7]==0x10)) // Check CRC and family code to prevent O's error
273 { 280 {
274 tTouch=make16(tMSB,tLSB); 281 tTouch=make16(tMSB,tLSB);
-   282 tTouch=tTouch*6+tTouch/4; // 1bit = 0,0625gradC recalculate to 1/100gradC
275 } 283 }
276 else 284 else
277 { 285 {
278 tTouch=ERROR; 286 tTouch=-27315;
279 } 287 }
280   -  
281 for(n=0;n<9;n++) printf("%X ",SN[n]); -  
282 -  
283 //!!! printf("CRC %u %u ",SN[8],TM_check_CRC(SN,8)); -  
284 //!!! printf("%.4f ",tTouch*6.25); -  
285 } 288 }
286 289
-   290 if(automatic) // Solve automatic mode
-   291 {
-   292 if(ta<1800) heat=MAXHEAT; // Need heating
-   293 if((abs(to1-to2)<200)&&(tTouch>to1)&&(abs(tTouch/4-to1)>500))
-   294 open=MAXOPEN; // Open the dome
-   295 }
-   296  
287 { // printf 297 { // printf
288 char output[8]; // Output buffer 298 char output[8]; // Output buffer
289 int8 j; // String pointer 299 int8 j; // String pointer
290 int8 check=0; // Checksum is calculated between '$' and '*' 300 int8 check=0; // Checksum is calculated between '$' and '*'
291   301  
Line 300... Line 310...
300 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } 310 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
301 sprintf(output,"%Ld \0", to1); 311 sprintf(output,"%Ld \0", to1);
302 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } 312 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
303 sprintf(output,"%Ld \0", to2); 313 sprintf(output,"%Ld \0", to2);
304 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } 314 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
305 if(tTouch==ERROR) -  
306 { -  
307 sprintf(output,"-27315 \0"); // Error condition 315 sprintf(output,"%Ld \0",tTouch);
308 } -  
309 else -  
310 { -  
311 sprintf(output,"%Ld \0",tTouch*6+(tTouch/4)); // 1bit = 0,0625gradC -  
312 } -  
313 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } 316 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
314 sprintf(output,"%u \0", heat); 317 sprintf(output,"%u \0", heat);
315 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } 318 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
316 sprintf(output,"%u \0", open); 319 sprintf(output,"%u \0", open);
317 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } 320 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
318 sprintf(output,"*%X\r\n\0", check); 321 sprintf(output,"*%X\r\n\0", check);
319 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); } 322 j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); }
320 delay(SEND_DELAY); 323 delay(SEND_DELAY);
321 } 324 }
322 325
323   -  
324 //---WDT 326 //---WDT
325 restart_wdt(); 327 restart_wdt();
326 } 328 }
327 } 329 }
328   330  
329   331  
330 //#include "dbloader.c" // Space reservation for the BootLoader 332 #include "dbloader.c" // Space reservation for the BootLoader