Subversion Repositories Projects

Rev

Rev 514 | Go to most recent revision | Details | 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
 
27
volatile uint16_t old_timer1 = 0, ppm = 0;
28
 
29
/**
30
 * init ppm, including timer1 for measurement
31
 */
32
void ppm_init() {
33
        PORTE |= (1 << PORTE0);         // enable pullup on INT0 pin
34
        GICR |= (1<<INT2);                      // External Interrupt Request 2 Enable
35
        EMCUCR |= (1<<ISC2);            // a rising edge on INT2 activates the interrupt
36
        TCCR1B |= (0<<CS12)|(1<<CS10)|(1<<CS11); // timer1 up with prescaler 64
37
}
38
 
39
/**
40
 * Handle INT2 interrupts that occur on changing edges of ppm signal
41
 */
42
ISR(INT2_vect) {
43
        // since the pin might get bogus reads we wait for 123 signals
44
        static uint8_t valid_ppm_to_go = 123;
45
        if (EMCUCR & (1<<ISC2)) { // rising
46
                old_timer1 = TCNT1;
47
                EMCUCR &= ~(1<<ISC2); // next one is falling
48
        } else {               
49
                if (valid_ppm_to_go) {
50
                        valid_ppm_to_go--;
51
                } else {
52
                        ppm = TCNT1 - old_timer1;
53
                        ppm -= 256;
54
                        if (ppm < 128) { // we want HUD
55
                                COSD_FLAGS |= COSD_FLAG_HUD;
56
                        } else { // we do not want hud
57
                                if (COSD_FLAGS & COSD_FLAG_HUD) {
58
                                        clear();
59
                                }
60
                                COSD_FLAGS &= ~COSD_FLAG_HUD;
61
                        }
62
                }
63
                EMCUCR |= (1<<ISC2); // next one is rising
64
        }
65
        //write_ndigit_number_u(2, 2, ppm, 1000, 0); // debug 
66
        //write_ndigit_number_u(2, 3, valid_ppm_to_go, 100, 0); // debug 
67
        //write_ndigit_number_u(2, 4, COSD_FLAGS, 100, 0); // debug 
68
}