Rev 53 | Rev 55 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 53 | Rev 54 | ||
---|---|---|---|
Line 57... | Line 57... | ||
57 | ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536); |
57 | ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536); |
58 | if ((ppm > 600) && (ppm < 2400)) |
58 | if ((ppm > 600) && (ppm < 2400)) |
59 | { |
59 | { |
60 | if (ppm > 2100) ppm = 2100; |
60 | if (ppm > 2100) ppm = 2100; |
61 | if (ppm < 900) ppm = 900; |
61 | if (ppm < 900) ppm = 900; |
62 | ppm = (ppm_signal * 7 + ppm) / 8; |
62 | ppm = (ppm_signal * 3 + ppm) / 4; |
63 | ppm_signal = ppm; |
63 | ppm_signal = ppm; |
64 | ppm_new = 1; |
64 | if (ppm_new < 50) ppm_new++; |
65 | } |
65 | } |
Line 66... | Line 66... | ||
66 | 66 | ||
Line 67... | Line 67... | ||
67 | } |
67 | } |
Line 107... | Line 107... | ||
107 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; |
107 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; |
Line 108... | Line 108... | ||
108 | 108 | ||
109 | PORTB = PORTB_BAK; |
109 | PORTB = PORTB_BAK; |
Line -... | Line 110... | ||
- | 110 | PORTD = PORTD_BAK; |
|
110 | PORTD = PORTD_BAK; |
111 | |
111 | 112 | ||
112 | if (ms1++ == 32) |
113 | if (ms1++ == 32) |
113 | { |
114 | { |
114 | ms1=0; |
115 | ms1=0; |
Line 134... | Line 135... | ||
134 | return(((temp_hi << 8) | temp_lo) + t + 1); |
135 | return(((temp_hi << 8) | temp_lo) + t + 1); |
Line 135... | Line 136... | ||
135 | 136 | ||
Line -... | Line 137... | ||
- | 137 | } |
|
136 | } |
138 | |
137 | 139 | ||
138 | 140 | ||
139 | char CheckDelay(unsigned int t) |
141 | char CheckDelay(unsigned int t) |
Line 179... | Line 181... | ||
179 | } |
181 | } |
Line 180... | Line 182... | ||
180 | 182 | ||
181 | 183 | ||
182 | 184 | ||
183 | /*##############################################################################*/ |
185 | /*##############################################################################*/ |
184 | int GetPPM(void) |
186 | unsigned int GetPPM(void) |
185 | { |
187 | { |
Line 186... | Line 188... | ||
186 | //this routines seems to be nesseccary, as reading a 16 bit value |
188 | //this routines seems to be nesseccary, as reading a 16 bit value |
187 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
189 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
Line 188... | Line -... | ||
188 | //low and high byte of the 16 bit value a wrong result is possible |
- | |
189 | 190 | //low and high byte of the 16 bit value a wrong result is possible |
|
190 | unsigned char intmask; |
191 | |
191 | unsigned int ppm_temp; |
192 | unsigned char temp_hi; |
192 | 193 | unsigned char temp_lo; |
|
Line 193... | Line 194... | ||
193 | intmask = TIMSK; //backup interupt enable bits |
194 | |
Line 194... | Line 195... | ||
194 | TIMSK &= ~(1<<TICIE1); //disable ppm interrupt |
195 | temp_hi = (ppm_signal >> 8); |
195 | ppm_temp = ppm_signal; |
196 | temp_lo = (ppm_signal & 0xff); |
196 | TIMSK = intmask; //restore interupt enable bits |
197 | if (temp_hi != (ppm_signal >> 8)) temp_hi = (ppm_signal >> 8); |
197 | return(ppm_temp); //return ppm_signal |
198 | return( (temp_hi << 8) | temp_lo); |
198 | 199 | ||
- | 200 | } |
|
- | 201 | ||
199 | } |
202 | |
- | 203 | /*##############################################################################*/ |
|
- | 204 | // MAIN |
|
- | 205 | /*##############################################################################*/ |
|
- | 206 | int main (void) |
|
- | 207 | { |
|
- | 208 | ||
- | 209 | #define step 128 |
|
- | 210 | #define mul 2 |
|
200 | 211 | ||
- | 212 | #define sigeepadr 0x00 |
|
201 | 213 | #define mineepadr 0x20 |
|
- | 214 | #define maxeepadr 0x22 |
|
- | 215 | #define eepsig 0x55aa |
|
- | 216 | ||
- | 217 | ||
- | 218 | ||
202 | /*##############################################################################*/ |
219 | unsigned int ppm; |
- | 220 | unsigned int setupdly; |
|
Line 203... | Line 221... | ||
203 | // MAIN |
221 | unsigned int ppmtodly; |
204 | /*##############################################################################*/ |
222 | unsigned int lmax; |
Line 205... | Line 223... | ||
205 | int main (void) |
223 | unsigned int lmin; |
Line 223... | Line 241... | ||
223 | ch2 = 0; |
241 | ch2 = 0; |
224 | ch3 = 0; |
242 | ch3 = 0; |
225 | ch4 = 0; |
243 | ch4 = 0; |
226 | ch5 = 0; |
244 | ch5 = 0; |
Line -... | Line 245... | ||
- | 245 | ||
- | 246 | lmax = 0x0000; |
|
- | 247 | lmin = 0xffff; |
|
227 | 248 | ||
228 | //StartUART(); |
249 | StartUART(); |
229 | StartPPM(); |
250 | StartPPM(); |
230 | //StartI2C(); |
251 | //StartI2C(); |
231 | StartPWM(); |
252 | StartPWM(); |
Line 232... | Line 253... | ||
232 | sei(); |
253 | sei(); |
233 | - | ||
234 | - | ||
235 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
254 | |
Line -... | Line 255... | ||
- | 255 | ||
- | 256 | min = 1100; |
|
- | 257 | max = 1900; |
|
- | 258 | ||
- | 259 | if (eeprom_read_word(sigeepadr) != eepsig) |
|
- | 260 | { |
|
236 | 261 | eeprom_write_word(mineepadr, min); |
|
237 | 262 | eeprom_write_word(maxeepadr, max); |
|
- | 263 | eeprom_write_word(sigeepadr, eepsig); |
|
- | 264 | } |
|
- | 265 | else |
|
Line 238... | Line -... | ||
238 | colorState = 0; |
- | |
239 | 266 | { |
|
240 | while (1) |
- | |
Line 241... | Line -... | ||
241 | { |
- | |
242 | - | ||
243 | /* |
- | |
244 | #define step 128 |
- | |
245 | #define mul 2 |
- | |
246 | - | ||
247 | if ((ppm >= (step * 0) && (ppm < (step * 1))) ch0 = mul * ((ppm - (step * 0))); |
- | |
Line -... | Line 267... | ||
- | 267 | min = eeprom_read_word(mineepadr); |
|
248 | if ((ppm >= (step * 1)) && (ppm < (step * 2))) ch1 = mul * ((ppm - (step * 1))); |
268 | max = eeprom_read_word(maxeepadr); |
249 | if ((ppm >= (step * 2)) && (ppm < (step * 3))) ch0 = mul * ((step - 1) - (ppm - (step * 2))); |
- | |
- | 269 | } |
|
Line 250... | Line -... | ||
250 | if ((ppm >= (step * 3)) && (ppm < (step * 4))) ch2 = mul * ((ppm - (step * 3))); |
- | |
251 | if ((ppm >= (step * 4)) && (ppm < (step * 5))) ch1 = mul * ((step - 1) - (ppm - (step * 4))); |
- | |
252 | if ((ppm >= (step * 5)) && (ppm < (step * 6))) ch0 = mul * ((ppm - (step * 5))); |
270 | |
253 | if ((ppm >= (step * 6)) && (ppm < (step * 7))) ch2 = mul * ((step - 1) - (ppm - (step * 6))); |
271 | printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
254 | - | ||
255 | //printf("%d ",ppm); |
- | |
256 | */ |
- | |
257 | - | ||
Line 258... | Line 272... | ||
258 | for (i=0; i<=255; i++) |
272 | |
- | 273 | ||
- | 274 | setup = 0; |
|
- | 275 | setupdly = SetDelay(3000); |
|
- | 276 | ppmtodly = SetDelay(5000); |
|
- | 277 | ||
259 | { |
278 | while (1) |
- | 279 | { |
|
- | 280 | ||
- | 281 | if (ppm_new > 20) |
|
260 | switch(colorState) |
282 | { |
261 | { |
283 | PORTC clrbit ledred; |
- | 284 | ppm = GetPPM(); |
|
Line -... | Line 285... | ||
- | 285 | ppmtodly = SetDelay(500); |
|
262 | case 0: |
286 | if (lmax < ppm) lmax=ppm; |
263 | ch0 = i; //fade in (ch0) red |
287 | if (lmin > ppm) lmin=ppm; |
264 | nextcolorState = 2; |
288 | } |
265 | break; |
289 | else |
Line -... | Line 290... | ||
- | 290 | { |
|
- | 291 | PORTC setbit ledred; |
|
266 | 292 | ppm = min; |
|
- | 293 | } |
|
- | 294 | ||
267 | case 2: |
295 | if (CheckDelay(ppmtodly)) |
- | 296 | { |
|
- | 297 | ppmtodly = SetDelay(5000); |
|
- | 298 | ppm_new = 0; |
|
268 | ch1 = i; //fade in (ch1) blue to get pure purple (red + blue) |
299 | } |
- | 300 | ||
- | 301 | if ((ppm > 1600) && ((setup&1)==0)) setup++; |
|
- | 302 | if ((ppm < 1400) && ((setup&1)==1)) setup++; |
|
269 | nextcolorState = 4; |
303 | if (setup == 6) |
- | 304 | { |
|
- | 305 | PORTD setbit ledgreen; |
|
Line 270... | Line -... | ||
270 | break; |
- | |
271 | 306 | eeprom_write_word(mineepadr, lmin); |
|
272 | case 4: |
- | |
273 | ch0 = 255 - i; //fade out (ch0) red to get pure blue |
- | |
Line 274... | Line -... | ||
274 | nextcolorState = 6; |
- | |
275 | break; |
- | |
276 | - | ||
277 | case 6: |
- | |
Line -... | Line 307... | ||
- | 307 | eeprom_write_word(maxeepadr, lmax); |
|
- | 308 | min = lmin; |
|
- | 309 | max = lmax; |
|
- | 310 | setupdly = SetDelay(2000); |
|
- | 311 | } |
|
- | 312 | if (CheckDelay(setupdly)) |
|
278 | ch2 = i; //fade in (ch2) green to get pure cyan (blue + green) |
313 | { |
- | 314 | setup = 0; |
|
- | 315 | PORTD clrbit ledgreen; |
|
- | 316 | } |
|
- | 317 | ||
279 | nextcolorState = 8; |
318 | //printf("ppm: %d / min: %d / max: %d\n",ppm,lmin,lmax); |
- | 319 | ||
- | 320 | ||
- | 321 | /* |
|
- | 322 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
|
- | 323 | if ((ppm >= (step * 0)) && (ppm < (step * 1))) |
|
- | 324 | { |
|
- | 325 | ch0 = mul * ((ppm - (step * 0))); //fade in red > red (red only) |
|
- | 326 | ch1 = 0; |
|
- | 327 | ch2 = 0; |
|
- | 328 | } |
|
- | 329 | if ((ppm >= (step * 1)) && (ppm < (step * 2))) |
|
- | 330 | { |
|
- | 331 | ch0 = ((step-1) * mul); |
|
- | 332 | ch2 = mul * ((ppm - (step * 1))); //fade in blue > purple (red + blue) |
|
- | 333 | ch1 = 0; |
|
- | 334 | } |
|
280 | break; |
335 | if ((ppm >= (step * 2)) && (ppm < (step * 3))) |
- | 336 | { |
|
- | 337 | ch0 = mul * ((step - 1) - (ppm - (step * 2))); //fade out red > blue (blue only) |
|
- | 338 | ch2 = ((step-1) * mul); |
|
- | 339 | ch1 = 0; |
|
- | 340 | } |
|
- | 341 | if ((ppm >= (step * 3)) && (ppm < (step * 4))) |
|
281 | 342 | { |
|
- | 343 | ch0 = 0; |
|
282 | case 8: |
344 | ch2 = ((step-1) * mul); |
- | 345 | ch1 = mul * ((ppm - (step * 3))); //fade in green > tuerkis (blue + green) |
|
- | 346 | } |
|
- | 347 | if ((ppm >= (step * 4)) && (ppm < (step * 5))) |
|
- | 348 | { |
|
- | 349 | ch0 = 0; |
|
- | 350 | ch2 = mul * ((step - 1) - (ppm - (step * 4))); //fade out blue > green (green only) |
|
- | 351 | ch1 = ((step-1) * mul); |
|
- | 352 | } |
|
- | 353 | if ((ppm >= (step * 5)) && (ppm < (step * 6))) |
|
- | 354 | { |
|
- | 355 | ch0 = mul * ((ppm - (step * 5))); //fade in red > yellow (green + red) |
|
- | 356 | ch2 = 0; |
|
- | 357 | ch1 = ((step-1) * mul); |
|
Line 283... | Line -... | ||
283 | ch1 = 255 - i; //fade out (ch1) blue to get pure green |
- | |
284 | nextcolorState = 10; |
- | |
285 | break; |
- | |
Line 286... | Line -... | ||
286 | - | ||
Line 287... | Line -... | ||
287 | case 10: |
- | |
288 | ch0 = i; //fade in (ch0) red to get yellow pure (green + red) |
- | |
Line 289... | Line 358... | ||
289 | nextcolorState = 12; |
358 | } |