Rev 55 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 55 | Rev 56 | ||
---|---|---|---|
Line 23... | Line 23... | ||
23 | volatile unsigned char CH2; |
23 | volatile unsigned char CH2; |
24 | volatile unsigned char CH3; |
24 | volatile unsigned char CH3; |
25 | volatile unsigned char CH4; |
25 | volatile unsigned char CH4; |
26 | volatile unsigned char CH5; |
26 | volatile unsigned char CH5; |
Line -... | Line 27... | ||
- | 27 | ||
- | 28 | uint16_t EEMEM EEPMIN=0x0000; |
|
- | 29 | uint16_t EEMEM EEPMAX=0xffff; |
|
- | 30 | uint16_t EEMEM EEPSIG=0xffff; |
|
- | 31 | ||
- | 32 | ||
- | 33 | //led kennlinie, (noch nicht implementiert, nur vorbereitet) |
|
- | 34 | unsigned char kl[256]={ |
|
- | 35 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 36 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 37 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 38 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 39 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 40 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 41 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 42 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 43 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 44 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 45 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 46 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 47 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 48 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 49 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
|
- | 50 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 |
|
- | 51 | }; |
|
- | 52 | ||
Line 27... | Line 53... | ||
27 | 53 | ||
28 | 54 | ||
29 | /*##############################################################################*/ |
55 | /*##############################################################################*/ |
30 | SIGNAL(SIG_OVERFLOW1) |
56 | SIGNAL(SIG_OVERFLOW1) |
Line 196... | Line 222... | ||
196 | int main (void) |
222 | int main (void) |
197 | { |
223 | { |
Line 198... | Line 224... | ||
198 | 224 | ||
199 | #define STEP 256 |
225 | #define STEP 256 |
200 | #define MUL 1 |
226 | #define MUL 1 |
Line 201... | Line -... | ||
201 | #define REDUCE 5 |
- | |
202 | - | ||
203 | #define EEPADRSIG 0x00 |
- | |
204 | #define EEPADRMIN 0x20 |
227 | #define REDUCE 2 |
Line 205... | Line 228... | ||
205 | #define EEPADRMAX 0x22 |
228 | |
206 | #define EEPSIGATURE 0x55aa |
229 | #define EEPSIGNATURE 0x55aa |
207 | 230 | ||
208 | unsigned int ppm; |
231 | unsigned int ppm; |
Line 213... | Line 236... | ||
213 | unsigned char setup; |
236 | unsigned char setup; |
214 | unsigned int lmax; |
237 | unsigned int lmax; |
215 | unsigned int lmin; |
238 | unsigned int lmin; |
216 | unsigned int max; |
239 | unsigned int max; |
217 | unsigned int min; |
240 | unsigned int min; |
218 | unsigned long temp1; |
241 | signed long temp1; |
219 | unsigned long temp2; |
242 | signed long temp2; |
220 | - | ||
221 | - | ||
Line 222... | Line 243... | ||
222 | 243 | ||
223 | DDRB = (CH0_B|CH1_B|CH2_B); |
244 | DDRB = (CH0_B|CH1_B|CH2_B); |
Line 224... | Line 245... | ||
224 | PORTB = 0x00; |
245 | PORTB = 0x00; |
Line 243... | Line 264... | ||
243 | StartPPM(); |
264 | StartPPM(); |
244 | //StartI2C(); |
265 | //StartI2C(); |
245 | StartPWM(); |
266 | StartPWM(); |
246 | sei(); |
267 | sei(); |
Line 247... | Line -... | ||
247 | - | ||
248 | - | ||
249 | 268 | ||
250 | if (eeprom_read_word(EEPADRSIG) != EEPSIGATURE) //check eep if signature is there |
269 | if (eeprom_read_word(&EEPSIG) != EEPSIGNATURE) //check eep if signature is there |
251 | { |
270 | { |
252 | min = 1100; //default min |
271 | min = 1100; //default min |
253 | max = 1900; //default max |
272 | max = 1900; //default max |
254 | eeprom_write_word(EEPADRMIN, min); //no, write initial min |
273 | eeprom_write_word(&EEPMIN, min); //no, write initial min |
255 | eeprom_write_word(EEPADRMAX, max); //and max values |
274 | eeprom_write_word(&EEPMAX, max); //and max values |
256 | eeprom_write_word(EEPADRSIG, EEPSIGATURE); //along with eep signature |
275 | eeprom_write_word(&EEPSIG, EEPSIGNATURE); //along with eep signature |
257 | } |
276 | } |
258 | else |
277 | else |
259 | { |
278 | { |
260 | min = eeprom_read_word(EEPADRMIN); //signature ok |
279 | min = eeprom_read_word(&EEPMIN); //signature ok |
261 | max = eeprom_read_word(EEPADRMAX); //read min and max |
280 | max = eeprom_read_word(&EEPMAX); //read min and max |
Line 262... | Line 281... | ||
262 | } |
281 | } |
263 | 282 | ||
264 | setup = 0; //reset setup toggle counter |
283 | setup = 0; //reset setup toggle counter |
265 | setupdly = SetDelay(3000); |
284 | setupdly = SetDelay(5000); |
Line 266... | Line 285... | ||
266 | ppmtodly = SetDelay(5000); |
285 | ppmtodly = SetDelay(5000); |
267 | flashdly = SetDelay(100); |
286 | flashdly = SetDelay(1000); |
Line 268... | Line 287... | ||
268 | 287 | ||
Line 294... | Line 313... | ||
294 | if (setup < 6) |
313 | if (setup < 6) |
295 | { |
314 | { |
296 | if ((ppm > 1600) && ((setup&1)==0)) setup++; // |
315 | if ((ppm > 1600) && ((setup&1)==0)) setup++; // |
297 | if ((ppm < 1400) && ((setup&1)==1)) setup++; // |
316 | if ((ppm < 1400) && ((setup&1)==1)) setup++; // |
Line 298... | Line 317... | ||
298 | 317 | ||
299 | if (CheckDelay(flashdly)) //setup timeout reached |
318 | if (CheckDelay(flashdly)) |
300 | { |
319 | { |
301 | CH0 = CH0 ^ 0xff; |
320 | CH0 = CH0 ^ 0xff; |
302 | CH1 = CH1 ^ 0xff; |
321 | CH1 = CH1 ^ 0xff; |
303 | CH2 = CH2 ^ 0xff; |
322 | CH2 = CH2 ^ 0xff; |
304 | flashdly = SetDelay(250); |
323 | flashdly = SetDelay(250); |
305 | } |
- | |
306 | 324 | } |
|
Line 307... | Line 325... | ||
307 | } |
325 | } |
308 | 326 | ||
309 | if (setup == 6) //if stick is toggled 6 times |
327 | if (setup == 6) //if stick is toggled 6 times |
- | 328 | { //within setup timeout |
|
310 | { //within setup timeout |
329 | PORTD setbit ledgreen; //store ppm min and max |
311 | PORTD setbit ledgreen; //store ppm min and max |
330 | setupdly = SetDelay(3000); //for 2000ms |
312 | eeprom_write_word(EEPADRMIN, lmin); //in eeprom |
331 | eeprom_write_word(&EEPMIN, lmin); //in eeprom |
313 | eeprom_write_word(EEPADRMAX, lmax); |
332 | eeprom_write_word(&EEPMAX, lmax); |
314 | min = lmin; |
333 | min = lmin; |
Line -... | Line 334... | ||
- | 334 | max = lmax; |
|
- | 335 | setup = 7; //enter PWM toggle mode |
|
- | 336 | ||
- | 337 | } |
|
- | 338 | ||
315 | max = lmax; |
339 | |
316 | setupdly = SetDelay(2000); |
340 | if (setup == 7) |
317 | 341 | { |
|
318 | if (CheckDelay(flashdly)) //setup timeout reached |
342 | if (CheckDelay(flashdly)) //each 25ms toggle PWM's |
319 | { |
343 | { |
320 | CH0 = CH0 ^ 0xff; |
344 | CH0 = CH0 ^ 0xff; |
321 | CH1 = CH1 ^ 0xff; |
345 | CH1 = CH1 ^ 0xff; |
322 | CH2 = CH2 ^ 0xff; |
346 | CH2 = CH2 ^ 0xff; |
323 | flashdly = SetDelay(25); |
347 | flashdly = SetDelay(25); |
Line 324... | Line 348... | ||
324 | } |
348 | } |
325 | 349 | ||
326 | } |
350 | } |
327 | 351 | ||
328 | if (CheckDelay(setupdly)) //setup timeout reached |
352 | if (CheckDelay(setupdly)) //setup timeout reached |
Line 329... | Line 353... | ||
329 | { |
353 | { |
Line 330... | Line 354... | ||
330 | setup = 7; //lockdown setup |
354 | setup = 8; //lockdown setup |
331 | PORTD clrbit ledgreen; |
355 | PORTD clrbit ledgreen; |
Line 332... | Line 356... | ||
332 | } |
356 | } |
333 | 357 | ||
334 | //printf("ppm: %d / min: %d / max: %d\n",ppm,lmin,lmax); |
358 | printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
Line 335... | Line 359... | ||
335 | 359 | ||
336 | 360 | ||
Line -... | Line 361... | ||
- | 361 | ||
- | 362 | if (setup == 8) |
|
337 | 363 | { |
|
338 | if (setup = 7) |
364 | |
339 | { |
365 | temp1 = (STEP * (signed long)30000 * (signed long)6) / ((max-REDUCE) - (min+REDUCE)); |
340 | 366 | temp2 = ((ppm - (min+REDUCE)) * temp1); |
|
341 | temp1 = (STEP * (long)40000 * (long)6) / ((max-REDUCE) - (min+REDUCE)); |
367 | color = temp2 / 30000; |