Blame |
Last modification |
View Log
| RSS feed
/*------------------------------------------------------------------------------
** **
** Ident : main.h **
** Project : MX12 3 ppm channel expander **
** Author : J.Wanders **
** modified : 05.2008 Heinrich Fischer for use with WinAVR **
** **
** 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. **
** **
**----------------------------------------------------------------------------*/
#include <avr/io.h>
#include <inttypes.h>
/* CONSTANTS */
#define TRUE 0xFF
#define FALSE 0x00
#define CHANNEL_7_ADC PORTA1 // (pin12)
#define CHANNEL_8_ADC PORTA2 // (pin11)
#define CHANNEL_9_ADC PORTA3 // (pin11)
#define PPM_IN PORTA7 // (pin6)
#define PPM_OUT_PIN PORTB2 // (pin5)
#define ADC_CHANNEL_7 0x01 // ADC1 - PORTA1 (pin12)
#define ADC_CHANNEL_8 0x02 // ADC2 - PORTA2 (pin11)
#define ADC_CHANNEL_9 0x03 // ADC3 - PORTA3 (pin10)
#define ADC_CHANNEL_MASK 0x03
#define START_PULSE_HIGH 400 // [0.4ms]
#define START_PULSE_LOW 600 // [0.6ms]
//#define FORCE_LOW_END_FRAME 2100 // [2.1ms]
//#define MIN_SYNC_TIME 2400 // [2.4ms]
//NEW definition in main.h
#define FORCE_LOW_END_FRAME 500 // [0,5ms]
#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
/**** MACROS ******************************************************************/
#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_ICP_CTC TCCR1B |= (1<<WGM13) // CTC mode for ICP, prescaler 8 / 8MHz => [1.0us]
#define SET_TIMER_TO_COMPA_CTC TCCR1B &= ~(1<<WGM13) // CTC mode for COMPA, prescaler 8 / 8MHz => [1.0us]
// clear ADC enable & ADC Start Conversion & ADC Interrupt Enable bit
#define ADC_DISABLE ADCSRA &= ~((1<<ADEN)|(1<<ADSC)|(1<<ADIE))
// set ADC enable & ADC Start Conversion & ADC Interrupt Enable bit
#define ADC_ENABLE ADCSRA |= (1<<ADEN)|(1<<ADSC)|(1<<ADIE)
/**** END MACROS *****************************************************************************/
//#define cli() __disable_interrupt()
//#define sei() __enable_interrupt()