Rev 56 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 56 | Rev 57 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | 12 | ||
13 | #include "main.h" |
13 | #include "main.h" |
14 | #include "uart.h" |
14 | #include "uart.h" |
Line 15... | Line 15... | ||
15 | #include "twislave.h" |
15 | #include "twislave.h" |
16 | 16 | ||
17 | volatile unsigned int PPM_SIGNAL = 1500; |
17 | volatile unsigned int PPM_SIGNAL = 1520; |
18 | volatile unsigned char PPM_NEW = 0; |
18 | volatile unsigned char PPM_NEW = 0; |
19 | volatile unsigned char TMR1OvF = 0; |
19 | volatile unsigned char TMR1OvF = 0; |
20 | volatile unsigned int TMR1MS; |
20 | volatile unsigned int TMR1MS; |
Line 226... | Line 226... | ||
226 | #define MUL 1 |
226 | #define MUL 1 |
227 | #define REDUCE 2 |
227 | #define REDUCE 2 |
Line 228... | Line 228... | ||
228 | 228 | ||
Line -... | Line 229... | ||
- | 229 | #define EEPSIGNATURE 0x55aa |
|
- | 230 | ||
- | 231 | #define inimin 1200 |
|
229 | #define EEPSIGNATURE 0x55aa |
232 | #define inimax 1800 |
230 | 233 | ||
231 | unsigned int ppm; |
234 | unsigned int ppm; |
232 | signed int color; |
235 | signed int color; |
233 | unsigned int setupdly; |
236 | unsigned int setupdly; |
234 | unsigned int ppmtodly; |
237 | unsigned int ppmtodly; |
235 | unsigned int flashdly; |
238 | unsigned int flashdly; |
236 | unsigned char setup; |
239 | unsigned char setup; |
237 | unsigned int lmax; |
240 | unsigned int lmax; |
238 | unsigned int lmin; |
241 | unsigned int lmin; |
239 | unsigned int max; |
242 | unsigned int max; |
240 | unsigned int min; |
243 | unsigned int min; |
Line 241... | Line 244... | ||
241 | signed long temp1; |
244 | signed long temp1; |
242 | signed long temp2; |
245 | signed long temp2; |
Line 243... | Line 246... | ||
243 | 246 | ||
Line 258... | Line 261... | ||
258 | CH5 = 0; |
261 | CH5 = 0; |
Line 259... | Line 262... | ||
259 | 262 | ||
260 | lmax = 0x0000; |
263 | lmax = 0x0000; |
Line 261... | Line 264... | ||
261 | lmin = 0xffff; |
264 | lmin = 0xffff; |
262 | 265 | ||
263 | StartUART(); |
266 | // StartUART(); |
264 | StartPPM(); |
267 | StartPPM(); |
265 | //StartI2C(); |
268 | //StartI2C(); |
Line -... | Line 269... | ||
- | 269 | StartPWM(); |
|
- | 270 | sei(); |
|
- | 271 | ||
266 | StartPWM(); |
272 | min = inimin; //default min |
267 | sei(); |
273 | max = inimax; //default max |
268 | - | ||
269 | if (eeprom_read_word(&EEPSIG) != EEPSIGNATURE) //check eep if signature is there |
- | |
270 | { |
274 | |
271 | min = 1100; //default min |
275 | if (eeprom_read_word(&EEPSIG) != EEPSIGNATURE) //check eep if signature is there |
272 | max = 1900; //default max |
276 | { |
273 | eeprom_write_word(&EEPMIN, min); //no, write initial min |
277 | eeprom_write_word(&EEPMIN, min); //no, write initial min |
274 | eeprom_write_word(&EEPMAX, max); //and max values |
278 | eeprom_write_word(&EEPMAX, max); //and max values |
275 | eeprom_write_word(&EEPSIG, EEPSIGNATURE); //along with eep signature |
279 | eeprom_write_word(&EEPSIG, EEPSIGNATURE); //along with eep signature |
- | 280 | } |
|
276 | } |
281 | else |
277 | else |
282 | { |
278 | { |
283 | |
Line -... | Line 284... | ||
- | 284 | min = eeprom_read_word(&EEPMIN); //signature ok |
|
279 | min = eeprom_read_word(&EEPMIN); //signature ok |
285 | max = eeprom_read_word(&EEPMAX); //read min and max |
280 | max = eeprom_read_word(&EEPMAX); //read min and max |
286 | } |
281 | } |
287 | |
282 | 288 | ||
Line 353... | Line 359... | ||
353 | { |
359 | { |
354 | setup = 8; //lockdown setup |
360 | setup = 8; //lockdown setup |
355 | PORTD clrbit ledgreen; |
361 | PORTD clrbit ledgreen; |
356 | } |
362 | } |
Line 357... | Line -... | ||
357 | - | ||
358 | printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
- | |
359 | - | ||
Line 360... | Line 363... | ||
360 | 363 | ||
361 | 364 | ||
Line -... | Line 365... | ||
- | 365 | if (setup == 8) |
|
- | 366 | { |
|
362 | if (setup == 8) |
367 | |
363 | { |
368 | |
364 | 369 | ||
365 | temp1 = (STEP * (signed long)30000 * (signed long)6) / ((max-REDUCE) - (min+REDUCE)); |
370 | temp1 = ((long)STEP * 6 * 20000) / ((max-REDUCE) - (min+REDUCE)); |
366 | temp2 = ((ppm - (min+REDUCE)) * temp1); |
371 | temp2 = (((int)ppm - ((int)min+REDUCE)) * temp1); |
367 | color = temp2 / 30000; |
372 | color = temp2 / 20000; |
- | 373 | ||
- | 374 | if (color < 0) color = 0; |
|
- | 375 | if (color > ((STEP*6)+1)) color = ((STEP*6)+1); |
|
- | 376 | ||
- | 377 | ||
- | 378 | //printf("p %u ",ppm); |
|
- | 379 | //printf("pm %u ",(min+REDUCE)); |
|
Line 368... | Line -... | ||
368 | - | ||
Line 369... | Line 380... | ||
369 | if (color < 0) color = 0; |
380 | //printf("t1 %li ",temp1); |
370 | if (color > (STEP * 6)) color = (STEP * 6); |
381 | //printf("t2 %li ",temp2); |
371 | 382 | //printf("c %i\n ",color); |
|
372 | printf("color: %d\n",color); |
383 |