Rev 778 | Rev 791 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 778 | Rev 780 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | // ************************************************************* |
1 | // *************************************************************** |
2 | // ** Spektrum Diversity - use up to 4 satellite receivers ** |
2 | // ** Spektrum Diversity v1.0 - use up to 4 satellite receivers ** |
3 | // ************************************************************* |
3 | // *************************************************************** |
4 | // ** Target: An Atmel ATtiny2313 (RC-Oscillator @ 8 MHz) ** |
4 | // ** Target: An Atmel ATtiny2313 (RC-Oscillator @ 8 MHz) ** |
5 | // ** controls a 74HC151 Multiplexer ** |
5 | // ** controls a 74HC151 Multiplexer ** |
6 | // ************************************************************* |
6 | // *************************************************************** |
7 | // ** It monitors the data from 4 satellite receivers and ** |
7 | // ** It monitors the data from 4 satellite receivers and ** |
8 | // ** connects a valid one to the output via the multiplexer ** |
8 | // ** connects a valid one to the output via the multiplexer ** |
9 | // ************************************************************* |
9 | // *************************************************************** |
10 | // ** LED-Modes during startup (in chronological order) ** |
10 | // ** LED-Modes during startup (in chronological order) ** |
11 | // ** ************************ ** |
11 | // ** ************************ ** |
12 | // ** LED fast blink: Waiting for first datapulse ** |
12 | // ** LED fast blink: Waiting for first datapulse ** |
13 | // ** LED slow blink: Waiting 3 seconds while counting sat's ** |
13 | // ** LED slow blink: Waiting 3 seconds while counting sat's ** |
14 | // ** LED flashes: Indicates the number of active sat's ** |
14 | // ** LED flashes: Indicates the number of active sat's ** |
15 | // ** ** |
15 | // ** ** |
16 | // ** LED-Modes during operation ** |
16 | // ** LED-Modes during operation ** |
17 | // ** ************************** ** |
17 | // ** ************************** ** |
18 | // ** LED OFF: Everything is fine ** |
18 | // ** LED OFF: Everything is fine ** |
19 | // ** LED ON: FAILURE - The first selected sat had lost sync ** |
19 | // ** LED ON: FAILURE - The first selected sat had lost sync ** |
20 | // ** ** |
20 | // ** ** |
21 | // ** LED-Modes during Self-Test ** |
21 | // ** LED-Modes after Self-Test ** |
22 | // ** ************************** ** |
22 | // ** ************************* ** |
23 | // ** LED flashes at 1 Hz: Everything is fine ** |
23 | // ** LED flashes at 1 Hz: Everything is fine ** |
24 | // ** LED flashes some times: FAILURE ** |
24 | // ** LED flashes some times: Times flashed -> damaged Channel# ** |
- | 25 | // ** LED off: check voltage(regulator) or firmware ** |
|
25 | // ************************************************************* |
26 | // *************************************************************** |
26 | // ** (c) 2010-0xFFFF Stefan Pendsa ** |
27 | // ** (c) 2010-0xFFFF Stefan Pendsa ** |
27 | // ** License: don't know - use it and have fun ** |
28 | // ** License: don't know - use it and have fun ** |
28 | // ************************************************************* |
29 | // *************************************************************** |
Line 29... | Line 30... | ||
29 | 30 | ||
30 | #include <avr/io.h> |
31 | #include <avr/io.h> |
31 | #include <avr/interrupt.h> |
32 | #include <avr/interrupt.h> |
Line 32... | Line 33... | ||
32 | #include <util/delay.h> |
33 | #include <util/delay.h> |
33 | 34 | ||
Line 34... | Line 35... | ||
34 | #define LED_OFF PORTD |= 1 << PORTD0 |
35 | #define LED_OFF PORTD |= 1 << PD0 |
Line 45... | Line 46... | ||
45 | 46 | ||
46 | 47 | ||
47 | 48 | ||
- | 49 | void SelectSat(unsigned char sat) |
|
48 | void SelectSat(unsigned char sat) |
50 | { |
Line 49... | Line 51... | ||
49 | { |
51 | PORTD = (PORTD & 0b1100111) | (sat << 3); // Select the input for 74HC151 |
Line 64... | Line 66... | ||
64 | void Binding(void) // Binding sequence for DX7 |
66 | void Binding(void) // Binding sequence for DX7 |
65 | { |
67 | { |
66 | unsigned char i = 0; |
68 | unsigned char i = 0; |
Line 67... | Line 69... | ||
67 | 69 | ||
68 | DDRB = 0b11110000; // Sat-Pins to output |
70 | DDRB = 0b11110000; // Sat-Pins to output |
Line 69... | Line 71... | ||
69 | _delay_ms(80); // Let them boot up |
71 | _delay_ms(80); // Let them time to boot up |
70 | 72 | ||
71 | for (i=0;i<3;i++) // send three negative 100µs pulses to all sat's |
73 | for (i=0;i<3;i++) // send three negative 100µs pulses to all sat's |
72 | { |
74 | { |
Line 89... | Line 91... | ||
89 | 91 | ||
Line 90... | Line 92... | ||
90 | DDRB = 0b11110000; // Port B Output for satellites, Input for feedback |
92 | DDRB = 0b11110000; // Port B Output for satellites, Input for feedback |
91 | 93 | ||
92 | PORTB = 0b01010000; // Test Pattern |
94 | PORTB = 0b01010000; // Test Pattern |
93 | SelectSat(0); |
95 | SelectSat(0); |
94 | if (!(PINB & (1<<PB3))) error++; |
96 | if (!(PINB & (1<<PB3))) error = 1; |
95 | SelectSat(1); |
97 | SelectSat(1); |
96 | if (PINB & (1<<PB3)) error++; |
98 | if (PINB & (1<<PB3)) error = 2; |
97 | SelectSat(2); |
99 | SelectSat(2); |
98 | if (!(PINB & (1<<PB3))) error++; |
100 | if (!(PINB & (1<<PB3))) error = 3; |
Line 99... | Line 101... | ||
99 | SelectSat(3); |
101 | SelectSat(3); |
100 | if (PINB & (1<<PB3)) error++; |
102 | if (PINB & (1<<PB3)) error = 4; |
101 | 103 | ||
102 | PORTB = 0b10100000; // Another (inverted) Test Pattern |
104 | PORTB = 0b10100000; // Another (inverted) Test Pattern |
103 | SelectSat(0); |
105 | SelectSat(0); |
104 | if (PINB & (1<<PB3)) error++; |
106 | if (PINB & (1<<PB3)) error = 1; |
105 | SelectSat(1); |
107 | SelectSat(1); |
106 | if (!(PINB & (1<<PB3))) error++; |
108 | if (!(PINB & (1<<PB3))) error = 2; |
107 | SelectSat(2); |
109 | SelectSat(2); |
Line 108... | Line 110... | ||
108 | if (PINB & (1<<PB3)) error++; |
110 | if (PINB & (1<<PB3)) error = 3; |
Line 109... | Line 111... | ||
109 | SelectSat(3); |
111 | SelectSat(3); |
110 | if (!(PINB & (1<<PB3))) error++; |
112 | if (!(PINB & (1<<PB3))) error = 4; |
Line 120... | Line 122... | ||
120 | LED_OFF; |
122 | LED_OFF; |
121 | _delay_ms(900); |
123 | _delay_ms(900); |
122 | } |
124 | } |
123 | else |
125 | else |
124 | { |
126 | { |
125 | for (i=0;i<error;i++) // When error occured -> Flash once for every error |
127 | for (i=0;i<error;i++) // When error occured -> Flash-Out the Errorcode |
126 | { |
128 | { |
127 | LED_ON; |
129 | LED_ON; |
128 | _delay_ms(100); |
130 | _delay_ms(100); |
129 | LED_OFF; |
131 | LED_OFF; |
130 | _delay_ms(400); |
132 | _delay_ms(400); |
Line 146... | Line 148... | ||
146 | unsigned char sat = 4; |
148 | unsigned char sat = 4; |
Line 147... | Line 149... | ||
147 | 149 | ||
148 | DDRB = 0b00000000; // Port B Input for satellites and feedback |
150 | DDRB = 0b00000000; // Port B Input for satellites and feedback |
149 | DDRD = 0b0011001; // Port D Output for MUX and LED, Input for Switch & Test |
151 | DDRD = 0b0011001; // Port D Output for MUX and LED, Input for Switch & Test |
150 | PORTB = 0b11110000; // Port B Pullup's for (unused) satellites |
152 | PORTB = 0b11110000; // Port B Pullup's for (unused) satellites |
Line 151... | Line 153... | ||
151 | PORTD = 0b1100001; // Port D Pullup's for Switch & Test, LED on |
153 | PORTD = 0b1100001; // Port D Pullup's for Switch & Test, LED off |
Line 152... | Line 154... | ||
152 | 154 | ||
153 | for (i=0;i<4;i++) active[i] = 0; // Reset active-array |
155 | for (i=0;i<4;i++) active[i] = 0; // Reset active-array |
Line -... | Line 156... | ||
- | 156 | ||
- | 157 | if (!(PIND & (1<<PD5))) Testing(); // Initiate Self-Test when Test-Pad is low |
|
154 | 158 | if (!(PIND & (1<<PD6))) Binding(); // Initiate Binding when Bind-Button is pressed |
|
155 | if (!(PIND & (1<<PD5))) Testing(); // Initiate Self-Test when Test-Pad is low |
159 | |
156 | if (!(PIND & (1<<PD6))) Binding(); // Initiate Binding when Bind-Button is pressed |
160 | _delay_ms(100); |
Line 157... | Line 161... | ||
157 | 161 |