Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1398 → Rev 1397

/RC-Expander/branches/MX16s_10Ch_V1.0/main.h
File deleted
\ No newline at end of file
/RC-Expander/branches/MX16s_10Ch_V1.0/_make.bat
File deleted
\ No newline at end of file
/RC-Expander/branches/MX16s_10Ch_V1.0/main.c
File deleted
/RC-Expander/branches/MX16s_10Ch_V1.0/main.hex
File deleted
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/main.h
New file
0,0 → 1,101
/*------------------------------------------------------------------------------
** **
** 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()
 
 
 
 
 
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/MX12-Erweiterung.pnproj
New file
0,0 → 1,0
<Project name="MX12-Erweiterung"><File path="main.c"></File><File path="main.h"></File><File path="makefile"></File></Project>
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/makefile
New file
0,0 → 1,381
#--------------------------------------------------------------------
# MCU name
MCU = attiny24
F_CPU = 8000000
#-------------------------------------------------------------------
VERSION_MAJOR = 1
VERSION_MINOR = 3
VERSION_INDEX = 0
#-------------------------------------------------------------------
#OPTIONS
#-
#-------------------------------------------------------------------
 
ifeq ($(F_CPU), 8000000)
QUARZ = 8MHZ
endif
 
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
 
# Target file name (without extension).
 
ifeq ($(VERSION_INDEX), 0)
TARGET = MX12_extender_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)
endif
 
 
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
 
##########################################################################################################
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c
#SRC += < add more soure files>
 
##########################################################################################################
 
 
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
 
 
 
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS =
 
 
# Optional compiler flags.
# -g: generate debugging information (for GDB, or for COFF conversion)
# -O*: optimization level
# -f...: tuning, see gcc manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create assembler listing
CFLAGS = -O$(OPT) \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-Wall -Wstrict-prototypes \
-Wa,-adhlns=$(<:.c=.lst) \
$(patsubst %,-I%,$(EXTRAINCDIRS))
 
 
# Set a "language standard" compiler flag.
# Unremark just one line below to set the language standard to use.
# gnu99 = C99 + GNU extensions. See GCC manual for more information.
#CFLAGS += -std=c89
#CFLAGS += -std=gnu89
#CFLAGS += -std=c99
CFLAGS += -std=gnu99
 
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_INDEX=$(VERSION_INDEX)
 
 
# Optional assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
 
 
 
# Optional linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
 
# Additional libraries
 
# Minimalistic printf version
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
 
# Floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
 
# -lm = math library
LDFLAGS += -lm
 
 
##LDFLAGS += -T./linkerfile/avr5.x
 
 
 
# Programming support using avrdude. Settings and variables.
 
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
#AVRDUDE_PROGRAMMER = dt006
#AVRDUDE_PROGRAMMER = stk200
#AVRDUDE_PROGRAMMER = ponyser
AVRDUDE_PROGRAMMER = avrisp2
#falls Ponyser ausgewählt wird, muss sich unsere avrdude-Configdatei im Bin-Verzeichnis des Compilers befinden
 
#AVRDUDE_PORT = com1 # programmer connected to serial device
#AVRDUDE_PORT = lpt1 # programmer connected to parallel port
AVRDUDE_PORT = com1
 
#AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_SETTINGS)
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
 
#avrdude -c avrispv2 -P usb -p m32 -U flash:w:blink.hex
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
 
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE += -y
 
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
AVRDUDE_FLAGS += -V
 
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_FLAGS += -v -v
 
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = c:/userprog/WinAVR-20070525
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
 
 
# Define programs and commands.
SHELL = sh
 
CC = avr-gcc
 
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
 
# Programming support using avrdude.
AVRDUDE = avrdude
 
REMOVE = rm -f
COPY = cp
 
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
 
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
 
 
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
 
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
 
# Combine all necessary flags and optional flags.
# Add target processor to flags.
#ALL_CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. $(CFLAGS)
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
 
 
# Default target.
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
$(TARGET).lss $(TARGET).sym sizeafter finished end
 
 
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
 
finished:
@echo $(MSG_ERRORS_NONE)
 
end:
@echo $(MSG_END)
@echo
 
 
# Display size of file.
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
 
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
 
 
 
# Display compiler version information.
gccversion :
@$(CC) --version
 
 
# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
 
 
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
 
 
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
 
 
 
 
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
 
 
 
 
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
 
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
 
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
 
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
avr-nm -n $< > $@
 
 
 
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
 
 
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
 
 
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
 
 
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
 
 
 
 
 
 
# Target: clean project.
clean: begin clean_list finished end
 
clean_list :
@echo
@echo $(MSG_CLEANING)
# $(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
 
 
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
 
 
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
 
 
 
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
clean clean_list program
 
 
 
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/MX12_extender__V1_3.hex
New file
0,0 → 1,64
:1000000010C028C027C026C025C04DC0E7C022C0F0
:1000100021C020C01FC01EC01DC063C11BC01AC0AC
:1000200019C011241FBECFEDCDBF10E0A0E6B0E097
:10003000ECEDF3E002C005900D92A636B107D9F7BA
:1000400010E0A6E6B0E001C01D92AA36B107E1F7C4
:100050009FD1C2C1D5CFD798DF9ABA9AC298D1980A
:10006000D998D298DA98D398DB980895F89481B10A
:10007000866081B917B881E086B913B886B1886CFB
:1000800086B978940895F8941FBC8AE08EBD5D9877
:100090001DBC1CBC1BBC1ABC659A61988EB58064E3
:1000A0008EBD789408951F920F920FB60F9211246F
:1000B0002F933F938F939F93F894809167008330A1
:1000C00009F451C0843028F4813029F18230A0F540
:1000D0000AC08D3009F45EC08E3009F463C08430EC
:1000E00009F068C048C024B535B51DBC1CBC8EB530
:1000F0008F7B8EBD285B3B4029533A4448F4C29A1B
:1001000083E08093670010926600109269005CC0E3
:10011000C29881E025C0909169009F5F909369002B
:10012000C2981DBC1CBC15BC14BC8EB580648EBDB1
:100130009B3008F447C034C01DBC1CBCC29A8EB5AD
:100140008F7B8EBD809166008F5F809366008630C6
:1001500030F084E0809367001092660035C083E041
:100160008093670031C01DBC1CBCC2988EB58064F2
:100170008EBD82E0F5CF1DBC1CBCC2988EB58F7EB3
:100180008EBD6598619A88E592E09BBD8ABD599ABB
:1001900085E0E6CF1DBC1CBCC2988EB580648EBDC8
:1001A0008EE0DECF1DBC1CBCC29A8EB58F7B8EBD8F
:1001B0008DE0D6CFC2981DBC1CBC15BC14BC8EB53E
:1001C00080648EBD1092670078949F918F913F91CB
:1001D0002F910F900FBE0F901F9018951F920F92A6
:1001E0000FB60F9211248F939F93F894809167001C
:1001F0008830B1F1893040F48630D1F0873018F57D
:10020000853009F055C009C08A3009F43FC08A30F2
:1002100080F18B3009F04CC042C0C2981DBC1CBCA0
:1002200080916000909161009BBD8ABD86E008C00E
:10023000C29A1DBC1CBC80E991E09BBD8ABD87E0D1
:100240008093670046C0C2981DBC1CBC80916200B0
:1002500090916300885A9D4F9BBD8ABD88E0F0CF86
:10026000C29A1DBC1CBC80E991E09BBD8ABD89E09F
:10027000E7CFC2981DBC1CBC8091640090916500C2
:10028000885A9D4F9BBD8ABD8AE0DACFC29A1DBCB9
:100290001CBC80E991E09BBD8ABD8BE0D1CFC298A8
:1002A0001DBC1CBC84EF91E09BBD8ABD8CE0C8CF17
:1002B0008EB580648EBD6198659A8EB58F7E8EBD39
:1002C0001DBC1CBC1BBC1ABC15BC14BC1092670026
:1002D0005D9A78949F918F910F900FBE0F901F9011
:1002E00018951F920F920FB60F9211242F933F93E0
:1002F0008F939F9386B1877386B924B135B183E01C
:10030000293E380710F028EE33E087B18C7F87B99B
:1003100080916800813031F4309361002093600057
:1003200082E00DC0823031F430936300209362008C
:1003300083E005C0309365002093640081E08093E2
:10034000680087B190916800892B87B986B1886C65
:1003500086B99F918F913F912F910F900FBE0F9073
:100360001F90189580916000909161008F5F9F4F62
:10037000C9F380916200909163008F5F9F4F91F36A
:1003800080916400909165008F5F9F4F59F30895AD
:1003900062DEF89481B1866081B917B881E086B9D0
:1003A00013B886B1886C86B978948091600090917A
:1003B00061008F5F9F4FC9F380916200909163004D
:1003C0008F5F9F4F91F380916400909165008F5FE4
:0C03D0009F4F59F358DEFFCFF894FFCF89
:0603DC00FFFFFFFFFFFF21
:00000001FF
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/MX12-Erweiterung.pnps
New file
0,0 → 1,0
<pd><ViewState><e p="MX12-Erweiterung" x="true"></e></ViewState></pd>
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/main.c
New file
0,0 → 1,429
/*------------------------------------------------------------------------------
** **
** Ident : main.c **
** Project : MX12 2 (3) ppm channel expander **
** Author : Jacques Wanders **
** Description : main module **
** Copyright (c): 05.2008 Jacques Wanders **
** modified : 05.2008 Heinrich Fischer for use with WinAVR **
** **
**----------------------------------------------------------------------------**
** Release : v1.0 initial release **
** Date : 13-05-2008 **
**----------------------------------------------------------------------------**
** Release : v1.1 **
** Date : 13-05-2008 **
** Notes : Added Channel 9 **
**----------------------------------------------------------------------------**
** Release : v1.2 **
** Date : 22-05-2008 **
** Notes : Modified time definitions for FORCE_LOW_END_FRAME **
** and MIN_SYNC_TIME to avoid lost pulse groups **
**----------------------------------------------------------------------------**
** Release : v1.3 **
** Date : 14-08-2008 **
** Notes : Pass thrue for PCM mode **
** Detects a NON-PPM signal, enables endless passthrue mode **
**----------------------------------------------------------------------------**
** 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 ENABLE_BIT_DEFINITIONS
//#include <ioavr.h>
//#include <inavr.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "main.h"
 
 
enum{
stPPM_SYNC,
stPPM_SYNC_WAIT,
stPPM_CHANNEL_START,
stPPM_CHANNEL_DATA,
stPPM_CHANNEL_7_DATA_TRIGGER,
stPPM_CHANNEL_7_DATA,
stPPM_CHANNEL_8_START,
stPPM_CHANNEL_8_DATA,
stPPM_CHANNEL_9_START,
stPPM_CHANNEL_9_DATA,
stPPM_FINISH_PULSE,
stPPM_FINISH_FRAME,
stPPM_FRAME_END,
stPCM_MODE_PULSE_LOW,
stPCM_MODE_PULSE_HIGH,
};
 
unsigned char channel_number = 0;
unsigned char ppm_state = stPPM_SYNC;
unsigned char adc_channel = 0;
unsigned char sync_retry_count = 0;
volatile unsigned int channel_7 = 0xffff; // set to max. for testing if conversion is valid
volatile unsigned int channel_8 = 0xffff; // set to max. for testing if conversion is valid
volatile unsigned int channel_9 = 0xffff; // set to max. for testing if conversion is valid
 
 
/*------------------------------------------------------------------------------
** **
** function : init_pin(void) **
** purpose : Initialise I/O pins **
** **
**----------------------------------------------------------------------------*/
void init_pin(void)
{
 
DDRA &= ~(1<<PPM_IN); // set Input Capture Pin as input
PORTA |= (1<<PPM_IN); // enable pullup
 
DDRB |= (1<<PPM_OUT_PIN); // configure PPM_OUT pin as output
SET_PPM_OUT_LOW; // set low
 
DDRA &= ~(1 << CHANNEL_7_ADC); // Channel 7 (pin12) input
PORTA &= ~(1 << CHANNEL_7_ADC); // disable pullup
 
DDRA &= ~(1 << CHANNEL_8_ADC); // Channel 8 (pin11) input
PORTA &= ~(1 << CHANNEL_8_ADC); // disable pullup
 
DDRA &= ~(1 << CHANNEL_9_ADC); // Channel 8 (pin11) input
PORTA &= ~(1 << CHANNEL_9_ADC); // disable pullup
 
}
/*-init_pin-------------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : init_adc(void) **
** purpose : Initialise ADC registers **
** **
**----------------------------------------------------------------------------*/
void init_adc(void)
{
 
cli(); // disable interrupts
 
DIDR0 |= ((1<<ADC2D)|(1<<ADC1D)); // digital input disable for pin 11 and 12
ADMUX = 0x00; // VCC as reference voltage, select channel 0
ADCSRA = (1 << ADPS2) | (1 << ADPS1)|| (0 << ADPS0); // 8.0 [Mhz] / 128 = 62,5 [kHz]
ADCSRB = 0x00; // free running mode
 
ADC_ENABLE;
 
sei(); // enable interrupts
}
/*-init_adc-------------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : init_timer1(void) **
** purpose : Initialise timer0 **
** Note(s) : Frequency : 8.0 [Mhz] **
** 8 / 8.0 Mhz : 1.00 [us] **
** **
**----------------------------------------------------------------------------*/
void init_timer1(void)
{
cli(); // disable interrupts
 
TCCR1A = ((0<<WGM11)|(0<<WGM10)); // CTC mode
TCCR1B = ((0<<WGM13)|(1<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10)); // CTC mode for COMPA, prescaler 8 / 8MHz => [1.0us]
 
CLEAR_INPUT_CAPTURE_INTERRUPT_FLAG; // reset ICF flag
 
SET_COUNTER_TO_ZERO;
SET_COMPARE_COUNTER_TO_ZERO;
ENABLE_INPUT_CAPTURE;
DISABLE_OUTPUT_COMPARE;
RISING_EDGE_TRIGGER;
 
sei(); // enable interrupts
}
/*-init_timer1----------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : timer1_capture_interrupt(void) **
** purpose : Synchronise PPM frame and copy input events to PPM_OUT, **
** start mixing Ch7, 8 and 9 data when detect start pulse of Ch7 **
** **
**----------------------------------------------------------------------------*/
//#pragma vector=TIM1_CAPT_vect
//static __nested __interrupt void timer1_capture_interrupt (void)
ISR(TIMER1_CAPT_vect)
{
cli(); // disable interrupts
unsigned int data;
 
switch (ppm_state)
{
case stPPM_SYNC: // detect rising edge pulse
data = ICR1; // get timer value after input capture
SET_COUNTER_TO_ZERO;
FALLING_EDGE_TRIGGER;
if(data >= MIN_SYNC_TIME && data <= MAX_SYNC_TIME) // valid sync trigger
{
SET_PPM_OUT_HIGH;
ppm_state = stPPM_CHANNEL_DATA; // next state: get data
channel_number = 0;
sync_retry_count = 0; // when valid data, reset sync retry counter (v1.3)
}
else // trigger but not a valid sync time
{
SET_PPM_OUT_LOW;
ppm_state = stPPM_SYNC_WAIT; // next state: wait for next sync event
}
break;
 
case stPPM_SYNC_WAIT:
sync_retry_count++; // count number of retry's (v1.3)
SET_PPM_OUT_LOW; // not nessecery, output should already be low
SET_COUNTER_TO_ZERO;
SET_CAPTURE_COUNTER_TO_ZERO;
RISING_EDGE_TRIGGER;
if(sync_retry_count > 10) // 10x retry is to much, no PPM (v1.3)
ppm_state = stPCM_MODE_PULSE_HIGH; // set to mode PCM pass thrue (v1.3)
else // (v1.3)
ppm_state = stPPM_SYNC; // next state: try again for new sync
break;
 
case stPPM_CHANNEL_START: // detect rising edge pulse
SET_COUNTER_TO_ZERO;
SET_PPM_OUT_HIGH;
FALLING_EDGE_TRIGGER;
channel_number++; // prepare for next MX12 channel clock
if(channel_number>5) // all six channels read
{
ppm_state = stPPM_CHANNEL_7_DATA_TRIGGER; // 7th. channel but now self created
channel_number = 0;
}
else
ppm_state = stPPM_CHANNEL_DATA;
break;
 
case stPPM_CHANNEL_DATA: // detect falling edge pulse
SET_COUNTER_TO_ZERO;
SET_PPM_OUT_LOW;
RISING_EDGE_TRIGGER;
ppm_state = stPPM_CHANNEL_START; // wait for next channel rising edge pulse
break;
 
case stPPM_CHANNEL_7_DATA_TRIGGER: // detect rising edge pulse
SET_COUNTER_TO_ZERO;
SET_PPM_OUT_LOW;
SET_TIMER_TO_COMPA_CTC;
DISABLE_INPUT_CAPTURE;
ENABLE_OUTPUT_COMPARE;
OCR1A = START_PULSE_LOW; // startpulse length 0.3ms
TRIGGER_INPUT_COMPARE_INTERRUPT;
ppm_state = stPPM_CHANNEL_7_DATA;
break;
 
case stPCM_MODE_PULSE_LOW: // detect falling edge pulse (v1.3)
SET_COUNTER_TO_ZERO; // prevent overflow interrupt
SET_PPM_OUT_LOW;
RISING_EDGE_TRIGGER;
ppm_state = stPCM_MODE_PULSE_HIGH;
break;
 
case stPCM_MODE_PULSE_HIGH: // detect rising edge pulse (v1.3)
SET_COUNTER_TO_ZERO; // prevent overflow interrupt
SET_PPM_OUT_HIGH;
FALLING_EDGE_TRIGGER;
ppm_state = stPCM_MODE_PULSE_LOW;
break;
 
default:
SET_PPM_OUT_LOW; // not nessecery, output should already be low
SET_COUNTER_TO_ZERO;
SET_CAPTURE_COUNTER_TO_ZERO;
RISING_EDGE_TRIGGER;
ppm_state = stPPM_SYNC; // next state: try again for new sync
break;
 
}
sei();
}
/*-timer1_capture_interrupt---------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : timer1_compare_interrupt(void) **
** purpose : Mixing channel 7, 8 and 9 data into ppm out, **
** start input capture for frame synchronisation **
** **
**----------------------------------------------------------------------------*/
//#pragma vector=TIM1_COMPA_vect
//__interrupt void timer1_compare_interrupt (void)
ISR(TIM1_COMPA_vect)
{
cli();
switch (ppm_state)
{
case stPPM_CHANNEL_7_DATA: // create 7th channel data
SET_PPM_OUT_LOW;
SET_COUNTER_TO_ZERO;
OCR1A = channel_7; // COMPA: 0,7ms + channel 7 ADC value
ppm_state = stPPM_CHANNEL_8_START; // next State
break;
 
case stPPM_CHANNEL_8_START: // create 8th channel start pulse
SET_PPM_OUT_HIGH;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_HIGH; // startpulse length 0.3ms
ppm_state = stPPM_CHANNEL_8_DATA; // next State
break;
 
case stPPM_CHANNEL_8_DATA: // create 8th channel data
SET_PPM_OUT_LOW;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_LOW + channel_8; // COMPA: 0,7ms + channel 7 ADC value
ppm_state = stPPM_CHANNEL_9_START; // next State
break;
 
case stPPM_CHANNEL_9_START: // create 8th channel start pulse
SET_PPM_OUT_HIGH;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_HIGH; // startpulse length 0.3ms
ppm_state = stPPM_CHANNEL_9_DATA; // next State
break;
 
case stPPM_CHANNEL_9_DATA: // create 8th channel data
SET_PPM_OUT_LOW;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_LOW + channel_9; // COMPA: 0,7ms + channel 7 ADC value
ppm_state = stPPM_FINISH_PULSE; // next State
break;
 
case stPPM_FINISH_PULSE: // create last pulse
SET_PPM_OUT_HIGH;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_HIGH; // startpulse length 0.3ms
ppm_state = stPPM_FINISH_FRAME; // next State
break;
 
case stPPM_FINISH_FRAME: // create extra low pulse for masking PPM_IN data of channel 7 and 8
SET_PPM_OUT_LOW;
SET_COUNTER_TO_ZERO;
OCR1A = FORCE_LOW_END_FRAME; // keep last end low; 2 channels max - 2 channels min => 2x2ms - 2x1ms + extra length = 2 ms + 1 ms = 3ms => 3000 ticks
ppm_state = stPPM_FRAME_END; // next State
break;
 
case stPPM_FRAME_END:
default:
RISING_EDGE_TRIGGER;
DISABLE_OUTPUT_COMPARE;
ENABLE_INPUT_CAPTURE;
SET_TIMER_TO_COMPA_CTC;
SET_COUNTER_TO_ZERO;
SET_COMPARE_COUNTER_TO_ZERO;
SET_CAPTURE_COUNTER_TO_ZERO;
ppm_state = stPPM_SYNC; // next State
TRIGGER_INPUT_CAPTURE_INTERRUPT;
break;
 
}
sei();
}
/*-timer1_compare_interrupt---------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : adc_server(void) **
** purpose : Handle Analog conversion of RC channel 7, 8 and 9 **
** **
**----------------------------------------------------------------------------*/
//#pragma vector=ADC_vect
//__interrupt void adc_server(void)
ISR(ADC_vect)
{
unsigned int AdcResult;
 
ADC_DISABLE;
 
AdcResult = ADC;
if(AdcResult > 1000) // limit conversion value
AdcResult = 1000; // 1000 => 1ms
 
ADMUX &= ~(ADC_CHANNEL_MASK); // clear channel select bits
 
if(adc_channel == ADC_CHANNEL_7)
{
channel_7 = AdcResult; // set channel 7 value;
adc_channel = ADC_CHANNEL_8; // set next event for channel 8 conversion
}
else if(adc_channel == ADC_CHANNEL_8)
{
channel_8 = AdcResult; // set channel 8 value;
adc_channel = ADC_CHANNEL_9; // set next event for channel 9 conversion
}
else
{
channel_9 = AdcResult; // set channel 9 value;
adc_channel = ADC_CHANNEL_7; // set next event for channel 7 conversion
}
 
ADMUX |= adc_channel; // select new conversion channel
 
ADC_ENABLE;
}
/*-adc_server-----------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : check_valid_adc_value(void) **
** purpose : wait until 3 ADC channels are processed at least once **
** before init Input Capture/Timer1 **
** **
**----------------------------------------------------------------------------*/
void check_valid_adc_value (void)
{
unsigned char exit = FALSE;
 
do
{
if(channel_7 < 0xffff && channel_8 < 0xffff && channel_9 < 0xffff) // All three channels must be processed
exit = TRUE;
 
}while (!exit);
}
/*-check_valid_adc_value------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : main(void) **
** **
**----------------------------------------------------------------------------*/
int main(void)
{
 
init_pin();
init_adc();
check_valid_adc_value(); // wait until both ADC channels are processed at least once
init_timer1();
 
while(1)
{}
}
 
/*-main-----------------------------------------------------------------------*/
 
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/MX12-Erweiterung.pnproj
New file
0,0 → 1,0
<Project name="MX12-Erweiterung"><File path="main.c"></File><File path="main.h"></File><File path="makefile"></File></Project>
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/makefile
New file
0,0 → 1,379
#--------------------------------------------------------------------
# MCU name
MCU = attiny24
F_CPU = 8000000
#-------------------------------------------------------------------
VERSION_MAJOR = 1
VERSION_MINOR = 2
VERSION_INDEX = 0
#-------------------------------------------------------------------
#OPTIONS
#-
#-------------------------------------------------------------------
 
ifeq ($(F_CPU), 8000000)
QUARZ = 8MHZ
endif
 
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
 
# Target file name (without extension).
 
ifeq ($(VERSION_INDEX), 0)
TARGET = MX12_expander_$(HEX_NAME)_V$(VERSION_MAJOR)_$(VERSION_MINOR)sp
endif
 
 
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
 
##########################################################################################################
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c
#SRC += < add more soure files>
 
##########################################################################################################
 
 
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
 
 
 
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS =
 
 
# Optional compiler flags.
# -g: generate debugging information (for GDB, or for COFF conversion)
# -O*: optimization level
# -f...: tuning, see gcc manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create assembler listing
CFLAGS = -O$(OPT) \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-Wall -Wstrict-prototypes \
-Wa,-adhlns=$(<:.c=.lst) \
$(patsubst %,-I%,$(EXTRAINCDIRS))
 
 
# Set a "language standard" compiler flag.
# Unremark just one line below to set the language standard to use.
# gnu99 = C99 + GNU extensions. See GCC manual for more information.
#CFLAGS += -std=c89
#CFLAGS += -std=gnu89
#CFLAGS += -std=c99
CFLAGS += -std=gnu99
 
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_INDEX=$(VERSION_INDEX)
 
 
# Optional assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
 
 
 
# Optional linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
 
# Additional libraries
 
# Minimalistic printf version
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
 
# Floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
 
# -lm = math library
LDFLAGS += -lm
 
 
##LDFLAGS += -T./linkerfile/avr5.x
 
 
 
# Programming support using avrdude. Settings and variables.
 
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
#AVRDUDE_PROGRAMMER = dt006
#AVRDUDE_PROGRAMMER = stk200
#AVRDUDE_PROGRAMMER = ponyser
AVRDUDE_PROGRAMMER = avrispv2
#falls Ponyser ausgewählt wird, muss sich unsere avrdude-Configdatei im Bin-Verzeichnis des Compilers befinden
 
#AVRDUDE_PORT = com1 # programmer connected to serial device
#AVRDUDE_PORT = lpt1 # programmer connected to parallel port
AVRDUDE_PORT = usb # programmer connected to USB
 
#AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_SETTINGS)
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
 
#avrdude -c avrispv2 -P usb -p m32 -U flash:w:blink.hex
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
 
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE += -y
 
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
AVRDUDE_FLAGS += -V
 
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_FLAGS += -v -v
 
# ---------------------------------------------------------------------------
# Define directories, if needed.
DIRAVR = c:/userprog/WinAVR-20070525
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
 
 
# Define programs and commands.
SHELL = sh
 
CC = avr-gcc
 
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
 
# Programming support using avrdude.
AVRDUDE = avrdude
 
REMOVE = rm -f
COPY = cp
 
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
 
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
 
 
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
 
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
 
# Combine all necessary flags and optional flags.
# Add target processor to flags.
#ALL_CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. $(CFLAGS)
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
 
 
# Default target.
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
$(TARGET).lss $(TARGET).sym sizeafter finished end
 
 
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
 
finished:
@echo $(MSG_ERRORS_NONE)
 
end:
@echo $(MSG_END)
@echo
 
 
# Display size of file.
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
 
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
 
 
 
# Display compiler version information.
gccversion :
@$(CC) --version
 
 
# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
 
 
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
 
 
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
 
 
 
 
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
 
 
 
 
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
 
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
 
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
 
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
avr-nm -n $< > $@
 
 
 
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
 
 
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
 
 
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
 
 
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
 
 
 
 
 
 
# Target: clean project.
clean: begin clean_list finished end
 
clean_list :
@echo
@echo $(MSG_CLEANING)
# $(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
 
 
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
 
 
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
 
 
 
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
clean clean_list program
 
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/main.c
New file
0,0 → 1,408
/*------------------------------------------------------------------------------
** **
** Ident : main.c **
** Project : MX12 2 (3) ppm channel expander **
** Author : Jacques Wanders **
** Description : main module **
** Copyright (c): 05.2008 Jacques Wanders **
** modified : 05.2008 Heinrich Fischer for use with WinAVR **
** **
**----------------------------------------------------------------------------**
** Release : v1.0 initial release **
** Date : 13-05-2008 **
**----------------------------------------------------------------------------**
** Release : v1.1 **
** Date : 13-05-2008 **
** Notes : Added Channel 9 **
**----------------------------------------------------------------------------**
** Release : v1.2 **
** Date : 22-05-2008 **
** Notes : Modified time definitions for FORCE_LOW_END_FRAME **
** and MIN_SYNC_TIME to avoid lost pulse groups **
**----------------------------------------------------------------------------**
** Release : v1.2sp **
** Date : 06-10-2008 **
** Notes : Special version, with a total of 8 channels. **
** original 6th MX12 channel is ignored and replaced **
**----------------------------------------------------------------------------**
** **
** 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 ENABLE_BIT_DEFINITIONS
//#include <ioavr.h>
//#include <inavr.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "main.h"
 
 
enum{
stPPM_SYNC,
stPPM_SYNC_WAIT,
stPPM_CHANNEL_START,
stPPM_CHANNEL_DATA,
stPPM_CHANNEL_6_DATA_TRIGGER,
stPPM_CHANNEL_6_DATA,
stPPM_CHANNEL_7_START,
stPPM_CHANNEL_7_DATA,
stPPM_CHANNEL_8_START,
stPPM_CHANNEL_8_DATA,
stPPM_FINISH_PULSE,
stPPM_FINISH_FRAME,
stPPM_FRAME_END,
};
 
unsigned char channel_number = 0;
unsigned char ppm_state = stPPM_SYNC;
unsigned char adc_channel = 0;
volatile unsigned int channel_6 = 0xffff; // set to max. for testing if conversion is valid
volatile unsigned int channel_7 = 0xffff; // set to max. for testing if conversion is valid
volatile unsigned int channel_8 = 0xffff; // set to max. for testing if conversion is valid
 
 
/*------------------------------------------------------------------------------
** **
** function : init_pin(void) **
** purpose : Initialise I/O pins **
** **
**----------------------------------------------------------------------------*/
void init_pin(void)
{
 
DDRA &= ~(1<<PPM_IN); // set Input Capture Pin as input
PORTA |= (1<<PPM_IN); // enable pullup
 
DDRB |= (1<<PPM_OUT_PIN); // configure PPM_OUT pin as output
SET_PPM_OUT_LOW; // set low
 
DDRA &= ~(1 << CHANNEL_6_ADC); // Channel 6 (pin12) input
PORTA &= ~(1 << CHANNEL_6_ADC); // disable pullup
 
DDRA &= ~(1 << CHANNEL_7_ADC); // Channel 7 (pin11) input
PORTA &= ~(1 << CHANNEL_7_ADC); // disable pullup
 
DDRA &= ~(1 << CHANNEL_6_ADC); // Channel 8 (pin10) input
PORTA &= ~(1 << CHANNEL_6_ADC); // disable pullup
 
}
/*-init_pin-------------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : init_adc(void) **
** purpose : Initialise ADC registers **
** **
**----------------------------------------------------------------------------*/
void init_adc(void)
{
 
cli(); // disable interrupts
 
DIDR0 |= ((1<<ADC2D)|(1<<ADC1D)); // digital input disable for pin 11 and 12
ADMUX = 0x00; // VCC as reference voltage, select channel 0
ADCSRA = (1 << ADPS2) | (1 << ADPS1)|| (0 << ADPS0); // 8.0 [Mhz] / 128 = 62,5 [kHz]
ADCSRB = 0x00; // free running mode
 
ADC_ENABLE;
 
sei(); // enable interrupts
}
/*-init_adc-------------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : init_timer1(void) **
** purpose : Initialise timer0 **
** Note(s) : Frequency : 8.0 [Mhz] **
** 8 / 8.0 Mhz : 1.00 [us] **
** **
**----------------------------------------------------------------------------*/
void init_timer1(void)
{
cli(); // disable interrupts
 
TCCR1A = ((0<<WGM11)|(0<<WGM10)); // CTC mode
TCCR1B = ((0<<WGM13)|(1<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10)); // CTC mode for COMPA, prescaler 8 / 8MHz => [1.0us]
 
CLEAR_INPUT_CAPTURE_INTERRUPT_FLAG; // reset ICF flag
 
SET_COUNTER_TO_ZERO;
SET_COMPARE_COUNTER_TO_ZERO;
ENABLE_INPUT_CAPTURE;
DISABLE_OUTPUT_COMPARE;
RISING_EDGE_TRIGGER;
 
sei(); // enable interrupts
}
/*-init_timer1----------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : timer1_capture_interrupt(void) **
** purpose : Synchronise PPM frame and copy input events to PPM_OUT, **
** start mixing Ch6, 7 and 7 data when detect start pulse of Ch7 **
** **
**----------------------------------------------------------------------------*/
//#pragma vector=TIM1_CAPT_vect
//static __nested __interrupt void timer1_capture_interrupt (void)
ISR(TIMER1_CAPT_vect)
{
cli(); // disable interrupts
unsigned int data;
 
switch (ppm_state)
{
case stPPM_SYNC: // detect rising edge pulse
data = ICR1; // get timer value after input capture
SET_COUNTER_TO_ZERO;
FALLING_EDGE_TRIGGER;
if(data >= MIN_SYNC_TIME && data <= MAX_SYNC_TIME) // valid sync trigger
{
SET_PPM_OUT_HIGH;
ppm_state = stPPM_CHANNEL_DATA; // next state: get data
channel_number = 0;
}
else // trigger but not a valid sync time
{
SET_PPM_OUT_LOW;
ppm_state = stPPM_SYNC_WAIT; // next state: wait for next sync event
}
break;
 
case stPPM_SYNC_WAIT:
SET_PPM_OUT_LOW; // not nessecery, output should already be low
SET_COUNTER_TO_ZERO;
SET_CAPTURE_COUNTER_TO_ZERO;
RISING_EDGE_TRIGGER;
ppm_state = stPPM_SYNC; // next state: try again for new sync
break;
 
case stPPM_CHANNEL_START: // detect rising edge pulse
SET_COUNTER_TO_ZERO;
SET_PPM_OUT_HIGH;
FALLING_EDGE_TRIGGER;
channel_number++; // prepare for next MX12 channel clock
if(channel_number>4) // all 5 channels read
{
ppm_state = stPPM_CHANNEL_6_DATA_TRIGGER; // 7th. channel but now self created
channel_number = 0;
}
else
ppm_state = stPPM_CHANNEL_DATA;
break;
 
case stPPM_CHANNEL_DATA: // detect falling edge pulse
SET_COUNTER_TO_ZERO;
SET_PPM_OUT_LOW;
RISING_EDGE_TRIGGER;
ppm_state = stPPM_CHANNEL_START; // wait for next channel rising edge pulse
break;
 
case stPPM_CHANNEL_6_DATA_TRIGGER: // detect rising edge pulse
SET_COUNTER_TO_ZERO;
SET_PPM_OUT_LOW;
SET_TIMER_TO_COMPA_CTC;
DISABLE_INPUT_CAPTURE;
ENABLE_OUTPUT_COMPARE;
OCR1A = START_PULSE_LOW; // startpulse length 0.3ms
TRIGGER_INPUT_COMPARE_INTERRUPT;
ppm_state = stPPM_CHANNEL_6_DATA;
break;
 
default:
SET_PPM_OUT_LOW; // not nessecery, output should already be low
SET_COUNTER_TO_ZERO;
SET_CAPTURE_COUNTER_TO_ZERO;
RISING_EDGE_TRIGGER;
ppm_state = stPPM_SYNC; // next state: try again for new sync
break;
 
}
sei();
}
/*-timer1_capture_interrupt---------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : timer1_compare_interrupt(void) **
** purpose : Mixing channel 7, 8 and 9 data into ppm out, **
** start input capture for frame synchronisation **
** **
**----------------------------------------------------------------------------*/
//#pragma vector=TIM1_COMPA_vect
//__interrupt void timer1_compare_interrupt (void)
ISR(TIM1_COMPA_vect)
{
cli();
switch (ppm_state)
{
case stPPM_CHANNEL_6_DATA: // create 6th channel data
SET_PPM_OUT_LOW;
SET_COUNTER_TO_ZERO;
OCR1A = channel_6; // COMPA: 0,7ms + channel 6 ADC value
ppm_state = stPPM_CHANNEL_7_START; // next State
break;
 
case stPPM_CHANNEL_7_START: // create 7th channel start pulse
SET_PPM_OUT_HIGH;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_HIGH; // startpulse length 0.3ms
ppm_state = stPPM_CHANNEL_7_DATA; // next State
break;
 
case stPPM_CHANNEL_7_DATA: // create 7th channel data
SET_PPM_OUT_LOW;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_LOW + channel_7; // COMPA: 0,7ms + channel 6 ADC value
ppm_state = stPPM_CHANNEL_8_START; // next State
break;
 
case stPPM_CHANNEL_8_START: // create 7th channel start pulse
SET_PPM_OUT_HIGH;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_HIGH; // startpulse length 0.3ms
ppm_state = stPPM_CHANNEL_8_DATA; // next State
break;
 
case stPPM_CHANNEL_8_DATA: // create 7th channel data
SET_PPM_OUT_LOW;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_LOW + channel_8; // COMPA: 0,7ms + channel 7 ADC value
ppm_state = stPPM_FINISH_PULSE; // next State
break;
 
case stPPM_FINISH_PULSE: // create last pulse
SET_PPM_OUT_HIGH;
SET_COUNTER_TO_ZERO;
OCR1A = START_PULSE_HIGH; // startpulse length 0.3ms
ppm_state = stPPM_FINISH_FRAME; // next State
break;
 
case stPPM_FINISH_FRAME: // create extra low pulse for masking PPM_IN data of channel 7 and 8
SET_PPM_OUT_LOW;
SET_COUNTER_TO_ZERO;
OCR1A = FORCE_LOW_END_FRAME; // keep last end low; 2 channels max - 2 channels min => 2x2ms - 2x1ms + extra length = 2 ms + 1 ms = 3ms => 3000 ticks
ppm_state = stPPM_FRAME_END; // next State
break;
 
case stPPM_FRAME_END:
default:
RISING_EDGE_TRIGGER;
DISABLE_OUTPUT_COMPARE;
ENABLE_INPUT_CAPTURE;
SET_TIMER_TO_COMPA_CTC;
SET_COUNTER_TO_ZERO;
SET_COMPARE_COUNTER_TO_ZERO;
SET_CAPTURE_COUNTER_TO_ZERO;
ppm_state = stPPM_SYNC; // next State
TRIGGER_INPUT_CAPTURE_INTERRUPT;
break;
 
}
sei();
}
/*-timer1_compare_interrupt---------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : adc_server(void) **
** purpose : Handle Analog conversion of RC channel 6, 7 and 8 **
** **
**----------------------------------------------------------------------------*/
//#pragma vector=ADC_vect
//__interrupt void adc_server(void)
ISR(ADC_vect)
{
unsigned int AdcResult;
 
ADC_DISABLE;
 
AdcResult = ADC;
if(AdcResult > 1000) // limit conversion value
AdcResult = 1000; // 1000 => 1ms
 
ADMUX &= ~(ADC_CHANNEL_MASK); // clear channel select bits
 
if(adc_channel == ADC_CHANNEL_6)
{
channel_6 = AdcResult; // set channel 6 value;
adc_channel = ADC_CHANNEL_7; // set next event for channel 7 conversion
}
else if(adc_channel == ADC_CHANNEL_7)
{
channel_7 = AdcResult; // set channel 7 value;
adc_channel = ADC_CHANNEL_8; // set next event for channel 8 conversion
}
else
{
channel_8 = AdcResult; // set channel 8 value;
adc_channel = ADC_CHANNEL_6; // set next event for channel 6 conversion
}
 
ADMUX |= adc_channel; // select new conversion channel
 
ADC_ENABLE;
}
/*-adc_server-----------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : check_valid_adc_value(void) **
** purpose : wait until 3 ADC channels are processed at least once **
** before init Input Capture/Timer1 **
** **
**----------------------------------------------------------------------------*/
void check_valid_adc_value (void)
{
unsigned char exit = FALSE;
 
do
{
if(channel_6 < 0xffff && channel_7 < 0xffff && channel_8 < 0xffff) // both channels must be processed
exit = TRUE;
 
}while (!exit);
}
/*-check_valid_adc_value------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------
** **
** function : main(void) **
** **
**----------------------------------------------------------------------------*/
int main(void)
{
 
init_pin();
init_adc();
check_valid_adc_value(); // wait until both ADC channels are processed at least once
init_timer1();
 
while(1)
{}
}
 
/*-main-----------------------------------------------------------------------*/
 
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/MX12_expander__V1_2sp.hex
New file
0,0 → 1,58
:1000000010C028C027C026C025C04DC0B9C022C01E
:1000100021C020C01FC01EC01DC035C11BC01AC0DA
:1000200019C011241FBECFEDCDBF10E0A0E6B0E097
:10003000E0E8F3E002C005900D92A636B107D9F7CB
:1000400010E0A6E6B0E001C01D92A936B107E1F7C5
:1000500071D194C1D5CFD798DF9ABA9AC298D19866
:10006000D998D298DA98D198D9980895F89481B10E
:10007000866081B917B881E086B913B886B1886CFB
:1000800086B978940895F8941FBC8AE08EBD5D9877
:100090001DBC1CBC1BBC1ABC659A61988EB58064E3
:1000A0008EBD789408951F920F920FB60F9211246F
:1000B0002F933F938F939F93F894809167008230A2
:1000C000E9F0833018F4882339F046C0833059F1C1
:1000D000843009F041C02FC024B535B51DBC1CBC0F
:1000E0008EB58F7B8EBD285B3B4029533A4418F474
:1000F000C29A83E011C0C29881E02BC01DBC1CBC19
:10010000C29A8EB58F7B8EBD809166008F5F809383
:100110006600853030F084E08093670010926600BE
:1001200025C083E016C01DBC1CBCC2988EB580647F
:100130008EBD82E00EC01DBC1CBCC2988EB58F7EE9
:100140008EBD6598619A88E592E09BBD8ABD599AFB
:1001500085E0809367000AC0C2981DBC1CBC15BC1A
:1001600014BC8EB580648EBD1092670078949F9108
:100170008F913F912F910F900FBE0F901F90189568
:100180001F920F920FB60F9211248F939F93F894A2
:10019000809167008830B1F1893040F48630D1F029
:1001A000873018F5853009F055C009C08A3009F448
:1001B0003FC08A3080F18B3009F04CC042C0C298F9
:1001C0001DBC1CBC80916000909161009BBD8ABDEC
:1001D00086E008C0C29A1DBC1CBC80E991E09BBDB2
:1001E0008ABD87E08093670046C0C2981DBC1CBCD6
:1001F0008091620090916300885A9D4F9BBD8ABD9B
:1002000088E0F0CFC29A1DBC1CBC80E991E09BBD88
:100210008ABD89E0E7CFC2981DBC1CBC80916400F8
:1002200090916500885A9D4F9BBD8ABD8AE0DACFC8
:10023000C29A1DBC1CBC80E991E09BBD8ABD8BE0CD
:10024000D1CFC2981DBC1CBC8CED95E09BBD8ABD76
:100250008CE0C8CF8EB580648EBD6198659A8EB5EE
:100260008F7E8EBD1DBC1CBC1BBC1ABC15BC14BC37
:10027000109267005D9A78949F918F910F900FBEB6
:100280000F901F9018951F920F920FB60F92112486
:100290002F933F938F939F9386B1877386B924B131
:1002A00035B183E0293E380710F028EE33E087B1FE
:1002B0008C7F87B980916800813031F43093610080
:1002C0002093600082E00DC0823031F430936300EF
:1002D0002093620083E005C03093650020936400A2
:1002E00081E08093680087B190916800892B87B97D
:1002F00086B1886C86B99F918F913F912F910F9015
:100300000FBE0F901F901895809160009091610032
:100310008F5F9F4FC9F380916200909163008F5F60
:100320009F4F91F380916400909165008F5F9F4F84
:1003300059F3089590DEF89481B1866081B917B8B9
:1003400081E086B913B886B1886C86B978948091BB
:100350006000909161008F5F9F4FC9F380916200B0
:10036000909163008F5F9F4F91F380916400909113
:1003700065008F5F9F4F59F386DEFFCFF894FFCF64
:06038000FFFFFFFFFFFF7D
:00000001FF
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/main.h
New file
0,0 → 1,101
/*------------------------------------------------------------------------------
** **
** 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_6_ADC PORTA1 // (pin12)
#define CHANNEL_7_ADC PORTA2 // (pin11)
#define CHANNEL_8_ADC PORTA3 // (pin11)
#define PPM_IN PORTA7 // (pin6)
#define PPM_OUT_PIN PORTB2 // (pin5)
 
#define ADC_CHANNEL_6 0x01 // ADC1 - PORTA1 (pin12)
#define ADC_CHANNEL_7 0x02 // ADC2 - PORTA2 (pin11)
#define ADC_CHANNEL_8 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 1500 // [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()