/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/MX12_expander__V1_2sp.hex |
---|
File deleted |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/main.h |
---|
File deleted |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/MX12-Erweiterung.pnproj |
---|
File deleted |
\ No newline at end of file |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/makefile |
---|
File deleted |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12 Expander 1.2sp/main.c |
---|
File deleted |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/MX12-Erweiterung.pnps |
---|
File deleted |
\ No newline at end of file |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/main.c |
---|
File deleted |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/main.h |
---|
File deleted |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/MX12-Erweiterung.pnproj |
---|
File deleted |
\ No newline at end of file |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/makefile |
---|
File deleted |
/RC-Expander/branches/MX16s_10Ch_V1.0/MX12_Expander1.3/MX12_extender__V1_3.hex |
---|
File deleted |
/RC-Expander/branches/MX16s_10Ch_V1.0/_make.bat |
---|
0,0 → 1,21 |
set PATH=D:\Projekte\Atmel_AVR\_Tools\GCC\WinAVR-20100110_V4.3.3\bin;%PATH% |
del *.elf |
del *.hex |
@rem -> compile and link |
avr-gcc -Os -Wall -mmcu=attiny44a -DF_CPU=8000000 -o main.elf main.c |
@rem -> generate program hex file |
avr-objcopy -O ihex main.elf main.hex |
@rem -> display program size |
avr-size main.hex |
@rem -Os optimization level (optimize for size) |
@rem -Wall show all warnings |
@rem -mmcu=attiny44a generate code for ATtiny44a |
@rem -DF_CPU=8000000 CPU-Frequenz 8.0 MHz |
@rem -o output file name |
pause |
/RC-Expander/branches/MX16s_10Ch_V1.0/main.c |
---|
0,0 → 1,212 |
/*------------------------------------------------------------------------------ |
** Ident : main.c ** |
** Project : MX16s 8->10 ppm channel expander ** |
** Author : lakeroe ** |
** Description : main module ** |
** 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. ** |
------------------------------------------------------------------------------*/ |
#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_9_DATA, |
stPPM_CHANNEL_10_START, |
stPPM_CHANNEL_10_DATA, |
stPPM_FINISH_PULSE, |
stPPM_FRAME_END |
}; |
unsigned char channel_number = 0; |
unsigned char ppm_state = stPPM_SYNC; |
// timer1_capture_interrupt (void) |
// Synchronise PPM frame and copy input events to PPM_OUT, start mixing Ch9,10 data when detect start pulse of Ch9 |
ISR (TIM1_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: // detect falling edge pulse |
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 MX16s channel clock |
if(channel_number>7) // all eight channels read |
{ |
SET_COUNTER_TO_ZERO; |
SET_PPM_OUT_HIGH; |
SET_TIMER_TO_COMPA_CTC; |
DISABLE_INPUT_CAPTURE; |
ENABLE_OUTPUT_COMPARE; |
OCR1A = START_PULSE; // startpulse length 0.4ms |
TRIGGER_INPUT_COMPARE_INTERRUPT; |
ppm_state = stPPM_CHANNEL_9_DATA; // 9th. 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; |
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_compare_interrupt (void) |
// Mixing channel 9,10 data into ppm out, start input capture for frame synchronisation |
ISR (TIM1_COMPA_vect) |
{ |
cli (); |
switch (ppm_state) |
{ |
case stPPM_CHANNEL_9_DATA: |
SET_PPM_OUT_LOW; |
SET_COUNTER_TO_ZERO; |
if (PINA & (1 << CHANNEL_9)) // Channel 9 on/off |
OCR1A = PPM_PULSE_MAX - START_PULSE; |
else |
OCR1A = PPM_PULSE_MIN - START_PULSE; |
// set OCR1A between [PPM_PULSE_MIN-START_PULSE] and [PPM_PULSE_MAX-START_PULSE] for transmitting analog value |
ppm_state = stPPM_CHANNEL_10_START; // next State |
break; |
case stPPM_CHANNEL_10_START: |
SET_PPM_OUT_HIGH; |
SET_COUNTER_TO_ZERO; |
OCR1A = START_PULSE; // startpulse length 0.4ms |
ppm_state = stPPM_CHANNEL_10_DATA; // next State |
break; |
case stPPM_CHANNEL_10_DATA: |
SET_PPM_OUT_LOW; |
SET_COUNTER_TO_ZERO; |
if (PINA & (1 << CHANNEL_10)) // Channel 10 on/off |
OCR1A = PPM_PULSE_MAX - START_PULSE; |
else |
OCR1A = PPM_PULSE_MIN - START_PULSE; |
// set OCR1A between [PPM_PULSE_MIN-START_PULSE] and [PPM_PULSE_MAX-START_PULSE] for transmitting analog 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; // startpulse length 0.4ms |
ppm_state = stPPM_FRAME_END; // next State |
break; |
case stPPM_FRAME_END: |
default: |
SET_PPM_OUT_LOW; |
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 (); |
} |
int main (void) |
{ |
cli (); // disable interrupts |
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_9); // Channel 9 (Pin 10) input |
PORTA |= (1 << CHANNEL_9); // enable pullup |
DDRA &= ~(1 << CHANNEL_10); // Channel 10 (Pin 9) input |
PORTA |= (1 << CHANNEL_10); // enable pullup |
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 |
while(1); |
} |
/RC-Expander/branches/MX16s_10Ch_V1.0/main.h |
---|
0,0 → 1,66 |
/*------------------------------------------------------------------------------ |
** 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] |
/RC-Expander/branches/MX16s_10Ch_V1.0/main.hex |
---|
0,0 → 1,34 |
:1000000010C01FC01EC01DC01CC01CC084C019C0B1 |
:1000100018C017C016C015C014C013C012C011C03C |
:1000200010C011241FBECFE5D1E0DEBFCDBF10E070 |
:10003000A0E6B0E001C01D92A236B107E1F7CBD037 |
:10004000E2C0DECF1F920F920FB60F9211242F93B2 |
:100050003F938F939F93F89480916100813009F4CE |
:1000600046C0813030F08230B1F0833009F03FC0BB |
:1000700034C024B535B51DBC1CBC8EB58F7B8EBD80 |
:10008000285B3B4029533A4418F4C29A83E01EC0CF |
:10009000C29881E029C01DBC1CBCC29A8EB58F7B62 |
:1000A0008EBD809160008F5F80936000883098F0F3 |
:1000B0001DBC1CBCC29A8EB58F7E8EBD6598619AA0 |
:1000C00080E991E09BBD8ABD599A84E080936100EC |
:1000D0001092600016C083E007C01DBC1CBCC29813 |
:1000E0008EB580648EBD82E0809361000AC0C298A4 |
:1000F0001DBC1CBC15BC14BC8EB580648EBD10929A |
:10010000610078949F918F913F912F910F900FBE36 |
:100110000F901F9018951F920F920FB60F921124F7 |
:100120008F939F93F894809161008530C1F0863061 |
:1001300018F48430B1F505C08630E1F0873089F5D8 |
:1001400027C0C2981DBC1CBCCB9B03C080E496E0BA |
:1001500002C088E592E09BBD8ABD85E008C0C29AD6 |
:100160001DBC1CBC80E991E09BBD8ABD86E08093EC |
:10017000610029C0C2981DBC1CBCCC9B03C080E49C |
:1001800096E002C088E592E09BBD8ABD87E0EFCF94 |
:10019000C29A1DBC1CBC80E991E09BBD8ABD88E071 |
:1001A000E6CFC2988EB580648EBD6198659A8EB593 |
:1001B0008F7E8EBD1DBC1CBC1BBC1ABC15BC14BCE8 |
:1001C000109261005D9A78949F918F910F900FBE6D |
:1001D0000F901F901895F894D798DF9ABA9AC29802 |
:1001E000D398DB9AD498DC9A1FBC8AE08EBD5D98C8 |
:1001F0001DBC1CBC1BBC1ABC659A61988EB5806482 |
:0A0200008EBD7894FFCFF894FFCF75 |
:00000001FF |