Rev 54 | Rev 56 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 54 | Rev 55 | ||
---|---|---|---|
1 | //############################################################################ |
1 | //############################################################################ |
2 | // - PWM CTRL |
2 | // - PWM CTRL |
3 | // - Main |
3 | // - Main |
4 | // - ATMEGA8 mit 8MHz |
4 | // - ATMEGA8 mit 8MHz |
5 | // - Nur für den privaten Gebrauch |
5 | // - Nur für den privaten Gebrauch |
6 | // - Keine Garantie auf Fehlerfreiheit |
6 | // - Keine Garantie auf Fehlerfreiheit |
7 | // - Kommerzielle Nutzung nur mit meiner Zustimmung |
7 | // - Kommerzielle Nutzung nur mit meiner Zustimmung |
8 | // - walter Meyer @ www.freakware.de |
8 | // - walter Meyer @ www.freakware.de |
9 | // - 11.12.2007 |
9 | // - 11.12.2007 |
10 | // - Make sure Fuses are programmed for internal 8 MHz RC Oscilator |
10 | // - Make sure Fuses are programmed for internal 8 MHz RC Oscilator |
11 | //############################################################################*/ |
11 | //############################################################################*/ |
12 | 12 | ||
13 | #include "main.h" |
13 | #include "main.h" |
14 | #include "uart.h" |
14 | #include "uart.h" |
15 | #include "twislave.h" |
15 | #include "twislave.h" |
16 | 16 | ||
17 | volatile unsigned int ppm_signal = 1500; |
17 | volatile unsigned int PPM_SIGNAL = 1500; |
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; |
21 | volatile unsigned char ch0; |
21 | volatile unsigned char CH0; |
22 | volatile unsigned char ch1; |
22 | volatile unsigned char CH1; |
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; |
- | |
27 | volatile unsigned char ch0_tmp; |
- | |
28 | volatile unsigned char ch1_tmp; |
- | |
29 | volatile unsigned char ch2_tmp; |
- | |
30 | volatile unsigned char ch3_tmp; |
- | |
31 | volatile unsigned char ch4_tmp; |
- | |
32 | volatile unsigned char ch5_tmp; |
26 | volatile unsigned char CH5; |
33 | - | ||
34 | 27 | ||
35 | unsigned int timer; |
28 | |
36 | 29 | /*##############################################################################*/ |
|
37 | SIGNAL(SIG_OVERFLOW1) |
30 | SIGNAL(SIG_OVERFLOW1) |
38 | { |
31 | { |
39 | TMR1OvF++; |
32 | TMR1OvF++; |
40 | } |
33 | } |
41 | 34 | ||
42 | 35 | ||
43 | SIGNAL(SIG_INPUT_CAPTURE1) |
36 | SIGNAL(SIG_INPUT_CAPTURE1) |
44 | { |
37 | { |
45 | static unsigned int pos_ICR; |
38 | static unsigned int pos_ICR; |
46 | static unsigned int ppm; |
39 | static unsigned int ppm; |
47 | 40 | ||
48 | if ((TCCR1B & (1<<ICES1)) != 0) //rising edge |
41 | if ((TCCR1B & (1<<ICES1)) != 0) //rising edge |
49 | { |
42 | { |
50 | TCCR1B &= ~(1<<ICES1); //set falling egde |
43 | TCCR1B &= ~(1<<ICES1); //set falling egde |
51 | TMR1OvF = 0; |
44 | TMR1OvF = 0; |
52 | pos_ICR = ICR1; |
45 | pos_ICR = ICR1; |
53 | } |
46 | } |
54 | else //falling edge |
47 | else //falling edge |
55 | { |
48 | { |
56 | TCCR1B |= (1<<ICES1); //set rising egde |
49 | TCCR1B |= (1<<ICES1); //set rising egde |
57 | ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536); |
50 | ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536); |
58 | if ((ppm > 600) && (ppm < 2400)) |
51 | if ((ppm > 600) && (ppm < 2400)) |
59 | { |
52 | { |
60 | if (ppm > 2100) ppm = 2100; |
53 | if (ppm > 2100) ppm = 2100; |
61 | if (ppm < 900) ppm = 900; |
54 | if (ppm < 900) ppm = 900; |
62 | ppm = (ppm_signal * 3 + ppm) / 4; |
55 | ppm = (PPM_SIGNAL * 3 + ppm) / 4; |
63 | ppm_signal = ppm; |
56 | PPM_SIGNAL = ppm; |
64 | if (ppm_new < 50) ppm_new++; |
57 | if (PPM_NEW < 50) PPM_NEW++; |
65 | } |
58 | } |
66 | 59 | ||
67 | } |
60 | } |
68 | 61 | ||
69 | } |
62 | } |
70 | - | ||
71 | - | ||
72 | - | ||
73 | - | ||
- | 63 | ||
74 | 64 | /*##############################################################################*/ |
|
75 | SIGNAL(SIG_OVERFLOW0) |
65 | SIGNAL(SIG_OVERFLOW0) |
76 | { |
66 | { |
77 | // this function is called every 32us, |
67 | // this function is called every 32us, |
78 | // it is very important that it's execution time is as short as possible |
68 | // it is very important that it's execution time is as short as possible |
79 | // currently it's about 20us |
69 | // currently it's about 20us |
80 | 70 | ||
81 | static unsigned char counter = 254; |
71 | static unsigned char counter = 254; |
82 | static unsigned char ms1 = 0; |
72 | static unsigned char ms1 = 0; |
- | 73 | static unsigned char ch0_tmp = 0; |
|
- | 74 | static unsigned char ch1_tmp = 0; |
|
- | 75 | static unsigned char ch2_tmp = 0; |
|
- | 76 | static unsigned char ch3_tmp = 0; |
|
- | 77 | static unsigned char ch4_tmp = 0; |
|
- | 78 | static unsigned char ch5_tmp = 0; |
|
83 | unsigned char PORTB_BAK; |
79 | unsigned char PORTB_BAK; |
84 | unsigned char PORTD_BAK; |
80 | unsigned char PORTD_BAK; |
85 | 81 | ||
86 | PORTB_BAK = PORTB; |
82 | PORTB_BAK = PORTB; |
87 | PORTD_BAK = PORTD; |
83 | PORTD_BAK = PORTD; |
88 | 84 | ||
89 | if (counter++ == 254) |
85 | if (counter++ == 254) |
90 | { |
86 | { |
91 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); |
87 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); //new cycle, output on |
92 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); |
88 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); // |
93 | ch0_tmp = ch0; |
89 | ch0_tmp = CH0; |
94 | ch1_tmp = ch1; |
90 | ch1_tmp = CH1; |
95 | ch2_tmp = ch2; |
91 | ch2_tmp = CH2; |
96 | ch3_tmp = ch3; |
92 | ch3_tmp = CH3; |
97 | ch4_tmp = ch4; |
93 | ch4_tmp = CH4; |
98 | ch5_tmp = ch5; |
94 | ch5_tmp = CH5; |
99 | counter = 0; |
95 | counter = 0; |
100 | } |
96 | } |
101 | 97 | ||
102 | if (ch0_tmp == counter) PORTB_BAK LEDOFF CH0_B; |
98 | if (ch0_tmp == counter) PORTB_BAK LEDOFF CH0_B; //channel value reached, output off |
103 | if (ch1_tmp == counter) PORTB_BAK LEDOFF CH1_B; |
99 | if (ch1_tmp == counter) PORTB_BAK LEDOFF CH1_B; // |
104 | if (ch2_tmp == counter) PORTB_BAK LEDOFF CH2_B; |
100 | if (ch2_tmp == counter) PORTB_BAK LEDOFF CH2_B; // |
105 | if (ch3_tmp == counter) PORTD_BAK LEDOFF CH3_D; |
101 | if (ch3_tmp == counter) PORTD_BAK LEDOFF CH3_D; // |
106 | if (ch4_tmp == counter) PORTD_BAK LEDOFF CH4_D; |
102 | if (ch4_tmp == counter) PORTD_BAK LEDOFF CH4_D; // |
107 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; |
103 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; // |
108 | 104 | ||
109 | PORTB = PORTB_BAK; |
105 | PORTB = PORTB_BAK; |
110 | PORTD = PORTD_BAK; |
106 | PORTD = PORTD_BAK; |
111 | - | ||
112 | 107 | ||
113 | if (ms1++ == 32) |
108 | if (ms1++ == 32) |
114 | { |
109 | { |
115 | ms1=0; |
110 | ms1=0; |
116 | TMR1MS++; |
111 | TMR1MS++; |
117 | } |
112 | } |
118 | 113 | ||
119 | 114 | ||
120 | 115 | ||
121 | 116 | ||
122 | } |
117 | } |
123 | 118 | ||
124 | - | ||
- | 119 | ||
125 | 120 | /*##############################################################################*/ |
|
126 | unsigned int SetDelay (unsigned int t) |
121 | unsigned int SetDelay (unsigned int t) |
127 | { |
122 | { |
128 | unsigned char temp_hi; |
123 | unsigned char hi_byte; |
129 | unsigned char temp_lo; |
- | |
130 | - | ||
131 | temp_hi = (TMR1MS >> 8); |
- | |
132 | temp_lo = (TMR1MS & 0xff); |
- | |
- | 124 | unsigned char lo_byte; |
|
- | 125 | ||
133 | if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8); |
126 | hi_byte = (TMR1MS >> 8); |
- | 127 | lo_byte = (TMR1MS & 0xff); |
|
134 | 128 | if (hi_byte != (TMR1MS >> 8)) hi_byte = (TMR1MS >> 8); |
|
135 | return(((temp_hi << 8) | temp_lo) + t + 1); |
129 | |
136 | 130 | return(((hi_byte << 8) | lo_byte) + t + 1); |
|
137 | } |
131 | } |
138 | 132 | ||
139 | - | ||
- | 133 | ||
140 | 134 | /*##############################################################################*/ |
|
141 | char CheckDelay(unsigned int t) |
135 | char CheckDelay(unsigned int t) |
142 | { |
136 | { |
143 | unsigned char temp_hi; |
137 | unsigned char hi_byte; |
144 | unsigned char temp_lo; |
- | |
145 | - | ||
146 | temp_hi = (TMR1MS >> 8); |
- | |
147 | temp_lo = (TMR1MS & 0xff); |
- | |
- | 138 | unsigned char lo_byte; |
|
- | 139 | ||
148 | if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8); |
140 | hi_byte = (TMR1MS >> 8); |
- | 141 | lo_byte = (TMR1MS & 0xff); |
|
149 | 142 | if (hi_byte != (TMR1MS >> 8)) hi_byte = (TMR1MS >> 8); |
|
150 | return(((t - ((temp_hi << 8) | temp_lo)) & 0x8000) >> 9); |
143 | |
151 | 144 | return(((t - ((hi_byte << 8) | lo_byte)) & 0x8000) >> 9); |
|
152 | } |
145 | } |
153 | 146 | ||
154 | 147 | ||
155 | - | ||
156 | 148 | ||
157 | /*##############################################################################*/ |
149 | /*##############################################################################*/ |
158 | void StartPWM(void) |
150 | void StartPWM(void) |
159 | { |
151 | { |
160 | //Timer 0 Config for getting right timing for IR Pattern |
152 | //Timer 0 Config |
161 | TCCR0 = (0<<CS02)|(0<<CS01)|(1<<CS00); // (@8MHz) = 1/8us Clk = 256/8 = 32us overflow |
153 | TCCR0 = (0<<CS02)|(0<<CS01)|(1<<CS00); // (@8MHz) = 1/8us Clk = 256/8 = 32us overflow |
162 | TIMSK setbit (1<<TOIE0); // enable Int |
154 | TIMSK setbit (1<<TOIE0); // enable Int |
163 | 155 | ||
164 | } |
156 | } |
165 | 157 | ||
166 | - | ||
167 | 158 | ||
168 | /*##############################################################################*/ |
159 | /*##############################################################################*/ |
169 | void StartPPM(void) |
160 | void StartPPM(void) |
170 | { |
161 | { |
171 | 162 | ||
172 | //global timer1 Config |
163 | //Timer1 Config |
173 | TCCR1A = (0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)| |
164 | TCCR1A = (0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)| |
174 | (0<<FOC1A) |(0<<FOC1B) |(0<<WGM10) |(0<<WGM11); |
165 | (0<<FOC1A) |(0<<FOC1B) |(0<<WGM10) |(0<<WGM11); |
175 | TCCR1B = (1<<ICNC1)|(1<<ICES1)|(0<<WGM13)| |
166 | TCCR1B = (1<<ICNC1)|(1<<ICES1)|(0<<WGM13)| |
176 | (0<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10); //ICP_POS_FLANKE |
167 | (0<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10); //ICP_POS_FLANKE |
177 | 168 | ||
178 | // interrupts |
169 | // interrupts |
179 | TIMSK |= (1<<TICIE1)|(1<<TOIE1); //ICP_INT_ENABLE and TIMER1_INT_ENABLE |
170 | TIMSK |= (1<<TICIE1)|(1<<TOIE1); //ICP_INT_ENABLE and TIMER1_INT_ENABLE |
180 | 171 | ||
181 | } |
172 | } |
182 | 173 | ||
183 | - | ||
184 | 174 | ||
185 | /*##############################################################################*/ |
175 | /*##############################################################################*/ |
186 | unsigned int GetPPM(void) |
176 | unsigned int GetPPM(void) |
187 | { |
177 | { |
188 | //this routines seems to be nesseccary, as reading a 16 bit value |
178 | //this routines seems to be nesseccary, as reading a 16 bit value |
189 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
179 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
190 | //low and high byte of the 16 bit value a wrong result is possible |
180 | //low and high byte of the 16 bit value a wrong result is possible |
191 | 181 | ||
192 | unsigned char temp_hi; |
182 | unsigned char temp_hi; |
193 | unsigned char temp_lo; |
183 | unsigned char temp_lo; |
194 | 184 | ||
195 | temp_hi = (ppm_signal >> 8); |
185 | temp_hi = (PPM_SIGNAL >> 8); |
196 | temp_lo = (ppm_signal & 0xff); |
186 | temp_lo = (PPM_SIGNAL & 0xff); |
197 | if (temp_hi != (ppm_signal >> 8)) temp_hi = (ppm_signal >> 8); |
187 | if (temp_hi != (PPM_SIGNAL >> 8)) temp_hi = (PPM_SIGNAL >> 8); |
198 | return( (temp_hi << 8) | temp_lo); |
188 | return( (temp_hi << 8) | temp_lo); |
199 | 189 | ||
200 | } |
190 | } |
201 | 191 | ||
202 | 192 | ||
203 | /*##############################################################################*/ |
193 | /*##############################################################################*/ |
204 | // MAIN |
194 | // MAIN |
205 | /*##############################################################################*/ |
195 | /*##############################################################################*/ |
206 | int main (void) |
196 | int main (void) |
207 | { |
197 | { |
208 | 198 | ||
209 | #define step 128 |
199 | #define STEP 256 |
- | 200 | #define MUL 1 |
|
210 | #define mul 2 |
201 | #define REDUCE 5 |
211 | 202 | ||
212 | #define sigeepadr 0x00 |
203 | #define EEPADRSIG 0x00 |
213 | #define mineepadr 0x20 |
204 | #define EEPADRMIN 0x20 |
214 | #define maxeepadr 0x22 |
205 | #define EEPADRMAX 0x22 |
215 | #define eepsig 0x55aa |
- | |
216 | - | ||
217 | 206 | #define EEPSIGATURE 0x55aa |
|
- | 207 | ||
218 | 208 | unsigned int ppm; |
|
219 | unsigned int ppm; |
209 | signed int color; |
- | 210 | unsigned int setupdly; |
|
- | 211 | unsigned int ppmtodly; |
|
220 | unsigned int setupdly; |
212 | unsigned int flashdly; |
221 | unsigned int ppmtodly; |
213 | unsigned char setup; |
222 | unsigned int lmax; |
214 | unsigned int lmax; |
223 | unsigned int lmin; |
215 | unsigned int lmin; |
224 | unsigned int max; |
216 | unsigned int max; |
225 | unsigned int min; |
217 | unsigned int min; |
226 | unsigned int sig; |
218 | unsigned long temp1; |
227 | unsigned char setup; |
219 | unsigned long temp2; |
- | 220 | ||
228 | 221 | ||
229 | 222 | ||
230 | DDRB = (CH0_B|CH1_B|CH2_B); |
223 | DDRB = (CH0_B|CH1_B|CH2_B); |
231 | PORTB = 0x00; |
224 | PORTB = 0x00; |
232 | 225 | ||
233 | DDRC = (ledred); |
226 | DDRC = (ledred); |
234 | PORTC = 0x00; |
227 | PORTC = 0x00; |
235 | 228 | ||
236 | DDRD = (ledgreen|CH3_D|CH4_D|CH5_D); |
229 | DDRD = (ledgreen|CH3_D|CH4_D|CH5_D); |
237 | PORTD = 0x00; |
230 | PORTD = 0x00; |
238 | 231 | ||
239 | ch0 = 0; |
232 | CH0 = 0; |
240 | ch1 = 0; |
233 | CH1 = 0; |
241 | ch2 = 0; |
234 | CH2 = 0; |
242 | ch3 = 0; |
235 | CH3 = 0; |
243 | ch4 = 0; |
236 | CH4 = 0; |
244 | ch5 = 0; |
237 | CH5 = 0; |
245 | 238 | ||
246 | lmax = 0x0000; |
239 | lmax = 0x0000; |
247 | lmin = 0xffff; |
240 | lmin = 0xffff; |
248 | 241 | ||
249 | StartUART(); |
242 | StartUART(); |
250 | StartPPM(); |
243 | StartPPM(); |
251 | //StartI2C(); |
244 | //StartI2C(); |
252 | StartPWM(); |
245 | StartPWM(); |
253 | sei(); |
246 | sei(); |
254 | 247 | ||
255 | - | ||
256 | min = 1100; |
- | |
257 | max = 1900; |
248 | |
258 | 249 | ||
- | 250 | if (eeprom_read_word(EEPADRSIG) != EEPSIGATURE) //check eep if signature is there |
|
- | 251 | { |
|
259 | if (eeprom_read_word(sigeepadr) != eepsig) |
252 | min = 1100; //default min |
260 | { |
253 | max = 1900; //default max |
261 | eeprom_write_word(mineepadr, min); |
254 | eeprom_write_word(EEPADRMIN, min); //no, write initial min |
262 | eeprom_write_word(maxeepadr, max); |
255 | eeprom_write_word(EEPADRMAX, max); //and max values |
263 | eeprom_write_word(sigeepadr, eepsig); |
256 | eeprom_write_word(EEPADRSIG, EEPSIGATURE); //along with eep signature |
264 | } |
257 | } |
265 | else |
258 | else |
266 | { |
259 | { |
267 | min = eeprom_read_word(mineepadr); |
260 | min = eeprom_read_word(EEPADRMIN); //signature ok |
268 | max = eeprom_read_word(maxeepadr); |
261 | max = eeprom_read_word(EEPADRMAX); //read min and max |
269 | } |
262 | } |
270 | 263 | ||
271 | printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
- | |
272 | - | ||
273 | - | ||
274 | setup = 0; |
264 | setup = 0; //reset setup toggle counter |
275 | setupdly = SetDelay(3000); |
265 | setupdly = SetDelay(3000); |
- | 266 | ppmtodly = SetDelay(5000); |
|
276 | ppmtodly = SetDelay(5000); |
267 | flashdly = SetDelay(100); |
277 | 268 | ||
278 | while (1) |
269 | while (1) |
279 | { |
270 | { |
280 | 271 | ||
281 | if (ppm_new > 20) |
272 | if (PPM_NEW > 20) //ppm Signal ok |
282 | { |
273 | { |
283 | PORTC clrbit ledred; |
274 | PORTC clrbit ledred; |
284 | ppm = GetPPM(); |
275 | ppm = GetPPM(); |
285 | ppmtodly = SetDelay(500); |
276 | ppmtodly = SetDelay(500); //reset timeout |
286 | if (lmax < ppm) lmax=ppm; |
277 | if (lmax < ppm) lmax=ppm; //update impulse max |
287 | if (lmin > ppm) lmin=ppm; |
278 | if (lmin > ppm) lmin=ppm; //and min boundarys |
288 | } |
279 | } |
289 | else |
280 | else |
290 | { |
281 | { |
291 | PORTC setbit ledred; |
282 | PORTC setbit ledred; //ppm signal not ok |
292 | ppm = min; |
283 | ppm = min; //set ppm to minimum |
293 | } |
284 | } |
- | 285 | ||
294 | 286 | ||
295 | if (CheckDelay(ppmtodly)) |
287 | if (CheckDelay(ppmtodly)) //timeout |
296 | { |
288 | { |
297 | ppmtodly = SetDelay(5000); |
289 | ppmtodly = SetDelay(5000); |
298 | ppm_new = 0; |
290 | PPM_NEW = 0; //set ppm signal not ok |
299 | } |
- | |
300 | - | ||
- | 291 | } |
|
301 | if ((ppm > 1600) && ((setup&1)==0)) setup++; |
292 | |
302 | if ((ppm < 1400) && ((setup&1)==1)) setup++; |
293 | |
- | 294 | if (setup < 6) |
|
- | 295 | { |
|
- | 296 | if ((ppm > 1600) && ((setup&1)==0)) setup++; // |
|
- | 297 | if ((ppm < 1400) && ((setup&1)==1)) setup++; // |
|
- | 298 | ||
- | 299 | if (CheckDelay(flashdly)) //setup timeout reached |
|
- | 300 | { |
|
- | 301 | CH0 = CH0 ^ 0xff; |
|
- | 302 | CH1 = CH1 ^ 0xff; |
|
- | 303 | CH2 = CH2 ^ 0xff; |
|
- | 304 | flashdly = SetDelay(250); |
|
- | 305 | } |
|
- | 306 | ||
- | 307 | } |
|
- | 308 | ||
303 | if (setup == 6) |
309 | if (setup == 6) //if stick is toggled 6 times |
304 | { |
310 | { //within setup timeout |
305 | PORTD setbit ledgreen; |
311 | PORTD setbit ledgreen; //store ppm min and max |
306 | eeprom_write_word(mineepadr, lmin); |
312 | eeprom_write_word(EEPADRMIN, lmin); //in eeprom |
307 | eeprom_write_word(maxeepadr, lmax); |
313 | eeprom_write_word(EEPADRMAX, lmax); |
308 | min = lmin; |
314 | min = lmin; |
309 | max = lmax; |
315 | max = lmax; |
310 | setupdly = SetDelay(2000); |
316 | setupdly = SetDelay(2000); |
- | 317 | ||
- | 318 | if (CheckDelay(flashdly)) //setup timeout reached |
|
- | 319 | { |
|
- | 320 | CH0 = CH0 ^ 0xff; |
|
- | 321 | CH1 = CH1 ^ 0xff; |
|
- | 322 | CH2 = CH2 ^ 0xff; |
|
- | 323 | flashdly = SetDelay(25); |
|
- | 324 | } |
|
- | 325 | ||
311 | } |
326 | } |
- | 327 | ||
312 | if (CheckDelay(setupdly)) |
328 | if (CheckDelay(setupdly)) //setup timeout reached |
313 | { |
329 | { |
314 | setup = 0; |
330 | setup = 7; //lockdown setup |
315 | PORTD clrbit ledgreen; |
331 | PORTD clrbit ledgreen; |
316 | } |
332 | } |
317 | 333 | ||
318 | //printf("ppm: %d / min: %d / max: %d\n",ppm,lmin,lmax); |
334 | //printf("ppm: %d / min: %d / max: %d\n",ppm,lmin,lmax); |
319 | 335 | ||
- | 336 | ||
- | 337 | ||
- | 338 | if (setup = 7) |
|
320 | 339 | { |
|
- | 340 | ||
- | 341 | temp1 = (STEP * (long)40000 * (long)6) / ((max-REDUCE) - (min+REDUCE)); |
|
- | 342 | temp2 = ((ppm - (min+REDUCE)) * temp1); |
|
- | 343 | color = temp2 / 40000; |
|
- | 344 | ||
- | 345 | if (color < 0) color = 0; |
|
- | 346 | if (color > (STEP * 6)) color = (STEP * 6); |
|
321 | /* |
347 | |
322 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
348 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
323 | if ((ppm >= (step * 0)) && (ppm < (step * 1))) |
349 | if ((color >= (STEP * 0)) && (color < (STEP * 1))) |
324 | { |
350 | { |
325 | ch0 = mul * ((ppm - (step * 0))); //fade in red > red (red only) |
351 | CH0 = MUL * ((color - (STEP * 0))); //fade in red > red (red only) |
326 | ch1 = 0; |
352 | CH1 = 0; |
327 | ch2 = 0; |
353 | CH2 = 0; |
328 | } |
354 | } |
329 | if ((ppm >= (step * 1)) && (ppm < (step * 2))) |
355 | if ((color >= (STEP * 1)) && (color < (STEP * 2))) |
330 | { |
356 | { |
- | 357 | CH0 = ((STEP-1) * MUL); |
|
331 | ch0 = ((step-1) * mul); |
358 | CH1 = 0; |
332 | ch2 = mul * ((ppm - (step * 1))); //fade in blue > purple (red + blue) |
- | |
333 | ch1 = 0; |
359 | CH2 = MUL * ((color - (STEP * 1))); //fade in blue > purple (red + blue) |
334 | } |
360 | } |
335 | if ((ppm >= (step * 2)) && (ppm < (step * 3))) |
361 | if ((color >= (STEP * 2)) && (color < (STEP * 3))) |
336 | { |
362 | { |
337 | ch0 = mul * ((step - 1) - (ppm - (step * 2))); //fade out red > blue (blue only) |
- | |
338 | ch2 = ((step-1) * mul); |
363 | CH0 = MUL * ((STEP - 1) - (color - (STEP * 2))); //fade out red > blue (blue only) |
- | 364 | CH1 = 0; |
|
339 | ch1 = 0; |
365 | CH2 = ((STEP-1) * MUL); |
340 | } |
366 | } |
341 | if ((ppm >= (step * 3)) && (ppm < (step * 4))) |
367 | if ((color >= (STEP * 3)) && (color < (STEP * 4))) |
342 | { |
368 | { |
343 | ch0 = 0; |
- | |
344 | ch2 = ((step-1) * mul); |
369 | CH0 = 0; |
- | 370 | CH1 = MUL * ((color - (STEP * 3))); //fade in green > cyan (blue + green) |
|
345 | ch1 = mul * ((ppm - (step * 3))); //fade in green > tuerkis (blue + green) |
371 | CH2 = ((STEP-1) * MUL); |
346 | } |
372 | } |
347 | if ((ppm >= (step * 4)) && (ppm < (step * 5))) |
373 | if ((color >= (STEP * 4)) && (color < (STEP * 5))) |
348 | { |
374 | { |
- | 375 | CH0 = 0; |
|
349 | ch0 = 0; |
376 | CH1 = ((STEP-1) * MUL); |
350 | ch2 = mul * ((step - 1) - (ppm - (step * 4))); //fade out blue > green (green only) |
- | |
351 | ch1 = ((step-1) * mul); |
377 | CH2 = MUL * ((STEP - 1) - (color - (STEP * 4))); //fade out blue > green (green only) |
352 | } |
378 | } |
353 | if ((ppm >= (step * 5)) && (ppm < (step * 6))) |
379 | if ((color >= (STEP * 5)) && (color < (STEP * 6))) |
354 | { |
380 | { |
- | 381 | CH0 = MUL * ((color - (STEP * 5))); //fade in red > yellow (green + red) |
|
355 | ch0 = mul * ((ppm - (step * 5))); //fade in red > yellow (green + red) |
382 | CH1 = ((STEP-1) * MUL); |
356 | ch2 = 0; |
- | |
357 | ch1 = ((step-1) * mul); |
383 | CH2 = 0; |
358 | } |
384 | } |
359 | if ((ppm >= (step * 6)) && (ppm < (step * 7))) |
385 | if (color >= (STEP * 6)) |
- | 386 | { |
|
360 | { |
387 | CH0 = ((STEP-1) * MUL); //fade in red > yellow (green + red) |
361 | ch0 = ((step-1) * mul); |
388 | CH1 = ((STEP-1) * MUL); |
362 | ch2 = 0; |
- | |
363 | ch1 = mul * ((step - 1) - (ppm - (step * 6))); //fade out green > red (red only) |
389 | CH2 = 0; |
364 | } |
- | |
365 | if ((ppm >= (step * 7)) ) |
- | |
366 | { |
- | |
367 | ch0 = ((step-1) * mul); |
- | |
368 | ch2 = 0; |
- | |
369 | ch1 = 9; |
390 | } |
370 | } |
- | |
371 | */ |
- | |
372 | - | ||
373 | - | ||
374 | - | ||
375 | 391 | } |
|
376 | 392 | ||
377 | 393 | ||
378 | } |
394 | } |
379 | - | ||
380 | 395 | ||
381 | } |
396 | } |
382 | 397 | ||
383 | 398 |