Subversion Repositories Projects

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

/*------------------------------------------------------------------------------
** Ident                  : main.h                                            **
** Project                : MX16s 8->10 ppm channel expander                  **
** Author                 : lakeroe                                           **
** Copyright (c)          : 12.2011 lakeroe                                   **
** Original code and idea : Jacques Wanders                                   **
**                          http://forum.mikrokopter.de/topic-4405.html       **
**                          http://forum.mikrokopter.de/topic-4556.html       **
**----------------------------------------------------------------------------**
** Release                : v1.0 initial release                              **
** Date                   : 25-12-2011                                        **
**----------------------------------------------------------------------------**
** The use of this project (hardware, software, binary files, sources and     **
** documentation) is only permittet for non-commercial use                    **
** (directly or indirectly)                                                   **
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"**
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  **
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE **
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE   **
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR        **
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF       **
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS   **
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN    **
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)    **
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE **
** POSSIBILITY OF SUCH DAMAGE.                                                **
------------------------------------------------------------------------------*/


#define CHANNEL_9                                 PORTA3                        // (Pin 10)
#define CHANNEL_10                                PORTA4                        // (Pin 9)
#define PPM_IN                                    PORTA7                        // (Pin 6)
#define PPM_OUT_PIN                               PORTB2                        // (Pin 5)

#define START_PULSE                               400                           // [0.4ms]

#define PPM_PULSE_MIN                             1000                          // [1.0ms]
#define PPM_PULSE_MAX                             2000                          // [2.0ms]

#define MIN_SYNC_TIME                             3000                          // [3.0ms]
#define MAX_SYNC_TIME                             22000                         // total frame time - 8 x min channel frame time = 22ms - 8 x 1ms = 22 - 8

// minimum channel frame = START_PULSE_HIGH + START_PULSE_LOW = 400 + 600 counts = 1000 counts = 1ms
// PPM frame length = 22ms = 22000 counts

#define SET_PPM_OUT_HIGH                          PORTB  |=  (1<<PPM_OUT_PIN)
#define SET_PPM_OUT_LOW                           PORTB  &= ~(1<<PPM_OUT_PIN)

#define FALLING_EDGE_TRIGGER                      TCCR1B &= ~(1<<ICES1)
#define RISING_EDGE_TRIGGER                       TCCR1B |=  (1<<ICES1)

#define SET_COMPARE_COUNTER_TO_ZERO               OCR1A   = 0
#define SET_COUNTER_TO_ZERO                       TCNT1   = 0
#define SET_CAPTURE_COUNTER_TO_ZERO               ICR1    = 0

#define DISABLE_INPUT_CAPTURE                     TIMSK1 &= ~(1<<ICIE1)         // disable input capture
#define ENABLE_INPUT_CAPTURE                      TIMSK1 |=  (1 << ICIE1)       // enable input capture

#define DISABLE_OUTPUT_COMPARE                    TIMSK1 &= ~(1<<OCIE1A)        // disable Output Compare A Match Interrupt
#define ENABLE_OUTPUT_COMPARE                     TIMSK1 |=  (1<<OCIE1A)        // enable Output Compare A Match Interrupt

#define TRIGGER_INPUT_CAPTURE_INTERRUPT           TIFR1  |=  (1<<ICF1)          //
#define CLEAR_INPUT_CAPTURE_INTERRUPT_FLAG        TIFR1  &= ~(1<<ICF1)          // reset ICF flag

#define TRIGGER_INPUT_COMPARE_INTERRUPT           TIFR1  |=  (1<<OCF1A)         //

#define SET_TIMER_TO_COMPA_CTC                    TCCR1B &= ~(1<<WGM13)         // CTC mode for COMPA, prescaler 8 / 8MHz => [1.0us]