Rev 51 | Rev 53 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 51 | Rev 52 | ||
---|---|---|---|
Line 22... | Line 22... | ||
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; |
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; |
|
- | 33 | ||
- | 34 | ||
27 | unsigned int timer; |
35 | unsigned int timer; |
28 | 36 | ||
29 | SIGNAL(SIG_OVERFLOW1) |
37 | SIGNAL(SIG_OVERFLOW1) |
30 | { |
38 | { |
31 | TMR1OvF++; |
39 | TMR1OvF++; |
Line 64... | Line 72... | ||
64 | 72 | ||
65 | 73 | ||
66 | 74 | ||
67 | SIGNAL(SIG_OVERFLOW0) |
75 | SIGNAL(SIG_OVERFLOW0) |
68 | { |
76 | { |
- | 77 | // this function is called every 32us, |
|
- | 78 | // it is very important that it's execution time is as short as possible |
|
- | 79 | // currently it's about 20us |
|
- | 80 | ||
69 | static unsigned char counter; |
81 | static unsigned char counter = 254; |
70 | static unsigned char ms1; |
82 | static unsigned char ms1 = 0; |
71 | unsigned char PORTB_BAK; |
83 | unsigned char PORTB_BAK; |
72 | unsigned char PORTD_BAK; |
84 | unsigned char PORTD_BAK; |
73 | 85 | ||
74 | PORTB_BAK = PORTB; |
86 | PORTB_BAK = PORTB; |
75 | PORTD_BAK = PORTD; |
87 | PORTD_BAK = PORTD; |
76 | 88 | ||
77 | if (counter++ == 254) |
89 | if (counter++ == 254) |
78 | { |
90 | { |
79 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); |
91 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); |
80 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); |
92 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); |
- | 93 | ch0_tmp = ch0; |
|
- | 94 | ch1_tmp = ch1; |
|
- | 95 | ch2_tmp = ch2; |
|
- | 96 | ch3_tmp = ch3; |
|
- | 97 | ch4_tmp = ch4; |
|
- | 98 | ch5_tmp = ch5; |
|
81 | counter = 0; |
99 | counter = 0; |
82 | } |
100 | } |
83 | 101 | ||
84 | if (ch0 == counter) PORTB_BAK LEDOFF CH0_B; |
102 | if (ch0_tmp == counter) PORTB_BAK LEDOFF CH0_B; |
85 | if (ch1 == counter) PORTB_BAK LEDOFF CH1_B; |
103 | if (ch1_tmp == counter) PORTB_BAK LEDOFF CH1_B; |
86 | if (ch2 == counter) PORTB_BAK LEDOFF CH2_B; |
104 | if (ch2_tmp == counter) PORTB_BAK LEDOFF CH2_B; |
87 | if (ch3 == counter) PORTD_BAK LEDOFF CH3_D; |
105 | if (ch3_tmp == counter) PORTD_BAK LEDOFF CH3_D; |
88 | if (ch4 == counter) PORTD_BAK LEDOFF CH4_D; |
106 | if (ch4_tmp == counter) PORTD_BAK LEDOFF CH4_D; |
89 | if (ch5 == counter) PORTD_BAK LEDOFF CH5_D; |
107 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; |
90 | 108 | ||
91 | PORTB = PORTB_BAK; |
109 | PORTB = PORTB_BAK; |
92 | PORTD = PORTD_BAK; |
110 | PORTD = PORTD_BAK; |
93 | 111 | ||
94 | if (ms1++ == 32) |
112 | if (ms1++ == 32) |
Line 143... | Line 161... | ||
143 | 161 | ||
144 | } |
162 | } |
145 | 163 | ||
146 | 164 | ||
147 | 165 | ||
148 | - | ||
149 | /*##############################################################################*/ |
166 | /*##############################################################################*/ |
150 | void StartPPM(void) |
167 | void StartPPM(void) |
151 | { |
168 | { |
152 | 169 | ||
153 | //global timer1 Config |
170 | //global timer1 Config |
Line 161... | Line 178... | ||
161 | 178 | ||
162 | } |
179 | } |
163 | 180 | ||
164 | 181 | ||
165 | 182 | ||
- | 183 | /*##############################################################################*/ |
|
166 | int GetPPM(void) |
184 | int GetPPM(void) |
167 | { |
185 | { |
168 | //this routines seems to be nesseccary, as reading a 16 bit value |
186 | //this routines seems to be nesseccary, as reading a 16 bit value |
169 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
187 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
170 | //low and high byte of the 16 bit value a wrong result is possible |
188 | //low and high byte of the 16 bit value a wrong result is possible |
Line 186... | Line 204... | ||
186 | /*##############################################################################*/ |
204 | /*##############################################################################*/ |
187 | int main (void) |
205 | int main (void) |
188 | { |
206 | { |
189 | unsigned int i; |
207 | unsigned int i; |
190 | unsigned char colorState; |
208 | unsigned char colorState; |
191 | unsigned char nextcolorState; |
209 | unsigned char nextcolorState=0; |
192 | 210 | ||
193 | DDRB = (CH0_B|CH1_B|CH2_B); |
211 | DDRB = (CH0_B|CH1_B|CH2_B); |
194 | PORTB = 0x00; |
212 | PORTB = 0x00; |
195 | 213 | ||
196 | DDRC = (ledred); |
214 | DDRC = (ledred); |
Line 211... | Line 229... | ||
211 | //StartI2C(); |
229 | //StartI2C(); |
212 | StartPWM(); |
230 | StartPWM(); |
213 | sei(); |
231 | sei(); |
214 | 232 | ||
215 | 233 | ||
216 | //rot > Violett > Blau > Türkis > Grün > Gelb > |
234 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
217 | 235 | ||
218 | 236 | ||
219 | colorState = 0; |
237 | colorState = 0; |
220 | 238 | ||
221 | while (1) |
239 | while (1) |
Line 226... | Line 244... | ||
226 | for (i=0; i<=255; i++) |
244 | for (i=0; i<=255; i++) |
227 | { |
245 | { |
228 | switch(colorState) |
246 | switch(colorState) |
229 | { |
247 | { |
230 | case 0: |
248 | case 0: |
231 | ch0 = i; //fade in (ch0) red |
249 | ch0 = i; //fade in (ch0) red |
232 | nextcolorState = 2; |
250 | nextcolorState = 2; |
233 | break; |
251 | break; |
234 | 252 | ||
235 | case 2: |
253 | case 2: |
236 | ch1 = i; //fade in (ch1) blue to get purple (red + blue) |
254 | ch1 = i; //fade in (ch1) blue to get pure purple (red + blue) |
237 | nextcolorState = 4; |
255 | nextcolorState = 4; |
238 | break; |
256 | break; |
239 | 257 | ||
240 | case 4: |
258 | case 4: |
241 | ch0 = 255 - i; //fade out (ch0) red to get pure blue |
259 | ch0 = 255 - i; //fade out (ch0) red to get pure blue |
242 | nextcolorState = 6; |
260 | nextcolorState = 6; |
243 | break; |
261 | break; |
244 | 262 | ||
245 | case 6: |
263 | case 6: |
246 | ch2 = i; //fade in (ch2) green to get cyan (blue + green) |
264 | ch2 = i; //fade in (ch2) green to get pure cyan (blue + green) |
247 | nextcolorState = 8; |
265 | nextcolorState = 8; |
248 | break; |
266 | break; |
249 | 267 | ||
250 | case 8: |
268 | case 8: |
251 | ch1 = 255 - i; //fade out (ch1) blue to get pure green |
269 | ch1 = 255 - i; //fade out (ch1) blue to get pure green |
252 | nextcolorState = 10; |
270 | nextcolorState = 10; |
253 | break; |
271 | break; |
254 | 272 | ||
255 | case 10: |
273 | case 10: |
256 | ch0 = i; //fade in (ch0) red to get yellow (green + red) |
274 | ch0 = i; //fade in (ch0) red to get yellow pure (green + red) |
257 | nextcolorState = 12; |
275 | nextcolorState = 12; |
258 | break; |
276 | break; |
259 | 277 | ||
260 | case 12: |
278 | case 12: |
261 | ch2 = 255 - i; //fade out (ch2) green to get pure red |
279 | ch2 = 255 - i; //fade out (ch2) green to get pure red |
262 | nextcolorState = 0; |
280 | nextcolorState = 0; |
263 | break; |
281 | break; |
264 | } |
282 | } |
265 | 283 | ||
266 | 284 | ||
267 | timer = SetDelay(1); |
285 | timer = SetDelay(5); //wait 10ms |
268 | while (!CheckDelay(timer)); |
286 | while (!CheckDelay(timer)); |
269 | } |
287 | } |
270 | 288 | ||
271 | colorState = nextcolorState; |
289 | colorState = nextcolorState; |
- | 290 | ||
272 | timer = SetDelay(3); |
291 | timer = SetDelay(3); //hold pure colors for additional 3ms |
273 | while (!CheckDelay(timer)); |
292 | while (!CheckDelay(timer)); |
274 | 293 | ||
275 | 294 | ||
276 | } |
295 | } |
277 | 296 | ||
278 | 297 | ||
279 | } |
298 | } |
- | 299 | ||
- | 300 | ||
- | 301 | ||
- | 302 | /* |
|
- | 303 | 170 00fa 1F92 push __zero_reg__ |
|
- | 304 | 171 00fc 0F92 push __tmp_reg__ |
|
- | 305 | 172 00fe 0FB6 in __tmp_reg__,__SREG__ |
|
- | 306 | 173 0100 0F92 push __tmp_reg__ |
|
- | 307 | 174 0102 1124 clr __zero_reg__ |
|
- | 308 | 175 0104 2F93 push r18 |
|
- | 309 | 176 0106 3F93 push r19 |
|
- | 310 | 177 0108 8F93 push r24 |
|
- | 311 | 178 010a 9F93 push r25 |
|
- | 312 | 181 010c 38B3 in r19,56-0x20 |
|
- | 313 | 184 010e 22B3 in r18,50-0x20 |
|
- | 314 | 187 0110 8091 0000 lds r24,counter.1797 |
|
- | 315 | 188 0114 8F5F subi r24,lo8(-(1)) |
|
- | 316 | 189 0116 8093 0000 sts counter.1797,r24 |
|
- | 317 | 190 011a 8F3F cpi r24,lo8(-1) |
|
- | 318 | 191 011c 01F4 brne .L15 |
|
- | 319 | 193 011e 3E60 ori r19,lo8(14) |
|
- | 320 | 195 0120 2863 ori r18,lo8(56) |
|
- | 321 | 197 0122 8091 0000 lds r24,ch0 |
|
- | 322 | 198 0126 8093 0000 sts ch0_tmp,r24 |
|
- | 323 | 200 012a 8091 0000 lds r24,ch1 |
|
- | 324 | 201 012e 8093 0000 sts ch1_tmp,r24 |
|
- | 325 | 203 0132 8091 0000 lds r24,ch2 |
|
- | 326 | 204 0136 8093 0000 sts ch2_tmp,r24 |
|
- | 327 | 206 013a 8091 0000 lds r24,ch3 |
|
- | 328 | 207 013e 8093 0000 sts ch3_tmp,r24 |
|
- | 329 | 209 0142 8091 0000 lds r24,ch4 |
|
- | 330 | 210 0146 8093 0000 sts ch4_tmp,r24 |
|
- | 331 | 212 014a 8091 0000 lds r24,ch5 |
|
- | 332 | 213 014e 8093 0000 sts ch5_tmp,r24 |
|
- | 333 | 215 0152 1092 0000 sts counter.1797,__zero_reg__ |
|
- | 334 | 218 0156 8091 0000 lds r24,ch0_tmp |
|
- | 335 | 219 015a 9091 0000 lds r25,counter.1797 |
|
- | 336 | 220 015e 8917 cp r24,r25 |
|
- | 337 | 221 0160 01F4 brne .L17 |
|
- | 338 | 222 0162 377F andi r19,lo8(-9) |
|
- | 339 | 225 0164 8091 0000 lds r24,ch1_tmp |
|
- | 340 | 226 0168 8917 cp r24,r25 |
|
- | 341 | 227 016a 01F4 brne .L19 |
|
- | 342 | 228 016c 3B7F andi r19,lo8(-5) |
|
- | 343 | 231 016e 8091 0000 lds r24,ch2_tmp |
|
- | 344 | 232 0172 8917 cp r24,r25 |
|
- | 345 | 233 0174 01F4 brne .L21 |
|
- | 346 | 234 0176 3D7F andi r19,lo8(-3) |
|
- | 347 | 237 0178 8091 0000 lds r24,ch3_tmp |
|
- | 348 | 238 017c 8917 cp r24,r25 |
|
- | 349 | 239 017e 01F4 brne .L23 |
|
- | 350 | 240 0180 277F andi r18,lo8(-9) |
|
- | 351 | 243 0182 8091 0000 lds r24,ch4_tmp |
|
- | 352 | 244 0186 8917 cp r24,r25 |
|
- | 353 | 245 0188 01F4 brne .L25 |
|
- | 354 | 246 018a 2F7E andi r18,lo8(-17) |
|
- | 355 | 249 018c 8091 0000 lds r24,ch5_tmp |
|
- | 356 | 250 0190 8917 cp r24,r25 |
|
- | 357 | 251 0192 01F4 brne .L27 |
|
- | 358 | 252 0194 2F7D andi r18,lo8(-33) |
|
- | 359 | 255 0196 38BB out 56-0x20,r19 |
|
- | 360 | 257 0198 22BB out 50-0x20,r18 |
|
- | 361 | 259 019a 8091 0000 lds r24,ms1.1798 |
|
- | 362 | 260 019e 8F5F subi r24,lo8(-(1)) |
|
- | 363 | 261 01a0 8093 0000 sts ms1.1798,r24 |
|
- | 364 | 262 01a4 8132 cpi r24,lo8(33) |
|
- | 365 | 263 01a6 01F4 brne .L31 |
|
- | 366 | 265 01a8 1092 0000 sts ms1.1798,__zero_reg__ |
|
- | 367 | 267 01ac 8091 0000 lds r24,TMR1MS |
|
- | 368 | 268 01b0 9091 0000 lds r25,(TMR1MS)+1 |
|
- | 369 | 269 01b4 0196 adiw r24,1 |
|
- | 370 | 270 01b6 9093 0000 sts (TMR1MS)+1,r25 |
|
- | 371 | 271 01ba 8093 0000 sts TMR1MS,r24 |
|
- | 372 | 274 01be 9F91 pop r25 |
|
- | 373 | 275 01c0 8F91 pop r24 |
|
- | 374 | 276 01c2 3F91 pop r19 |
|
- | 375 | 277 01c4 2F91 pop r18 |
|
- | 376 | 278 01c6 0F90 pop __tmp_reg__ |
|
- | 377 | 279 01c8 0FBE out __SREG__,__tmp_reg__ |
|
- | 378 | 280 01ca 0F90 pop __tmp_reg__ |
|
- | 379 | 281 01cc 1F90 pop __zero_reg__ |
|
- | 380 | 282 01ce 1895 reti |
|
- | 381 | */ |