Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1398 | - | 1 | /*------------------------------------------------------------------------------ |
2 | ** Ident : main.h ** |
||
3 | ** Project : MX16s 8->10 ppm channel expander ** |
||
4 | ** Author : lakeroe ** |
||
5 | ** Copyright (c) : 12.2011 lakeroe ** |
||
6 | ** Original code and idea : Jacques Wanders ** |
||
7 | ** http://forum.mikrokopter.de/topic-4405.html ** |
||
8 | ** http://forum.mikrokopter.de/topic-4556.html ** |
||
9 | **----------------------------------------------------------------------------** |
||
10 | ** Release : v1.0 initial release ** |
||
11 | ** Date : 25-12-2011 ** |
||
12 | **----------------------------------------------------------------------------** |
||
13 | ** The use of this project (hardware, software, binary files, sources and ** |
||
14 | ** documentation) is only permittet for non-commercial use ** |
||
15 | ** (directly or indirectly) ** |
||
16 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"** |
||
17 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ** |
||
18 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ** |
||
19 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ** |
||
20 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ** |
||
21 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ** |
||
22 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ** |
||
23 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ** |
||
24 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ** |
||
25 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ** |
||
26 | ** POSSIBILITY OF SUCH DAMAGE. ** |
||
27 | ------------------------------------------------------------------------------*/ |
||
28 | |||
29 | #define CHANNEL_9 PORTA3 // (Pin 10) |
||
30 | #define CHANNEL_10 PORTA4 // (Pin 9) |
||
31 | #define PPM_IN PORTA7 // (Pin 6) |
||
32 | #define PPM_OUT_PIN PORTB2 // (Pin 5) |
||
33 | |||
34 | #define START_PULSE 400 // [0.4ms] |
||
35 | |||
36 | #define PPM_PULSE_MIN 1000 // [1.0ms] |
||
37 | #define PPM_PULSE_MAX 2000 // [2.0ms] |
||
38 | |||
39 | #define MIN_SYNC_TIME 3000 // [3.0ms] |
||
40 | #define MAX_SYNC_TIME 22000 // total frame time - 8 x min channel frame time = 22ms - 8 x 1ms = 22 - 8 |
||
41 | |||
42 | // minimum channel frame = START_PULSE_HIGH + START_PULSE_LOW = 400 + 600 counts = 1000 counts = 1ms |
||
43 | // PPM frame length = 22ms = 22000 counts |
||
44 | |||
45 | #define SET_PPM_OUT_HIGH PORTB |= (1<<PPM_OUT_PIN) |
||
46 | #define SET_PPM_OUT_LOW PORTB &= ~(1<<PPM_OUT_PIN) |
||
47 | |||
48 | #define FALLING_EDGE_TRIGGER TCCR1B &= ~(1<<ICES1) |
||
49 | #define RISING_EDGE_TRIGGER TCCR1B |= (1<<ICES1) |
||
50 | |||
51 | #define SET_COMPARE_COUNTER_TO_ZERO OCR1A = 0 |
||
52 | #define SET_COUNTER_TO_ZERO TCNT1 = 0 |
||
53 | #define SET_CAPTURE_COUNTER_TO_ZERO ICR1 = 0 |
||
54 | |||
55 | #define DISABLE_INPUT_CAPTURE TIMSK1 &= ~(1<<ICIE1) // disable input capture |
||
56 | #define ENABLE_INPUT_CAPTURE TIMSK1 |= (1 << ICIE1) // enable input capture |
||
57 | |||
58 | #define DISABLE_OUTPUT_COMPARE TIMSK1 &= ~(1<<OCIE1A) // disable Output Compare A Match Interrupt |
||
59 | #define ENABLE_OUTPUT_COMPARE TIMSK1 |= (1<<OCIE1A) // enable Output Compare A Match Interrupt |
||
60 | |||
61 | #define TRIGGER_INPUT_CAPTURE_INTERRUPT TIFR1 |= (1<<ICF1) // |
||
62 | #define CLEAR_INPUT_CAPTURE_INTERRUPT_FLAG TIFR1 &= ~(1<<ICF1) // reset ICF flag |
||
63 | |||
64 | #define TRIGGER_INPUT_COMPARE_INTERRUPT TIFR1 |= (1<<OCF1A) // |
||
65 | |||
66 | #define SET_TIMER_TO_COMPA_CTC TCCR1B &= ~(1<<WGM13) // CTC mode for COMPA, prescaler 8 / 8MHz => [1.0us] |