Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 780 → Rev 779

/Spektrum-Diversity/Software/diversity.c
1,12 → 1,12
// ***************************************************************
// ** Spektrum Diversity v1.0 - use up to 4 satellite receivers **
// ***************************************************************
// *************************************************************
// ** Spektrum Diversity - use up to 4 satellite receivers **
// *************************************************************
// ** Target: An Atmel ATtiny2313 (RC-Oscillator @ 8 MHz) **
// ** controls a 74HC151 Multiplexer **
// ***************************************************************
// *************************************************************
// ** It monitors the data from 4 satellite receivers and **
// ** connects a valid one to the output via the multiplexer **
// ***************************************************************
// *************************************************************
// ** LED-Modes during startup (in chronological order) **
// ** ************************ **
// ** LED fast blink: Waiting for first datapulse **
18,22 → 18,21
// ** LED OFF: Everything is fine **
// ** LED ON: FAILURE - The first selected sat had lost sync **
// ** **
// ** LED-Modes after Self-Test **
// ** ************************* **
// ** LED-Modes during Self-Test **
// ** ************************** **
// ** LED flashes at 1 Hz: Everything is fine **
// ** LED flashes some times: Times flashed -> damaged Channel# **
// ** LED off: check voltage(regulator) or firmware **
// ***************************************************************
// ** LED flashes some times: FAILURE **
// *************************************************************
// ** (c) 2010-0xFFFF Stefan Pendsa **
// ** License: don't know - use it and have fun **
// ***************************************************************
// *************************************************************
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
 
#define LED_OFF PORTD |= 1 << PD0
#define LED_ON PORTD &= ~(1 << PD0)
#define LED_OFF PORTD |= 1 << PORTD0
#define LED_ON PORTD &= ~(1 << PORTD0)
 
volatile unsigned int TimerEvent;
 
48,8 → 47,7
 
void SelectSat(unsigned char sat)
{
PORTD = (PORTD & 0b1100111) | (sat << 3); // Select the input for 74HC151
_delay_us(10); // Wait for stable state
PORTD = (PORTD & 0b00000001) | (sat<<3); // Select the Input for 74HC151
}
 
 
68,7 → 66,7
unsigned char i = 0;
 
DDRB = 0b11110000; // Sat-Pins to output
_delay_ms(80); // Let them time to boot up
_delay_ms(80); // Let them boot up
for (i=0;i<3;i++) // send three negative 100µs pulses to all sat's
{
93,23 → 91,23
 
PORTB = 0b01010000; // Test Pattern
SelectSat(0);
if (!(PINB & (1<<PB3))) error = 1;
if (!(PINB & (1<<PB3))) error++;
SelectSat(1);
if (PINB & (1<<PB3)) error = 2;
if (PINB & (1<<PB3)) error++;
SelectSat(2);
if (!(PINB & (1<<PB3))) error = 3;
if (!(PINB & (1<<PB3))) error++;
SelectSat(3);
if (PINB & (1<<PB3)) error = 4;
if (PINB & (1<<PB3)) error++;
 
PORTB = 0b10100000; // Another (inverted) Test Pattern
SelectSat(0);
if (PINB & (1<<PB3)) error = 1;
if (PINB & (1<<PB3)) error++;
SelectSat(1);
if (!(PINB & (1<<PB3))) error = 2;
if (!(PINB & (1<<PB3))) error++;
SelectSat(2);
if (PINB & (1<<PB3)) error = 3;
if (PINB & (1<<PB3)) error++;
SelectSat(3);
if (!(PINB & (1<<PB3))) error = 4;
if (!(PINB & (1<<PB3))) error++;
 
DDRB = 0b00000000; // Port B Input again
 
124,7 → 122,7
}
else
{
for (i=0;i<error;i++) // When error occured -> Flash-Out the Errorcode
for (i=0;i<error;i++) // When error occured -> Flash once for every error
{
LED_ON;
_delay_ms(100);
150,7 → 148,7
DDRB = 0b00000000; // Port B Input for satellites and feedback
DDRD = 0b0011001; // Port D Output for MUX and LED, Input for Switch & Test
PORTB = 0b11110000; // Port B Pullup's for (unused) satellites
PORTD = 0b1100001; // Port D Pullup's for Switch & Test, LED off
PORTD = 0b1100001; // Port D Pullup's for Switch & Test, LED on
 
for (i=0;i<4;i++) active[i] = 0; // Reset active-array
 
157,8 → 155,6
if (!(PIND & (1<<PD5))) Testing(); // Initiate Self-Test when Test-Pad is low
if (!(PIND & (1<<PD6))) Binding(); // Initiate Binding when Bind-Button is pressed
 
_delay_ms(100);
 
TCCR1B = ( 1 << CS10 ); // Timer1 Prescaler = 1 -> 8,192 msec
TIMSK = ( 1 << TOIE1 ); // Timer1 Overflow Interrupt Enable
sei(); // Global Interrupts enable