Line 1... |
Line 1... |
1 |
/**** IR Mrakomer 4 ****/ |
1 |
/**** IR Mrakomer 4 ****/ |
2 |
#define VERSION "4.0" |
2 |
#define VERSION "4.0" |
3 |
#define ID "$Id: irmrak4.c 1278 2009-01-07 00:47:35Z kakl $" |
3 |
#define ID "$Id: irmrak4.c 1280 2009-01-07 12:23:26Z kakl $" |
4 |
#include "irmrak4.h" |
4 |
#include "irmrak4.h" |
5 |
|
5 |
|
6 |
#define MAXHEAT 10 // Number of cycles for heating |
6 |
#define MAXHEAT 20 // Number of cycles for heating |
7 |
#define MAXOPEN 10 // Number of cycles for dome open |
7 |
#define MAXOPEN 20 // Number of cycles for dome open |
8 |
#define MEASURE_DELAY 10000 |
8 |
#define MEASURE_DELAY 10000 // Delay to a next measurement |
- |
|
9 |
#define RESPONSE_DELAY 100 // Reaction time after receiving a command |
- |
|
10 |
#define SAFETY_COUNT 100 // Time of one emergency cycle |
9 |
#define SEND_DELAY 50 |
11 |
#define SEND_DELAY 50 // Time between two characters on RS232 |
10 |
|
12 |
|
11 |
#define DOME PIN_B4 // Dome controll port |
13 |
#define DOME PIN_B4 // Dome controll port |
12 |
#define HEATING PIN_B3 // Heating for defrosting |
14 |
#define HEATING PIN_B3 // Heating for defrosting |
13 |
|
15 |
|
14 |
#bit CREN = 0x18.4 // USART registers |
16 |
#bit CREN = 0x18.4 // USART registers |
15 |
#bit SPEN = 0x18.7 |
17 |
#bit SPEN = 0x18.7 |
16 |
#bit OERR = 0x18.1 |
18 |
#bit OERR = 0x18.1 |
17 |
#bit FERR = 0x18.2 |
19 |
#bit FERR = 0x18.2 |
18 |
|
20 |
|
19 |
char VER[4]=VERSION; |
21 |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
20 |
char REV[50]=ID; |
22 |
char REV[50]=ID; |
21 |
|
23 |
|
22 |
int8 heat; |
24 |
int8 heat; // Status variables |
23 |
int8 open; |
25 |
int8 open; |
24 |
|
26 |
|
25 |
inline void toggle_dome(void) |
27 |
inline void toggle_dome(void) |
26 |
{ |
28 |
{ |
27 |
if (open>0) |
29 |
if (open>0) |
Line 33... |
Line 35... |
33 |
void delay(int16 cycles) |
35 |
void delay(int16 cycles) |
34 |
{ |
36 |
{ |
35 |
int16 i; |
37 |
int16 i; |
36 |
|
38 |
|
37 |
for(i=0; i<cycles; i++) {toggle_dome(); delay_us(100);} |
39 |
for(i=0; i<cycles; i++) {toggle_dome(); delay_us(100);} |
38 |
|
- |
|
39 |
restart_wdt(); |
- |
|
40 |
} |
40 |
} |
41 |
|
41 |
|
42 |
|
42 |
|
43 |
#include "smb.c" |
43 |
#include "smb.c" |
44 |
|
44 |
|
45 |
|
45 |
|
- |
|
46 |
// Read sensor RAM |
- |
|
47 |
// Returns temperature in °K |
46 |
int16 ReadTemp(int8 addr, int8 select) // Read sensor RAM |
48 |
int16 ReadTemp(int8 addr, int8 select) |
47 |
{ |
49 |
{ |
48 |
unsigned char arr[6]; // Buffer for the sent bytes |
50 |
unsigned char arr[6]; // Buffer for the sent bytes |
49 |
int8 crc; // Readed CRC |
51 |
int8 crc; // Readed CRC |
50 |
int16 temp; // Readed temperature |
52 |
int16 temp; // Readed temperature |
51 |
|
53 |
|
Line 72... |
Line 74... |
72 |
return temp; |
74 |
return temp; |
73 |
} |
75 |
} |
74 |
|
76 |
|
75 |
void main() |
77 |
void main() |
76 |
{ |
78 |
{ |
77 |
unsigned int16 n, temp, tempa; |
79 |
unsigned int16 seq, temp, tempa; |
78 |
signed int16 ta, to; |
80 |
signed int16 ta, to; |
- |
|
81 |
int8 safety_counter; |
79 |
|
82 |
|
80 |
output_low(HEATING); // Heating off |
83 |
output_low(HEATING); // Heating off |
81 |
setup_wdt(WDT_2304MS); // Setup Watch Dog |
84 |
setup_wdt(WDT_2304MS); // Setup Watch Dog |
82 |
setup_adc_ports(NO_ANALOGS); |
85 |
setup_adc_ports(NO_ANALOGS); |
83 |
setup_adc(ADC_OFF); |
86 |
setup_adc(ADC_OFF); |
Line 91... |
Line 94... |
91 |
|
94 |
|
92 |
delay_ms(1000); |
95 |
delay_ms(1000); |
93 |
restart_wdt(); |
96 |
restart_wdt(); |
94 |
printf("\n\r* Mrakomer %s (C) 2007 KAKL *\n\r",VER); // Welcome message |
97 |
printf("\n\r* Mrakomer %s (C) 2007 KAKL *\n\r",VER); // Welcome message |
95 |
printf("* %s *\n\r",REV); |
98 |
printf("* %s *\n\r",REV); |
96 |
printf("<#seq.> <ambient temp.> <space temp.> <heating> <dome>\n\r\n\r"); |
99 |
printf("<#sequence> <ambient [1/100 °C]> <sky [1/100 °C]> "); |
- |
|
100 |
printf("<heating [s]> <dome [s]>\n\r\n\r"); |
97 |
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read |
101 |
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read |
98 |
temp=ReadTemp(SA, RAM_Tobj1); |
102 |
temp=ReadTemp(SA, RAM_Tobj1); |
99 |
|
103 |
|
100 |
n=0; |
104 |
seq=0; |
101 |
heat=0; |
105 |
heat=0; |
102 |
open=0; |
106 |
open=0; |
103 |
|
107 |
|
104 |
// enable_interrupts(GLOBAL); |
108 |
// enable_interrupts(GLOBAL); |
105 |
// enable_interrupts(INT_RDA); |
109 |
// enable_interrupts(INT_RDA); |
106 |
|
110 |
|
- |
|
111 |
//---WDT |
107 |
restart_wdt(); |
112 |
restart_wdt(); |
108 |
|
113 |
|
109 |
while(TRUE) |
114 |
while(TRUE) |
110 |
{ |
115 |
{ |
111 |
while(kbhit()) getc(); // Flush USART buffer |
116 |
while(kbhit()) getc(); // Flush USART buffer |
112 |
CREN=0; CREN=1; // Reinitialise USART |
117 |
CREN=0; CREN=1; // Reinitialise USART |
113 |
|
118 |
|
- |
|
119 |
safety_counter=0; |
- |
|
120 |
|
114 |
do |
121 |
do |
115 |
{ |
122 |
{ |
116 |
delay(MEASURE_DELAY); |
- |
|
117 |
if (heat>0) |
- |
|
118 |
{ |
- |
|
119 |
output_high(HEATING); |
123 |
if (safety_counter<SAFETY_COUNT) safety_counter++; |
120 |
heat--; |
- |
|
121 |
} |
- |
|
122 |
else |
- |
|
123 |
{ |
124 |
|
124 |
output_low(HEATING); |
125 |
delay(RESPONSE_DELAY); |
125 |
} |
- |
|
126 |
|
126 |
|
- |
|
127 |
if (safety_counter>=SAFETY_COUNT) |
- |
|
128 |
{ |
- |
|
129 |
if (heat>0) |
- |
|
130 |
{ |
- |
|
131 |
output_high(HEATING); |
- |
|
132 |
heat--; |
- |
|
133 |
} |
- |
|
134 |
else |
- |
|
135 |
{ |
- |
|
136 |
output_low(HEATING); |
- |
|
137 |
} |
- |
|
138 |
|
127 |
if (open>0) open--; |
139 |
if (open>0) open--; |
- |
|
140 |
|
- |
|
141 |
safety_counter=0; |
- |
|
142 |
//---WDT |
- |
|
143 |
restart_wdt(); |
- |
|
144 |
} |
128 |
} while (!kbhit()); |
145 |
} while (!kbhit()); |
129 |
|
146 |
|
- |
|
147 |
//---WDT |
- |
|
148 |
restart_wdt(); |
130 |
{ |
149 |
{ |
131 |
char ch; |
150 |
char ch; |
132 |
|
151 |
|
133 |
ch=getc(); |
152 |
ch=getc(); |
134 |
|
153 |
|
135 |
switch (ch) |
154 |
switch (ch) |
136 |
{ |
155 |
{ |
137 |
case 'h': |
156 |
case 'h': |
138 |
heat=MAXHEAT; // Needs heating |
157 |
heat=MAXHEAT; // Need heating |
139 |
break; |
158 |
break; |
140 |
|
159 |
|
141 |
case 'c': |
160 |
case 'c': |
142 |
heat=0; // Needs colder |
161 |
heat=0; // Need colder |
143 |
break; |
162 |
break; |
144 |
|
163 |
|
145 |
case 'o': |
164 |
case 'o': |
146 |
open=MAXOPEN; // Open the dome |
165 |
open=MAXOPEN; // Open the dome |
147 |
break; |
166 |
break; |
Line 150... |
Line 169... |
150 |
open=0; // Lock the dome |
169 |
open=0; // Lock the dome |
151 |
break; |
170 |
break; |
152 |
} |
171 |
} |
153 |
} |
172 |
} |
154 |
|
173 |
|
155 |
n++; // Increment the number of measurement |
174 |
seq++; // Increment the number of measurement |
156 |
|
175 |
|
157 |
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor |
176 |
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor |
158 |
temp=ReadTemp(SA, RAM_Tobj1); |
177 |
temp=ReadTemp(SA, RAM_Tobj1); |
159 |
|
178 |
|
160 |
ta=tempa*2-27315; // °K -> °C |
179 |
ta=tempa*2-27315; // °K -> °C |
Line 162... |
Line 181... |
162 |
|
181 |
|
163 |
{ // printf |
182 |
{ // printf |
164 |
char output[30]; // Output buffer |
183 |
char output[30]; // Output buffer |
165 |
int8 j; // Counter |
184 |
int8 j; // Counter |
166 |
|
185 |
|
167 |
sprintf(output,"#%Lu %Ld %Ld %u %u\n\r\0", n, ta, to, heat, open); |
186 |
sprintf(output,"#%Lu %Ld %Ld %u %u\n\r\0", seq, ta, to, heat, open); |
168 |
|
187 |
|
169 |
j=0; |
188 |
j=0; |
170 |
while(output[j]!=0) |
189 |
while(output[j]!=0) |
171 |
{ |
190 |
{ |
172 |
delay(SEND_DELAY); |
191 |
delay(SEND_DELAY); |
173 |
putc(output[j++]); |
192 |
putc(output[j++]); |
174 |
output_toggle(DOME); |
193 |
output_toggle(DOME); |
175 |
} |
194 |
} |
176 |
} |
195 |
} |
- |
|
196 |
|
- |
|
197 |
delay(MEASURE_DELAY); // Delay to a next measurement |
- |
|
198 |
//---WDT |
- |
|
199 |
restart_wdt(); |
177 |
} |
200 |
} |
178 |
} |
201 |
} |
179 |
|
202 |
|