Rev 477 | Rev 528 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
477 | cascade | 1 | /**************************************************************************** |
2 | * Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje * |
||
3 | * admiralcascade@gmail.com * |
||
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
||
5 | * * |
||
6 | * This program is free software; you can redistribute it and/or modify * |
||
7 | * it under the terms of the GNU General Public License as published by * |
||
8 | * the Free Software Foundation; either version 2 of the License. * |
||
9 | * * |
||
10 | * This program is distributed in the hope that it will be useful, * |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
13 | * GNU General Public License for more details. * |
||
14 | * * |
||
15 | * You should have received a copy of the GNU General Public License * |
||
16 | * along with this program; if not, write to the * |
||
17 | * Free Software Foundation, Inc., * |
||
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
19 | ****************************************************************************/ |
||
20 | |||
21 | #include <avr/io.h> |
||
22 | #include <avr/interrupt.h> |
||
23 | #include "ppm.h" |
||
24 | #include "main.h" |
||
25 | #include "max7456_software_spi.h" // clearing |
||
26 | |||
514 | cascade | 27 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
28 | |||
477 | cascade | 29 | volatile uint16_t old_timer1 = 0, ppm = 0; |
30 | |||
31 | /** |
||
32 | * init ppm, including timer1 for measurement |
||
33 | */ |
||
34 | void ppm_init() { |
||
35 | PORTE |= (1 << PORTE0); // enable pullup on INT0 pin |
||
36 | GICR |= (1<<INT2); // External Interrupt Request 2 Enable |
||
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 |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Handle INT2 interrupts that occur on changing edges of ppm signal |
||
43 | */ |
||
44 | ISR(INT2_vect) { |
||
45 | // since the pin might get bogus reads we wait for 123 signals |
||
46 | static uint8_t valid_ppm_to_go = 123; |
||
47 | if (EMCUCR & (1<<ISC2)) { // rising |
||
48 | old_timer1 = TCNT1; |
||
49 | EMCUCR &= ~(1<<ISC2); // next one is falling |
||
50 | } else { |
||
51 | if (valid_ppm_to_go) { |
||
52 | valid_ppm_to_go--; |
||
53 | } else { |
||
54 | ppm = TCNT1 - old_timer1; |
||
55 | ppm -= 256; |
||
56 | if (ppm < 128) { // we want HUD |
||
57 | COSD_FLAGS |= COSD_FLAG_HUD; |
||
58 | } else { // we do not want hud |
||
59 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
||
60 | clear(); |
||
61 | } |
||
62 | COSD_FLAGS &= ~COSD_FLAG_HUD; |
||
63 | } |
||
64 | } |
||
65 | EMCUCR |= (1<<ISC2); // next one is rising |
||
66 | } |
||
67 | //write_ndigit_number_u(2, 2, ppm, 1000, 0); // debug |
||
68 | //write_ndigit_number_u(2, 3, valid_ppm_to_go, 100, 0); // debug |
||
69 | //write_ndigit_number_u(2, 4, COSD_FLAGS, 100, 0); // debug |
||
70 | } |
||
514 | cascade | 71 | |
72 | #endif |