Rev 758 | Rev 800 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 758 | Rev 761 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | 30 | ||
31 | /** |
31 | /** |
32 | * init ppm, including timer1 for measurement |
32 | * init ppm, including timer1 for measurement |
33 | */ |
33 | */ |
34 | void ppm_init() { |
34 | void ppm_init() { |
35 | PORTE |= (1 << PORTE0); // enable pullup on INT0 pin |
35 | PORTE |= (1 << PORTE0); // enable pullup on INT0 pin |
36 | GICR |= (1<<INT2); // External Interrupt Request 2 Enable |
36 | GICR |= (1 << INT2); // External Interrupt Request 2 Enable |
37 | EMCUCR |= (1<<ISC2); // a rising edge on INT2 activates the interrupt |
37 | EMCUCR |= (1 << ISC2); // a rising edge on INT2 activates the interrupt |
38 | TCCR1B |= (0<<CS12)|(1<<CS10)|(1<<CS11); // timer1 up with prescaler 64 |
38 | TCCR1B |= (0 << CS12) | (1 << CS10) | (1 << CS11); // timer1 up with prescaler 64 |
Line 39... | Line 39... | ||
39 | } |
39 | } |
40 | 40 | ||
41 | /** |
41 | /** |
42 | * Handle INT2 interrupts that occur on changing edges of ppm signal |
42 | * Handle INT2 interrupts that occur on changing edges of ppm signal |
43 | */ |
43 | */ |
44 | ISR(INT2_vect) { |
44 | ISR(INT2_vect) { |
45 | // since the pin might get bogus reads we wait for 123 signals |
45 | // since the pin might get bogus reads we wait for 123 signals |
46 | static uint8_t valid_ppm_to_go = 123; |
46 | static uint8_t valid_ppm_to_go = 123; |
47 | if (EMCUCR & (1<<ISC2)) { // rising |
47 | if (EMCUCR & (1 << ISC2)) { // rising |
48 | old_timer1 = TCNT1; |
48 | old_timer1 = TCNT1; |
49 | EMCUCR &= ~(1<<ISC2); // next one is falling |
49 | EMCUCR &= ~(1 << ISC2); // next one is falling |
50 | } else { |
50 | } else { |
51 | if (valid_ppm_to_go) { |
51 | if (valid_ppm_to_go) { |
52 | valid_ppm_to_go--; |
52 | valid_ppm_to_go--; |
53 | } else { |
53 | } else { |
54 | ppm = TCNT1 - old_timer1; |
54 | ppm = TCNT1 - old_timer1; |
55 | ppm -= 256; |
55 | ppm -= 256; |
56 | if (ppm < 128) { // we want HUD |
56 | if (ppm < 128) { // we want HUD |
57 | if (!(COSD_FLAGS_MODES & COSD_FLAG_HUD)) { |
57 | if (!(COSD_FLAGS_MODES & COSD_FLAG_HUD)) { |
58 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
58 | COSD_FLAGS_RUNTIME &= ~COSD_ICONS_WRITTEN; |
59 | } |
59 | } |
60 | COSD_FLAGS_MODES |= COSD_FLAG_HUD; |
60 | COSD_FLAGS_MODES |= COSD_FLAG_HUD; |
61 | } else { // we do not want hud |
61 | } else { // we do not want hud |
62 | if (COSD_FLAGS_MODES & COSD_FLAG_HUD) { |
62 | if (COSD_FLAGS_MODES & COSD_FLAG_HUD) { |
63 | clear(); |
63 | clear(); |
64 | } |
64 | } |
65 | COSD_FLAGS_MODES &= ~COSD_FLAG_HUD; |
65 | COSD_FLAGS_MODES &= ~COSD_FLAG_HUD; |
66 | } |
66 | } |
67 | } |
67 | } |
68 | EMCUCR |= (1<<ISC2); // next one is rising |
68 | EMCUCR |= (1 << ISC2); // next one is rising |
69 | } |
69 | } |
70 | //write_ndigit_number_u(2, 5, ppm, 1000, 0); // debug |
70 | //write_ndigit_number_u(2, 5, ppm, 1000, 0); // debug |
71 | //write_ndigit_number_u(2, 6, valid_ppm_to_go, 100, 0); // debug |
71 | //write_ndigit_number_u(2, 6, valid_ppm_to_go, 100, 0); // debug |
72 | //write_ndigit_number_u(2, 7, COSD_FLAGS_CONFIG, 100, 0); // debug |
72 | //write_ndigit_number_u(2, 7, COSD_FLAGS_CONFIG, 100, 0); // debug |
73 | PORTC ^= (1 << PC3); |
73 | PORTC ^= (1 << PC3); |
Line 74... | Line 74... | ||
74 | uptime = ppm; |
74 | uptime = ppm; |