Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 476 → Rev 477

/C-OSD/trunk/ppm.c
0,0 → 1,68
/****************************************************************************
* Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje *
* admiralcascade@gmail.com *
* Project-URL: http://www.mylifesucks.de/oss/c-osd/ *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
****************************************************************************/
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include "ppm.h"
#include "main.h"
#include "max7456_software_spi.h" // clearing
 
volatile uint16_t old_timer1 = 0, ppm = 0;
 
/**
* init ppm, including timer1 for measurement
*/
void ppm_init() {
PORTE |= (1 << PORTE0); // enable pullup on INT0 pin
GICR |= (1<<INT2); // External Interrupt Request 2 Enable
EMCUCR |= (1<<ISC2); // a rising edge on INT2 activates the interrupt
TCCR1B |= (0<<CS12)|(1<<CS10)|(1<<CS11); // timer1 up with prescaler 64
}
 
/**
* Handle INT2 interrupts that occur on changing edges of ppm signal
*/
ISR(INT2_vect) {
// since the pin might get bogus reads we wait for 123 signals
static uint8_t valid_ppm_to_go = 123;
if (EMCUCR & (1<<ISC2)) { // rising
old_timer1 = TCNT1;
EMCUCR &= ~(1<<ISC2); // next one is falling
} else {
if (valid_ppm_to_go) {
valid_ppm_to_go--;
} else {
ppm = TCNT1 - old_timer1;
ppm -= 256;
if (ppm < 128) { // we want HUD
COSD_FLAGS |= COSD_FLAG_HUD;
} else { // we do not want hud
if (COSD_FLAGS & COSD_FLAG_HUD) {
clear();
}
COSD_FLAGS &= ~COSD_FLAG_HUD;
}
}
EMCUCR |= (1<<ISC2); // next one is rising
}
//write_ndigit_number_u(2, 2, ppm, 1000, 0); // debug
//write_ndigit_number_u(2, 3, valid_ppm_to_go, 100, 0); // debug
//write_ndigit_number_u(2, 4, COSD_FLAGS, 100, 0); // debug
}