| 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 1287 2009-01-08 12:54:40Z kakl $" |
3 |
#define ID "$Id: irmrak4.c 1288 2009-01-08 19:01:53Z kakl $" |
| 4 |
#include "irmrak4.h" |
4 |
#include "irmrak4.h" |
| 5 |
|
5 |
|
| 6 |
#define MAXHEAT 20 // Number of cycles for heating |
6 |
#define MAXHEAT 20 // Number of cycles for heating |
| 7 |
#define MAXOPEN 20 // Number of cycles for dome open |
7 |
#define MAXOPEN 20 // Number of cycles for dome open |
| 8 |
#define MEASURE_DELAY 6000 // Delay to a next measurement |
8 |
#define MEASURE_DELAY 6000 // Delay to a next measurement |
| Line 86... |
Line 86... |
| 86 |
void main() |
86 |
void main() |
| 87 |
{ |
87 |
{ |
| 88 |
unsigned int16 seq, temp, tempa; |
88 |
unsigned int16 seq, temp, tempa; |
| 89 |
signed int16 ta, to; |
89 |
signed int16 ta, to; |
| 90 |
int8 safety_counter; |
90 |
int8 safety_counter; |
| - |
|
91 |
int1 repeat; |
| 91 |
|
92 |
|
| 92 |
output_high(DOME); // Close Dome |
93 |
output_high(DOME); // Close Dome |
| 93 |
output_low(HEATING); // Heating off |
94 |
output_low(HEATING); // Heating off |
| 94 |
setup_wdt(WDT_2304MS); // Setup Watch Dog |
95 |
setup_wdt(WDT_2304MS); // Setup Watch Dog |
| 95 |
setup_adc_ports(NO_ANALOGS); |
96 |
setup_adc_ports(NO_ANALOGS); |
| Line 106... |
Line 107... |
| 106 |
restart_wdt(); |
107 |
restart_wdt(); |
| 107 |
|
108 |
|
| 108 |
seq=0; // Variables initiation |
109 |
seq=0; // Variables initiation |
| 109 |
heat=0; |
110 |
heat=0; |
| 110 |
open=0; |
111 |
open=0; |
| - |
|
112 |
repeat=FALSE; |
| 111 |
|
113 |
|
| 112 |
welcome(); |
114 |
welcome(); |
| 113 |
|
115 |
|
| 114 |
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read |
116 |
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read |
| 115 |
temp=ReadTemp(SA, RAM_Tobj1); |
117 |
temp=ReadTemp(SA, RAM_Tobj1); |
| 116 |
|
118 |
|
| Line 118... |
Line 120... |
| 118 |
//---WDT |
120 |
//---WDT |
| 119 |
restart_wdt(); |
121 |
restart_wdt(); |
| 120 |
|
122 |
|
| 121 |
while(TRUE) // Main Loop |
123 |
while(TRUE) // Main Loop |
| 122 |
{ |
124 |
{ |
| 123 |
while(kbhit()) getc(); // Flush USART buffer |
- |
|
| 124 |
CREN=0; CREN=1; // Reinitialise USART |
- |
|
| 125 |
|
- |
|
| 126 |
safety_counter=SAFETY_COUNT; // Heating and Dome Count Down |
125 |
safety_counter=SAFETY_COUNT; // Heating and Dome Count Down |
| 127 |
do |
126 |
do |
| 128 |
{ |
127 |
{ |
| 129 |
if (safety_counter<SAFETY_COUNT) safety_counter++; |
128 |
if (safety_counter<SAFETY_COUNT) safety_counter++; |
| 130 |
|
129 |
|
| 131 |
delay(RESPONSE_DELAY); |
130 |
delay(RESPONSE_DELAY); |
| 132 |
|
131 |
|
| 133 |
if (safety_counter>=SAFETY_COUNT) |
132 |
if (safety_counter>=SAFETY_COUNT) |
| 134 |
{ |
133 |
{ |
| 135 |
if (heat>0) |
134 |
if (heat>0) heat--; |
| 136 |
{ |
- |
|
| 137 |
output_high(HEATING); |
- |
|
| 138 |
heat--; |
- |
|
| 139 |
} |
- |
|
| 140 |
else |
- |
|
| 141 |
{ |
- |
|
| 142 |
output_low(HEATING); |
- |
|
| 143 |
} |
- |
|
| 144 |
|
- |
|
| 145 |
if (open>0) open--; |
135 |
if (open>0) open--; |
| 146 |
|
136 |
|
| 147 |
safety_counter=0; |
137 |
safety_counter=0; |
| 148 |
//---WDT |
138 |
//---WDT |
| 149 |
restart_wdt(); |
139 |
restart_wdt(); |
| 150 |
} |
140 |
} |
| 151 |
} while (!kbhit()); |
141 |
} while (!kbhit()&&!repeat); |
| 152 |
|
142 |
|
| 153 |
//---WDT |
143 |
//---WDT |
| 154 |
restart_wdt(); |
144 |
restart_wdt(); |
| 155 |
{ // Retrieve command |
145 |
{ // Retrieve command |
| 156 |
char ch; |
146 |
char ch='k'; |
| 157 |
|
147 |
|
| 158 |
ch=getc(); |
148 |
if(kbhit()) ch=getc(); |
| 159 |
|
149 |
|
| 160 |
switch (ch) |
150 |
switch (ch) |
| 161 |
{ |
151 |
{ |
| 162 |
case 'h': |
152 |
case 'h': |
| 163 |
heat=MAXHEAT; // Need heating |
153 |
heat=MAXHEAT; // Need heating |
| Line 181... |
Line 171... |
| 181 |
break; |
171 |
break; |
| 182 |
|
172 |
|
| 183 |
case 'i': |
173 |
case 'i': |
| 184 |
if (open==0) welcome(); // Information about version, etc... |
174 |
if (open==0) welcome(); // Information about version, etc... |
| 185 |
break; // Only when dome is closed |
175 |
break; // Only when dome is closed |
| - |
|
176 |
|
| - |
|
177 |
case 'r': |
| - |
|
178 |
repeat=TRUE; // Repeate measure mode |
| - |
|
179 |
break; |
| - |
|
180 |
|
| - |
|
181 |
case 's': |
| - |
|
182 |
repeat=FALSE; // Single measure mode |
| - |
|
183 |
break; |
| 186 |
} |
184 |
} |
| 187 |
} |
185 |
} |
| - |
|
186 |
// while(kbhit()) getc(); // Flush USART buffer |
| - |
|
187 |
CREN=0; CREN=1; // Reinitialise USART |
| 188 |
|
188 |
|
| 189 |
seq++; // Increment the number of measurement |
189 |
seq++; // Increment the number of measurement |
| 190 |
|
190 |
|
| 191 |
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor |
191 |
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor |
| 192 |
temp=ReadTemp(SA, RAM_Tobj1); |
192 |
temp=ReadTemp(SA, RAM_Tobj1); |
| Line 208... |
Line 208... |
| 208 |
sprintf(output,"%u ", heat); |
208 |
sprintf(output,"%u ", heat); |
| 209 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); } |
209 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); } |
| 210 |
sprintf(output,"%u\n\r\0", open); |
210 |
sprintf(output,"%u\n\r\0", open); |
| 211 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); } |
211 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); } |
| 212 |
} |
212 |
} |
| - |
|
213 |
|
| - |
|
214 |
if(heating>0) { output_high(HEATING); } else { output_low(HEATING); } |
| 213 |
|
215 |
|
| 214 |
delay(MEASURE_DELAY); // Delay to a next measurement |
216 |
delay(MEASURE_DELAY); // Delay to a next measurement |
| 215 |
//---WDT |
217 |
//---WDT |
| 216 |
restart_wdt(); |
218 |
restart_wdt(); |
| 217 |
} |
219 |
} |