Rev 2313 Rev 2314
1 /* mija 2009 - process 1 /* mija 2009 - process
2   2  
3 SW pro ATmega8 mereni + regulace teploty 3 SW pro ATmega8 mereni + regulace teploty
4 Fosc = 8192000Hz externi krystal 4 Fosc = 8192000Hz externi krystal
5 5
6   6  
7 ver.: 0.0 - start 7 ver.: 0.0 - start
8 */ 8 */
9   9  
10 #include <avr/io.h> 10 #include <avr/io.h>
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <math.h> 12 #include <math.h>
13   13  
14 #include "process.h" 14 #include "process.h"
15 #include "key.h" 15 #include "key.h"
16 #include "lcd.h" 16 #include "lcd.h"
17 #include "clock.h" 17 #include "clock.h"
18   18  
19   19  
20 uint8_t ProcesStart(char *buffer,uint8_t key,uint16_t temp) 20 uint8_t ProcesStart(char *buffer,uint8_t key,uint16_t temp)
21 { 21 {
22 static uint8_t proces = SOLDER; 22 static uint8_t proces = SOLDER;
23 static uint8_t displ = 1; 23 static uint8_t displ = 1;
24 static uint16_t LastTemp; 24 static uint16_t LastTemp;
25 25
26 HeatOff(); 26 HeatOff();
27 if (key == TL1){ 27 if (key == TL1){
28 displ = 1; 28 displ = 1;
29 return proces; 29 return proces;
30 } 30 }
31 if ((key == TL2)){ 31 if ((key == TL2)){
32 switch (proces) 32 switch (proces)
33 { 33 {
34 case POSITIV: proces = DRY; 34 case POSITIV: proces = DRY;
35 break; 35 break;
36 case DRY: proces = SOLDER; 36 case DRY: proces = SOLDER;
37 break; 37 break;
38 case SOLDER: 38 case SOLDER:
39 default: proces = POSITIV; 39 default: proces = POSITIV;
40 break; 40 break;
41 } 41 }
42 displ = 1; 42 displ = 1;
43 } 43 }
44 if (displ){ 44 if (displ){
45 switch(proces) 45 switch(proces)
46 { 46 {
47 case POSITIV:sprintf(buffer,"\fPOSITIV\n%3dC ch",temp); 47 case POSITIV:sprintf(buffer,"\fPOSITIV\n%3dC ch",temp);
48 break; 48 break;
49 case DRY: sprintf(buffer,"\fDRY\n%3dC ch",temp); 49 case DRY: sprintf(buffer,"\fDRY\n%3dC ch",temp);
50 break; 50 break;
51 case SOLDER: 51 case SOLDER:
52 default: sprintf(buffer,"\fSOLDER\n%3dC ch",temp); 52 default: sprintf(buffer,"\fSOLDER\n%3dC ch",temp);
53 } 53 }
54 displ = 0; 54 displ = 0;
55 } 55 }
56 else{ 56 else{
57 if (temp !=LastTemp){ 57 if (temp !=LastTemp){
58 sprintf(buffer,"\n%3d",temp); 58 sprintf(buffer,"\n%3d",temp);
59 LastTemp=temp; 59 LastTemp=temp;
60 } 60 }
61 } 61 }
62 return START; 62 return START;
63 } 63 }
64   64  
65 /*uint8_t ProcesSolder(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock) 65 /*uint8_t ProcesSolder(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock)
66 { 66 {
67 enum{SOLDER_START,SOLDER_PREHEAT,SOLDER_SOLDER,SOLDER_COOL}; 67 enum{SOLDER_START,SOLDER_PREHEAT,SOLDER_SOLDER,SOLDER_COOL};
68 static uint8_t stav=SOLDER_START; 68 static uint8_t stav=SOLDER_START;
69 static uint8_t timer=PREHEATTIME; 69 static uint8_t timer=PREHEATTIME;
70 static uint8_t TimerFlag=0; 70 static uint8_t TimerFlag=0;
71 static uint8_t PrevSec; 71 static uint8_t PrevSec;
72   72  
73 if (key != NOKEY){ 73 if (key != NOKEY){
74 stav = SOLDER_START; 74 stav = SOLDER_START;
75 return START; 75 return START;
76 } 76 }
77 switch(stav) 77 switch(stav)
78 { 78 {
79 case SOLDER_START: 79 case SOLDER_START:
80 timer = PREHEATTIME+1; 80 timer = PREHEATTIME+1;
81 TimerFlag = 0; 81 TimerFlag = 0;
82 stav = SOLDER_PREHEAT; 82 stav = SOLDER_PREHEAT;
83 ClockInit(0,0,0,clock); 83 ClockInit(0,0,0,clock);
84 PrevSec = 0xff; 84 PrevSec = 0xff;
85 sprintf(buffer,"\f"); 85 sprintf(buffer,"\f");
86 break; 86 break;
87 case SOLDER_PREHEAT: 87 case SOLDER_PREHEAT:
88 if(temp >= PREHEATTEMPSTART) TimerFlag=1; 88 if(temp >= PREHEATTEMPSTART) TimerFlag=1;
89 ProcesHeat(PREHEATTEMP,temp); 89 ProcesHeat(PREHEATTEMP,temp);
90 if (!timer){ 90 if (!timer){
91 stav = SOLDER_SOLDER; 91 stav = SOLDER_SOLDER;
92 timer = SOLDERTIME+1; 92 timer = SOLDERTIME+1;
93 TimerFlag = 0; 93 TimerFlag = 0;
94 PrevSec = 0xff; 94 PrevSec = 0xff;
95 } 95 }
96 sprintf(buffer,"\rpreheat\n%3dC %3ds",temp,timer-1); 96 sprintf(buffer,"\rpreheat\n%3dC %3ds",temp,timer-1);
97 break; 97 break;
98 case SOLDER_SOLDER: 98 case SOLDER_SOLDER:
99 if(temp >= SOLDERTEMP) TimerFlag=1; 99 if(temp >= SOLDERTEMP) TimerFlag=1;
100 ProcesHeat(SOLDERTEMP,temp); 100 ProcesHeat(SOLDERTEMP,temp);
101 if (!timer){ 101 if (!timer){
102 stav = SOLDER_COOL; 102 stav = SOLDER_COOL;
103 timer = COOLTIME+1; 103 timer = COOLTIME+1;
104 TimerFlag = 0; 104 TimerFlag = 0;
105 PrevSec = 0xff; 105 PrevSec = 0xff;
106 } 106 }
107 sprintf(buffer,"\rsolder \n%3dC %3ds",temp,timer-1); 107 sprintf(buffer,"\rsolder \n%3dC %3ds",temp,timer-1);
108 break; 108 break;
109 case SOLDER_COOL: 109 case SOLDER_COOL:
110 HeatOff(); 110 HeatOff();
111 TimerFlag=1; 111 TimerFlag=1;
112 if (!timer){ 112 if (!timer){
113 stav = SOLDER_START; 113 stav = SOLDER_START;
114 PrevSec = 0xff; 114 PrevSec = 0xff;
115 return START; 115 return START;
116 } 116 }
117 sprintf(buffer,"\rcool \n%3dC %3ds",temp,timer-1); 117 sprintf(buffer,"\rcool \n%3dC %3ds",temp,timer-1);
118 break; 118 break;
119 default: HeatOff(); 119 default: HeatOff();
120 stav = SOLDER_START; 120 stav = SOLDER_START;
121 return START; 121 return START;
122 } 122 }
123 if ((PrevSec != clock->sec) && TimerFlag){ 123 if ((PrevSec != clock->sec) && TimerFlag){
124 PrevSec = clock->sec; 124 PrevSec = clock->sec;
125 timer --; 125 timer --;
126 } 126 }
127 return SOLDER; 127 return SOLDER;
128 }*/ 128 }*/
129   129  
130 uint8_t ProcesSolder(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock) 130 uint8_t ProcesSolder(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock)
131 { 131 {
132 enum{SOLDER_START,SOLDER_PREHEAT,SOLDER_SOLDER,SOLDER_COOL}; 132 enum{SOLDER_START,SOLDER_PREHEAT,SOLDER_SOLDER,SOLDER_COOL};
133 static uint8_t stav=SOLDER_START; 133 static uint8_t stav=SOLDER_START;
134 static uint8_t timer=PREHEATTIME; 134 static uint8_t timer=PREHEATTIME;
135 static uint8_t Timer2=0; 135 static uint8_t Timer2=0;
136 static uint8_t TimerFlag2=0; 136 static uint8_t TimerFlag2=0;
137 static uint8_t TimerFlag=0; 137 static uint8_t TimerFlag=0;
138 static uint8_t FlagSolder=0; 138 static uint8_t FlagSolder=0;
139 static uint8_t PrevSec; 139 static uint8_t PrevSec;
140 static uint16_t LastTemp=0; 140 static uint16_t LastTemp=0;
141   141  
142 if (key != NOKEY){ 142 if (key != NOKEY){
143 stav = SOLDER_START; 143 stav = SOLDER_START;
144 return START; 144 return START;
145 } 145 }
146 switch(stav) 146 switch(stav)
147 { 147 {
148 case SOLDER_START: 148 case SOLDER_START:
149 timer = 0; 149 timer = 0;
150 TimerFlag = 0; 150 TimerFlag = 0;
151 Timer2 = 0; 151 Timer2 = 0;
152 TimerFlag2 = 0; 152 TimerFlag2 = 0;
153 stav = SOLDER_PREHEAT; 153 stav = SOLDER_PREHEAT;
154 ClockInit(0,0,0,clock); 154 ClockInit(0,0,0,clock);
155 PrevSec = 0xff; 155 PrevSec = 0xff;
156 LastTemp = 0; 156 LastTemp = 0;
157 sprintf(buffer,"\f"); 157 sprintf(buffer,"\f");
158 break; 158 break;
159 case SOLDER_PREHEAT: 159 case SOLDER_PREHEAT:
160 if(temp >= PREHEATTEMPSTART) TimerFlag=1; 160 if(temp >= PREHEATTEMPSTART) TimerFlag=1;
161 if(temp >= PREHEATTEMP) TimerFlag2 = 1; 161 if(temp >= PREHEATTEMP) TimerFlag2 = 1;
162 if(temp >= PREHEATTEMPSTOP){ 162 if(temp >= PREHEATTEMPSTOP){
163 stav = SOLDER_SOLDER; 163 stav = SOLDER_SOLDER;
164 164
165 TimerFlag = 0; 165 TimerFlag = 0;
166 FlagSolder = 0; 166 FlagSolder = 0;
167 TimerFlag2 = 0; 167 TimerFlag2 = 0;
168 Timer2 = timer; 168 Timer2 = timer;
169 timer=0; 169 timer=0;
170 break; 170 break;
171 } 171 }
172 if (TimerFlag2 && (Timer2 < PREHEATTIMEOFF)){ 172 if (TimerFlag2 && (Timer2 < PREHEATTIMEOFF)){
173 if (LastTemp > temp) HeatOn(); 173 if (LastTemp > temp) HeatOn();
174 else { 174 else {
175 HeatOff(); 175 HeatOff();
176 if ((clock->sec & 0x4) == 0x4) LastTemp = temp; //4sec vzorkovani; 176 if ((clock->sec & 0x4) == 0x4) LastTemp = temp; //4sec vzorkovani;
177 } 177 }
178 //LastTemp=temp; 178 //LastTemp=temp;
179 } 179 }
180 else HeatOn(); 180 else HeatOn();
181 181
182 sprintf(buffer,"\rpreheat\n%3dC %3ds",temp,timer); 182 sprintf(buffer,"\rpreheat\n%3dC %3ds",temp,timer);
183 break; 183 break;
184 case SOLDER_SOLDER: 184 case SOLDER_SOLDER:
185 if(temp >= SOLDERTEMPSTART) TimerFlag=1; 185 if(temp >= SOLDERTEMPSTART) TimerFlag=1;
186 if(temp >= SOLDERTEMP) FlagSolder = 1; 186 if(temp >= SOLDERTEMP) FlagSolder = 1;
187 if (FlagSolder){ 187 if (FlagSolder){
188 HeatOff(); 188 HeatOff();
189 if(temp <= SOLDERTEMPSTART){ 189 if(temp <= SOLDERTEMPSTART){
190 stav = SOLDER_COOL; 190 stav = SOLDER_COOL;
191 timer=0x1; 191 timer=0x1;
192 TimerFlag = 0; 192 TimerFlag = 0;
193 break; 193 break;
194 } 194 }
195 } 195 }
196 else HeatOn(); 196 else HeatOn();
197 if (TimerFlag) Timer2=timer; 197 if (TimerFlag) Timer2=timer;
198 sprintf(buffer,"\rsolder \n%3dC %3ds",temp,Timer2); 198 sprintf(buffer,"\rsolder \n%3dC %3ds",temp,Timer2);
199 break; 199 break;
200 case SOLDER_COOL: 200 case SOLDER_COOL:
201 HeatOff(); 201 HeatOff();
202 TimerFlag=1; 202 TimerFlag=1;
203 if (!timer){ 203 if (!timer){
204 stav = SOLDER_START; 204 stav = SOLDER_START;
205 //PrevSec = 0xff; 205 //PrevSec = 0xff;
206 return START; 206 return START;
207 } 207 }
208 sprintf(buffer,"\rcool \n%3dC",temp); 208 sprintf(buffer,"\rcool \n%3dC",temp);
209 break; 209 break;
210 default: HeatOff(); 210 default: HeatOff();
211 stav = SOLDER_START; 211 stav = SOLDER_START;
212 return START; 212 return START;
213 } 213 }
214 if ((PrevSec != clock->sec)){ 214 if ((PrevSec != clock->sec)){
215 PrevSec = clock->sec; 215 PrevSec = clock->sec;
216 if (TimerFlag)timer ++; 216 if (TimerFlag)timer ++;
217 if (TimerFlag2) Timer2 ++; 217 if (TimerFlag2) Timer2 ++;
218 } 218 }
219   219  
220 return SOLDER; 220 return SOLDER;
221 } 221 }
222   222  
223 uint8_t ProcesPositiv(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock) 223 uint8_t ProcesPositiv(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock)
224 { 224 {
225 static uint8_t time = 0; 225 static uint8_t time = 0;
226 static uint8_t PrevSec; 226 static uint8_t PrevSec;
227 227
228 if (!time){ 228 if (!time){
229 time = POSITIVTIME+1; 229 time = POSITIVTIME+1;
230 ClockInit(0,0,0,clock); 230 ClockInit(0,0,0,clock);
231 PrevSec = 1; 231 PrevSec = 1;
232 } 232 }
233 ProcesHeat(POSITIVTEMP,temp); 233 ProcesHeat(POSITIVTEMP,temp);
234 if (key == TL1) time +=5; 234 if (key == TL1) time +=5;
235 if (key == TL2) { 235 if (key == TL2) {
236 time = 0; 236 time = 0;
237 return START; 237 return START;
238 } 238 }
239 if (PrevSec != clock->sec){ 239 if (PrevSec != clock->sec){
240 PrevSec = clock->sec; 240 PrevSec = clock->sec;
241 if (PrevSec == 0) time --; 241 if (PrevSec == 0) time --;
242 } 242 }
243 sprintf(buffer,"\n%3dC %3dm",temp,time); 243 sprintf(buffer,"\n%3dC %3dm",temp,time);
244 if (!time) return START; 244 if (!time) return START;
245 return POSITIV; 245 return POSITIV;
246 } 246 }
247   247  
248 uint8_t ProcesDry(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock) 248 uint8_t ProcesDry(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock)
249 { 249 {
250 static uint8_t time; 250 static uint8_t time;
251 static uint8_t PrevSec; 251 static uint8_t PrevSec;
252 252
253 if (!time){ 253 if (!time){
254 time = DRYTIME+1; 254 time = DRYTIME+1;
255 ClockInit(0,0,0,clock); 255 ClockInit(0,0,0,clock);
256 PrevSec = 1; 256 PrevSec = 1;
257 } 257 }
258 ProcesHeat(DRYTEMP,temp); 258 ProcesHeat(DRYTEMP,temp);
259 if (key == TL1) time +=5; 259 if (key == TL1) time +=5;
260 if (key == TL2) { 260 if (key == TL2) {
261 time = 0; 261 time = 0;
262 return START; 262 return START;
263 } 263 }
264 if (PrevSec != clock->sec){ 264 if (PrevSec != clock->sec){
265 PrevSec = clock->sec; 265 PrevSec = clock->sec;
266 if (PrevSec == 0) time --; 266 if (PrevSec == 0) time --;
267 } 267 }
268 sprintf(buffer,"\n%3dC %3dm",temp,time); 268 sprintf(buffer,"\n%3dC %3dm",temp,time);
269 if (!time) return START; 269 if (!time) return START;
270 return DRY; 270 return DRY;
271 } 271 }
272   272  
273 /* 273 /*
274 uint8_t ProcesTest(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock) 274 uint8_t ProcesTest(char *buffer,uint8_t key,uint16_t temp,Clockt_t *clock)
275 { 275 {
276 276
277 HeatOff(); 277 HeatOff();
278 sprintf(buffer,"\r%2d:%02d:%02d\n%3dC ",clock->hour,clock->min,clock->sec,temp); 278 sprintf(buffer,"\r%2d:%02d:%02d\n%3dC ",clock->hour,clock->min,clock->sec,temp);
279   279  
280 if (key == TL2) return START; 280 if (key == TL2) return START;
281 return TEST; 281 return TEST;
282 }*/ 282 }*/
283   283  
284 void ProcesDispl(char *data) 284 void ProcesDispl(char *data)
285 { 285 {
286 uint8_t a,b; 286 uint8_t a,b;
287   287  
288 for (a=0;a<MAXDISPLBUFFER;a++) 288 for (a=0;a<MAXDISPLBUFFER;a++)
289 { 289 {
290 switch (*(data+a)) 290 switch (*(data+a))
291 { 291 {
292 case 0: *data = 0;return; 292 case 0: *data = 0;return;
293 case '\n': LCD_gotoxy(1,2);break; 293 case '\n': LCD_gotoxy(1,2);break;
294 case '\r': LCD_gotoxy(1,1);break; 294 case '\r': LCD_gotoxy(1,1);break;
295 case '\f': LCD_gotoxy(1,1); 295 case '\f': LCD_gotoxy(1,1);
296 for (b=0;b<8;b++) LCD_putc(0x20); 296 for (b=0;b<8;b++) LCD_putc(0x20);
297 LCD_gotoxy(1,2); 297 LCD_gotoxy(1,2);
298 for (b=0;b<8;b++) LCD_putc(0x20); 298 for (b=0;b<8;b++) LCD_putc(0x20);
299 LCD_gotoxy(1,1); 299 LCD_gotoxy(1,1);
300 break; 300 break;
301 default : LCD_putc(*(data+a)); 301 default : LCD_putc(*(data+a));
302 } 302 }
303 } 303 }
304 *data = 0; 304 *data = 0;
305 } 305 }
306   306  
307 void ProcesTemp(uint16_t adc,uint16_t *temp) 307 void ProcesTemp(uint16_t adc,uint16_t *temp)
308 { 308 {
309 double Rpt; 309 double Rpt;
310 double Tpt; 310 double Tpt;
311   311  
312 Rpt = 1.0*adc*2350.0/1024.0; 312 Rpt = 1.0*adc*2350.0/1024.0;
313 313
314 #define A 3.90802e-3 314 #define A 3.90802e-3
315 #define B -5.802e-7 315 #define B -5.802e-7
316 316
317 Tpt = (-A + sqrt(A*A - 4*B*(1.0 - Rpt/1000.0)))/2.0/B; 317 Tpt = (-A + sqrt(A*A - 4*B*(1.0 - Rpt/1000.0)))/2.0/B;
318 //Tpt = (-A + sqrt(A*A - 4*B*(1.0 - Rpt)))/2.0/B; 318 //Tpt = (-A + sqrt(A*A - 4*B*(1.0 - Rpt)))/2.0/B;
319 //Tpt = (Rpt/1000.0 - 1.0)/A; 319 //Tpt = (Rpt/1000.0 - 1.0)/A;
320 320
321 *temp = (int16_t)Tpt; 321 *temp = (int16_t)Tpt;
322 } 322 }
323   323  
324 /* 324 /*
325 void ProcesHeat(uint16_t temp,uint16_t ActualTemp) 325 void ProcesHeat(uint16_t temp,uint16_t ActualTemp)
326 { 326 {
327 enum{HEAT_STABLE,HEAT_UP_1,HEAT_UP_2,HEAT_UP_3,HEAT_UP_4,HEAT_UP_5,HEAT_DOWN_1,HEAT_DOWN_2,HEAT_DOWN_3,HEAT_DOWN_4,HEAT_DOWN_5}; 327 enum{HEAT_STABLE,HEAT_UP_1,HEAT_UP_2,HEAT_UP_3,HEAT_UP_4,HEAT_UP_5,HEAT_DOWN_1,HEAT_DOWN_2,HEAT_DOWN_3,HEAT_DOWN_4,HEAT_DOWN_5};
328 static uint8_t stav = HEAT_STABLE; 328 static uint8_t stav = HEAT_STABLE;
329 static uint8_t PrevTemp = 0; 329 static uint8_t PrevTemp = 0;
330 static uint8_t TimeChange=0; 330 static uint8_t TimeChange=0;
331   331  
332 if (ActualTemp < (temp) 332 if (ActualTemp < (temp)
333   333  
334 switch(stav) 334 switch(stav)
335 { 335 {
336 case HEAT_STABLE: 336 case HEAT_STABLE:
337 if (ActualTemp>temp) HeatOff(); 337 if (ActualTemp>temp) HeatOff();
338 else HeatOn(); 338 else HeatOn();
339 break; 339 break;
340 case HEAT_UP_1: 340 case HEAT_UP_1:
341 break; 341 break;
342 case HEAT_UP_2: 342 case HEAT_UP_2:
343 break; 343 break;
344 case HEAT_UP_3: 344 case HEAT_UP_3:
345 break; 345 break;
346 case HEAT_UP_4: 346 case HEAT_UP_4:
347 break; 347 break;
348 case HEAT_UP_5: 348 case HEAT_UP_5:
349 break; 349 break;
350 case HEAT_DOWN_1: 350 case HEAT_DOWN_1:
351 break; 351 break;
352 case HEAT_DOWN_2: 352 case HEAT_DOWN_2:
353 break; 353 break;
354 case HEAT_DOWN_3: 354 case HEAT_DOWN_3:
355 break; 355 break;
356 case HEAT_DOWN_4: 356 case HEAT_DOWN_4:
357 break; 357 break;
358 case HEAT_DOWN_5: 358 case HEAT_DOWN_5:
359 break; 359 break;
360 } 360 }
361 if (ActualTemp>temp) HeatOff(); 361 if (ActualTemp>temp) HeatOff();
362 else HeatOn(); 362 else HeatOn();
363 } 363 }
364 */ 364 */
365 /* 365 /*
366 void ProcesHeat(uint16_t GequestTemp,uint16_t ActualTemp) 366 void ProcesHeat(uint16_t GequestTemp,uint16_t ActualTemp)
367 { 367 {
368   368  
369 #define TERM_STOP 15 //teplotni rozdil do regulace - trouba topi 369 #define TERM_STOP 15 //teplotni rozdil do regulace - trouba topi
370 #define T1 20 //vzorkovani pøi nabìhu teploty [s] 370 #define T1 20 //vzorkovani pøi nabìhu teploty [s]
371 #define T2 10 //vzorkovani pøi poklesu teploty [s] 371 #define T2 10 //vzorkovani pøi poklesu teploty [s]
372 #define T3 5 //vzorkovani pøi ustalene teplotì [s] 372 #define T3 5 //vzorkovani pøi ustalene teplotì [s]
373 #define T4 5 //doba topení [s] 373 #define T4 5 //doba topení [s]
374 #define MAINCYKLSPEED 100 374 #define MAINCYKLSPEED 100
375   375  
376 static uint8_t delta_s=0; 376 static uint8_t delta_s=0;
377 static uint16_t T_LAST=0; 377 static uint16_t T_LAST=0;
378 static uint8_t clock=MAINCYKLSPEED; //pocet opakovani teto fce za 1 sekundu 378 static uint8_t clock=MAINCYKLSPEED; //pocet opakovani teto fce za 1 sekundu
379   379  
380   380  
381   381  
382 if (!(-- clock)) {delta_s++;clock = MAINCYKLSPEED;} 382 if (!(-- clock)) {delta_s++;clock = MAINCYKLSPEED;}
383   383  
384 if( ActualTemp < (GequestTemp - TERM_STOP)){ 384 if( ActualTemp < (GequestTemp - TERM_STOP)){
385 HeatOn(); 385 HeatOn();
386 delta_s=0; 386 delta_s=0;
387 T_LAST=ActualTemp; 387 T_LAST=ActualTemp;
388 } 388 }
389 else{ 389 else{
390 if (ActualTemp < GequestTemp){ 390 if (ActualTemp < GequestTemp){
391 if (ActualTemp == T_LAST){ 391 if (ActualTemp == T_LAST){
392 if (delta_s < T1) HeatOff(); 392 if (delta_s < T1) HeatOff();
393 else HeatOn(); 393 else HeatOn();
394 if (delta_s > (T1 + T4)) delta_s = 0; 394 if (delta_s > (T1 + T4)) delta_s = 0;
395 } 395 }
396 else{ 396 else{
397 if (T_LAST > ActualTemp) delta_s=(T1 - T2); 397 if (T_LAST > ActualTemp) delta_s=(T1 - T2);
398 else delta_s=0; 398 else delta_s=0;
399 T_LAST=ActualTemp;HeatOff(); 399 T_LAST=ActualTemp;HeatOff();
400 } 400 }
401 } 401 }
402 else{ 402 else{
403 HeatOff();T_LAST=ActualTemp; 403 HeatOff();T_LAST=ActualTemp;
404 if (ActualTemp == GequestTemp) delta_s = (T1 - T3); 404 if (ActualTemp == GequestTemp) delta_s = (T1 - T3);
405 else delta_s = 0; 405 else delta_s = 0;
406 } 406 }
407 } 407 }
408 } 408 }
409 */ 409 */
410 /* 410 /*
411 void ProcesHeat(uint16_t RequestTemp,uint16_t ActualTemp) 411 void ProcesHeat(uint16_t RequestTemp,uint16_t ActualTemp)
412 { 412 {
413   413  
414 #define TERM_STOP 15 //teplotni rozdil do regulace - trouba topi 414 #define TERM_STOP 15 //teplotni rozdil do regulace - trouba topi
415 #define T1 20 //vzorkovani pøi nabìhu teploty [s] 415 #define T1 20 //vzorkovani pøi nabìhu teploty [s]
416 #define T2 10 //vzorkovani pøi poklesu teploty [s] 416 #define T2 10 //vzorkovani pøi poklesu teploty [s]
417 #define T3 5 //vzorkovani pøi ustalene teplotì [s] 417 #define T3 5 //vzorkovani pøi ustalene teplotì [s]
418 #define T4 5 //doba topení [s] 418 #define T4 5 //doba topení [s]
419 #define PERIOD 15 //[s] 419 #define PERIOD 15 //[s]
420 #define MAINCYKLSPEED 100 420 #define MAINCYKLSPEED 100
421   421  
422 static uint8_t delta_s=0; 422 static uint8_t delta_s=0;
423 static uint16_t LastTemp=0; 423 static uint16_t LastTemp=0;
424 static uint8_t clock=MAINCYKLSPEED; //pocet opakovani teto fce za 1 sekundu 424 static uint8_t clock=MAINCYKLSPEED; //pocet opakovani teto fce za 1 sekundu
425 static uint8_t Pwm=0; 425 static uint8_t Pwm=0;
426 static uint8_t DutyPwm = 0; 426 static uint8_t DutyPwm = 0;
427 static uint8_t FlagTemp = 1; 427 static uint8_t FlagTemp = 1;
428 static uint8_t FlagPwm = 0; 428 static uint8_t FlagPwm = 0;
429   429  
430   430  
431   431  
432 if (!(-- clock)){ 432 if (!(-- clock)){
433 delta_s++; 433 delta_s++;
434 clock = MAINCYKLSPEED; 434 clock = MAINCYKLSPEED;
435 if ((++Pwm) > PERIOD){ 435 if ((++Pwm) > PERIOD){
436 Pwm = 0; 436 Pwm = 0;
437 FlagPwm = 1; 437 FlagPwm = 1;
438 } 438 }
439 } 439 }
440   440  
441 if( ActualTemp < (RequestTemp - TERM_STOP)){ 441 if( ActualTemp < (RequestTemp - TERM_STOP)){
442 DutyPwm = PERIOD; 442 DutyPwm = PERIOD;
443 LastTemp = ActualTemp; 443 LastTemp = ActualTemp;
444 FlagTemp=1; 444 FlagTemp=1;
445 } 445 }
446 else{ 446 else{
447 if (FlagTemp){ 447 if (FlagTemp){
448 DutyPwm=0; 448 DutyPwm=0;
449 FlagTemp = 0; 449 FlagTemp = 0;
450 } 450 }
451 else 451 else
452 if (FlagPwm) 452 if (FlagPwm)
453 { 453 {
454 FlagPwm=0; 454 FlagPwm=0;
455 if (ActualTemp >= RequestTemp){ 455 if (ActualTemp >= RequestTemp){
456 if(LastTemp < ActualTemp ) { if (DutyPwm) DutyPwm --;} 456 if(LastTemp < ActualTemp ) { if (DutyPwm) DutyPwm --;}
457 } 457 }
458 else{ 458 else{
459 if (LastTemp >= ActualTemp) {if (DutyPwm<PERIOD)DutyPwm ++;} 459 if (LastTemp >= ActualTemp) {if (DutyPwm<PERIOD)DutyPwm ++;}
460 } 460 }
461 LastTemp = ActualTemp; 461 LastTemp = ActualTemp;
462 } 462 }
463 } 463 }
464   464  
465 if(ActualTemp<RequestTemp){ 465 if(ActualTemp<RequestTemp){
466 if (DutyPwm >= Pwm) HeatOn(); 466 if (DutyPwm >= Pwm) HeatOn();
467 else HeatOff(); 467 else HeatOff();
468 } 468 }
469 else HeatOff(); 469 else HeatOff();
470   470  
471 }*/ 471 }*/
472   472  
473 void ProcesHeat(uint16_t RequestTemp,uint16_t ActualTemp) 473 void ProcesHeat(uint16_t RequestTemp,uint16_t ActualTemp)
474 { 474 {
475   475  
476 #define TERM_STOP 15 //teplotni rozdil do regulace - trouba topi 476 #define TERM_STOP 15 //teplotni rozdil do regulace - trouba topi
477   477  
478 #define PERIOD 15 //[s] 478 #define PERIOD 15 //[s]
479 #define MAINCYKLSPEED 100 479 #define MAINCYKLSPEED 100
480   480  
481 static uint8_t delta_s=0; 481 static uint8_t delta_s=0;
482 static uint16_t LastTemp=0; 482 static uint16_t LastTemp=0;
483 static uint8_t clock=MAINCYKLSPEED; //pocet opakovani teto fce za 1 sekundu 483 static uint8_t clock=MAINCYKLSPEED; //pocet opakovani teto fce za 1 sekundu
484 static uint8_t Pwm=0; 484 static uint8_t Pwm=0;
485 static uint8_t DutyPwm = 0; 485 static uint8_t DutyPwm = 0;
486 static uint8_t FlagTemp = 1; 486 static uint8_t FlagTemp = 1;
487 static uint8_t FlagPwm = 0; 487 static uint8_t FlagPwm = 0;
488   488  
489   489  
490   490  
491 if (!(-- clock)){ 491 if (!(-- clock)){
492 clock = MAINCYKLSPEED; 492 clock = MAINCYKLSPEED;
493 if ((++Pwm) > PERIOD){ 493 if ((++Pwm) > PERIOD){
494 Pwm = 0; 494 Pwm = 0;
495 FlagPwm = 1; 495 FlagPwm = 1;
496 } 496 }
497 } 497 }
498   498  
499 if( ActualTemp < (RequestTemp - TERM_STOP)){ 499 if( ActualTemp < (RequestTemp - TERM_STOP)){
500 DutyPwm = PERIOD; 500 DutyPwm = PERIOD;
501 LastTemp = ActualTemp; 501 LastTemp = ActualTemp;
502 FlagTemp=1; 502 FlagTemp=1;
503 } 503 }
504 else{ 504 else{
505 if (FlagTemp){ 505 if (FlagTemp){
506 DutyPwm=0; 506 DutyPwm=0;
507 FlagTemp = 0; 507 FlagTemp = 0;
508 } 508 }
509 else 509 else
510 if (FlagPwm) 510 if (FlagPwm)
511 { 511 {
512 FlagPwm=0; 512 FlagPwm=0;
513 if (ActualTemp >= RequestTemp){ 513 if (ActualTemp >= RequestTemp){
514 if (ActualTemp != RequestTemp) 514 if (ActualTemp != RequestTemp)
515 if(LastTemp < ActualTemp ){ 515 if(LastTemp < ActualTemp ){
516 //if ((ActualTemp-LastTemp) > 1) 516 //if ((ActualTemp-LastTemp) > 1)
517 if (DutyPwm) DutyPwm --; 517 if (DutyPwm) DutyPwm --;
518 } 518 }
519 } 519 }
520 else{ 520 else{
521 if (LastTemp >= ActualTemp){ 521 if (LastTemp >= ActualTemp){
522 //if ((ActulaTemp - LastTemp)>1) 522 //if ((ActulaTemp - LastTemp)>1)
523 if (DutyPwm<PERIOD)DutyPwm ++; 523 if (DutyPwm<PERIOD)DutyPwm ++;
524 } 524 }
525 if(LastTemp < ActualTemp ){ 525 if(LastTemp < ActualTemp ){
526 if ((ActualTemp-LastTemp) > 5) 526 if ((ActualTemp-LastTemp) > 5)
527 if (DutyPwm) DutyPwm --; 527 if (DutyPwm) DutyPwm --;
528 } 528 }
529 } 529 }
530 LastTemp = ActualTemp; 530 LastTemp = ActualTemp;
531 } 531 }
532 } 532 }
533   533  
534 if(ActualTemp < RequestTemp) 534 if(ActualTemp < RequestTemp)
535 { 535 {
536 if (DutyPwm == PERIOD) HeatOn(); 536 if (DutyPwm == PERIOD) HeatOn();
537 else{ 537 else{
538 if (DutyPwm > Pwm) HeatOn(); 538 if (DutyPwm > Pwm) HeatOn();
539 else HeatOff(); 539 else HeatOff();
540 } 540 }
541 541
542 } 542 }
543 else HeatOff(); 543 else HeatOff();
544   544  
545 } 545 }