1,5 → 1,5 |
// *************************************************************** |
// ** Spektrum Diversity v1.0 - use up to 4 satellite receivers ** |
// ** Spektrum Diversity v1.3 - use up to 4 satellite receivers ** |
// *************************************************************** |
// ** Target: An Atmel ATtiny2313 (RC-Oscillator @ 8 MHz) ** |
// ** controls a 74HC151 Multiplexer ** |
7,11 → 7,9 |
// ** 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-Modes during startup ** |
// ** ************************ ** |
// ** LED fast blink: Waiting for first datapulse ** |
// ** LED slow blink: Waiting 3 seconds while counting sat's ** |
// ** LED flashes: Indicates the number of active sat's ** |
// ** LED fast flash: Waiting for first datapulse ** |
// ** ** |
// ** LED-Modes during operation ** |
// ** ************************** ** |
18,11 → 16,11 |
// ** LED OFF: Everything is fine ** |
// ** LED ON: FAILURE - The first selected sat had lost sync ** |
// ** ** |
// ** LED-Modes after Self-Test ** |
// ** ************************* ** |
// ** LED-Modes after Self-Test and pressed button ** |
// ** ******************************************** ** |
// ** LED flashes at 1 Hz: Everything is fine ** |
// ** LED flashes some times: Times flashed -> damaged Channel# ** |
// ** LED off: check voltage(regulator) or firmware ** |
// ** LED off: check voltage(regulator), button or firmware ** |
// *************************************************************** |
// ** (c) 2010-0xFFFF Stefan Pendsa ** |
// ** License: don't know - use it and have fun ** |
29,16 → 27,23 |
// *************************************************************** |
|
#include <avr/io.h> |
#include <avr/eeprom.h> |
#include <avr/interrupt.h> |
#include <util/delay.h> |
|
|
#define LED_OFF PORTD |= 1 << PD0 |
#define LED_ON PORTD &= ~(1 << PD0) |
|
volatile unsigned int TimerEvent; |
|
unsigned char eedummy EEMEM; // Dummy-Variable for Address 0 in EEPROM |
unsigned char eecheck EEMEM; // Check-Variable |
unsigned char bind; // Bind-Pulse-Counter (in RAM) |
unsigned char eebind EEMEM; // Bind-Pulse-Counter (in EEPROM) |
|
|
|
ISR(TIMER1_OVF_vect) // Triggered every 8,192 msec |
{ |
TimerEvent++; |
63,7 → 68,7 |
|
|
|
void Binding(void) // Binding sequence for DX7 |
void Binding(void) // Binding sequence |
{ |
unsigned char i = 0; |
|
70,7 → 75,7 |
DDRB = 0b11110000; // Sat-Pins to output |
_delay_ms(80); // Let them time to boot up |
|
for (i=0;i<3;i++) // send three negative 100µs pulses to all sat's |
for (i=0;i<bind;i++) // Send negative 100µs pulses to all sat's |
{ |
PORTB = 0b00000000; |
_delay_us(100); |
78,8 → 83,20 |
_delay_us(100); |
} |
|
_delay_ms(1000); |
DDRB = 0b00000000; // Sat-Pins to input after 1sec |
for (i=0;i<bind;i++) // Flash the number of used pulses to the LED |
{ |
LED_ON; |
_delay_ms(100); |
LED_OFF; |
_delay_ms(250); |
} |
|
DDRB = 0b00000000; // Sat-Pins to input again |
|
bind++; // Save increased bind-pulse-counter for next binding. |
if (bind > 6) bind = 3; // 3 pulses are for DX7+AR6200, 4-6 pulses have been seen... |
eeprom_write_byte(&eebind, bind); // around the world for other combinations. Hopefully it works for them. |
_delay_ms(500); |
} |
|
|
113,6 → 130,8 |
|
DDRB = 0b00000000; // Port B Input again |
|
while (PIND & (1<<PD6)); // Wait for Bind-Switch |
|
while(1) // Never return |
{ |
if (error == 0) // When no error occured -> LED flashes at 1 Hz |
143,9 → 162,8 |
int main(void) |
{ |
unsigned char i = 0; |
unsigned char j = 0; |
unsigned char active[4]; |
unsigned char sat = 4; |
unsigned char sat = 99; |
|
DDRB = 0b00000000; // Port B Input for satellites and feedback |
DDRD = 0b0011001; // Port D Output for MUX and LED, Input for Switch & Test |
154,6 → 172,16 |
|
for (i=0;i<4;i++) active[i] = 0; // Reset active-array |
|
|
if (eeprom_read_byte(&eecheck) != 0x42) // Invalid Data in EEPROM -> initialize |
{ |
eeprom_write_byte(&eecheck, 0x42); |
bind = 3; |
eeprom_write_byte(&eebind, bind); |
} |
else bind = eeprom_read_byte(&eebind); // Valid Data in EEPROM -> read bind-pulse-counter |
|
|
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 |
|
164,7 → 192,7 |
sei(); // Global Interrupts enable |
|
ResetTimer(); |
while((PINB & 0b11110000) == 0b11110000) // Wait for first signal (SYNC to frame) |
while(sat == 99) // Wait for first signal |
{ |
if (TimerEvent == 10) LED_ON; // Blink while waiting... |
if (TimerEvent == 20) |
172,54 → 200,21 |
LED_OFF; |
TimerEvent = 0; |
} |
} |
LED_OFF; |
|
ResetTimer(); |
while(1) // Check active satellites for 5 seconds |
{ |
if (TimerEvent == 20) LED_ON; // Blink (slower) while waiting... |
if (TimerEvent == 40) |
for (i=0;i<4;i++) // Select first active Satellite |
{ |
LED_OFF; |
TimerEvent = 0; |
j++; |
} |
|
for (i=0;i<4;i++) |
{ |
if (!(PINB & (1<<(i+4)))) |
{ |
active[i] = 1; |
if (sat == 4) // Select first active satellite (only once) |
{ |
sat = i; |
SelectSat(i); |
} |
|
sat = i; |
SelectSat(sat); |
break; |
} |
} |
|
if (j == 16) break; // 16 * 40 * 8ms = ~5sec |
} |
|
LED_OFF; |
_delay_ms(1000); |
|
for (i=0;i<4;i++) // Flash once for every active satellite |
{ |
if (active[i] == 1) |
{ |
LED_ON; |
_delay_ms(100); |
LED_OFF; |
_delay_ms(400); |
} |
} |
|
|
|
|
while(1) // Main-Loop |
{ |
for (i=0;i<4;i++) active[i] = 0; // Reset active-array |
233,7 → 228,6 |
ResetTimer(); |
while(TimerEvent < 1) // Check active satellites (for 1*8=8ms) |
{ |
|
for (i=0;i<4;i++) |
{ |
if (!(PINB & (1<<(i+4)))) |
245,7 → 239,6 |
|
if (active[sat] == 0) // Detect fail on active satellite |
{ |
LED_ON; // Failure-LED ON |
for (i=0;i<4;i++) // Select lowest active satellite |
{ |
if (active[i] == 1) |
255,6 → 248,7 |
break; |
} |
} |
LED_ON; // Failure-LED ON |
} |
|
if (!(PIND & (1<<PD6))) LED_OFF; // Reset Failure-LED when Bind-Button is pressed |