Porting Code from one board to another

I'm green as grass, but I'm trying to learn how to program. I want to fly a tricopter using MulitWii firmware which will run on a atmega 328. There is a specific board sold by a vendor, but I have a different board that is laidout a little differently. My board is the ArduIMU sold by 3DRobotics. This board is labeled with pins D8, A0, A1, A2, A3 available. The MultiWii code is setup to read PPM on pin labeled D2, but I only have D8 available for reading a Rx.

This is the line in the Rx sketch where PPM is started:

/**************************************************************************************/
/***************                PPM SUM RX Pin reading             ********************/
/**************************************************************************************/
// attachInterrupt fix for promicro
#if defined(PROMICRO) && defined(SERIAL_SUM_PPM)
  ISR(INT6_vect){rxInt();}
#endif

If I want to use pin D8, should I change that to ISR(INT8_vect) ?

Well, I cant even express the problem. Let me try one more time.

This line is in def.h:

#define PPM_PIN_INTERRUPT attachInterrupt(0, rxInt, RISING); //PIN 0

I am able to Rx a single channel by turning off PPM and uncommenting this line:

/********************************* Aux 2 Pin **********************************/
/
possibility to use PIN8 or PIN12 as the AUX2 RC input (only one, not both)
it deactivates in this case the POWER PIN (pin 12) or the BUZZER PIN (pin 8) */
#define RCAUXPIN8

I'm under the impression that pin D8 on my board is actually PIN 0

I got another piece of code that is part of the board definition in def.h

//RX PIN assignment inside the port //for PORTD
#define THROTTLEPIN 2
#define ROLLPIN 4
#define PITCHPIN 5
#define YAWPIN 6
#define AUX1PIN 7
#define AUX2PIN 0 // optional PIN 8 or PIN 1122
#define AUX3PIN 1 // unused
#define AUX4PIN 3 // unused

#define PCINT_PIN_COUNT 5
#define PCINT_RX_BITS (1<<2),(1<<4),(1<<5),(1<<6),(1<<7)
#define PCINT_RX_PORT PORTD
#define PCINT_RX_MASK PCMSK2
#define PCIR_PORT_BIT (1<<2)
#define RX_PC_INTERRUPT PCINT2_vect
#define RX_PCINT_PIN_PORT PIND
#define V_BATPIN A3 // Analog PIN 3
#define PSENSORPIN A2 // Analog PIN 2

I am able to Rx a single channel on my board's pin D8 if I use the #define RCAUXPIN8 , but I cant Rx it as PPM. I'm thinking the
#define RX_PC_INTERRUPT needs to be PCINT0 or PCINT8_vect. It's confusing me big time.

Yeah I can understand that little error... But you know, I've been in the electronics business since 1970... And I've Never seen an IC with a Pin 0... Something you'd have understood at a glance (I hope) had you looked at a schematic or a board itself (Uno)... or the Atmel ATMega data sheet. I do have to give you third credit... The 0 part is right... Just which one PB0?, PC0? or PD0? PB0, pin 14 isn't even on your short list of pins used or available. D8 is really pin 14

Doc

If I uncomment the #define RCAUXPIN8 and hook my PPM input to Pin labeled D8 on my board, nothing. If I turn off PPM and just hook one Rx channel to D8, i get PWM coming through.

I tried:

#define PPM_PIN_INTERRUPT attachInterrupt(8, rxInt, RISING); //PIN 0

and I tried:

#define PPM_PIN_INTERRUPT attachInterrupt(14, rxInt, RISING); //PIN 0

I dont know how to figure out how to reassign everything to match my board. The MultiWii code defines that PPM is to be used, then it gets confusing with ports, ISR, Pins, rising edges, falling edges, timers. I'm hoping to understand that, then maybe I can understand where changes need to be made.

Pin numbers and interrupts numbers aren't the same. Read this:

I think I'm going to cry. OK, I cant login to this site on the computer that has the code or schematics I have looked at. I log in and the forum page is just a blank.

I looked at the schematic for the ArduIMU and the pin labeled on the board as D8 and schematic says PB0/12.

#define PPM_PIN_INTERRUPT attachInterrupt(0, rxInt, RISING);

I thought 0 is pin number like pinMode(0, INPUT);

Could I #define PPM_PIN_INTERRUPT pinMode(8, INPUT); ?

CodeTarded:
I log in and the forum page is just a blank.

I've seen a similar problem in the past. I recommend that you edit the URL and delete everything to the right of the '?' - that cures it for me.

I switched to a different browser and it works. This is the Rx sketch.

[pre/**************************************************************************************/
/***************                PPM SUM RX Pin reading             ********************/
/**************************************************************************************/
// attachInterrupt fix for promicro
#if defined(PROMICRO) && defined(SERIAL_SUM_PPM)
  ISR(INT6_vect){rxInt();}
#endif

// PPM_SUM at THROTTLE PIN on MEGA boards
#if defined(PPM_ON_THROTTLE) && defined(MEGA) && defined(SERIAL_SUM_PPM)
  ISR(PCINT2_vect) { if(PINK & (1<<0)) rxInt(); }
#endif

// Read PPM SUM RX Data
#if defined(SERIAL_SUM_PPM)
  void rxInt() {
    uint16_t now,diff;
    static uint16_t last = 0;
    static uint8_t chan = 0;
  #if defined(FAILSAFE)
    static uint8_t GoodPulses;
  #endif][/pre]

So, if this is starting to make any sense, then when my board uses attachInterrupt(0, rxInt, RISING) it will listen for changes on the interrupt pin and send whatever it reads to execute rxInt(). If the edge is detected as RISING, that triggers the ISR?

I guess I'm trying to figure out what is the right ISR(INT????) if my pin is D8/PB0 ??

I managed to change some code and get the Red LED to light up and blink away.

#if defined(PROMINI)
#if !defined(MONGOOSE1_0)
#define LEDPIN_PINMODE pinMode (13, OUTPUT);
#define LEDPIN_TOGGLE PINB |= 1<<5; //switch LEDPIN state (digital PIN 13)
#define LEDPIN_OFF PORTB &= ~(1<<5);
#define LEDPIN_ON PORTB |= (1<<5);

To this:

#if defined(PROMINI)
#if !defined(MONGOOSE1_0)
#define LEDPIN_PINMODE pinMode (5, OUTPUT); //pinMode (5, OUTPUT);
#define LEDPIN_TOGGLE PIND |= 1<<5; //switch LEDPIN state (digital PIN 5/RED)
#define LEDPIN_OFF PORTD &= ~(1<<5);
#define LEDPIN_ON PORTD |= (1<<5);

Then I changed it to this to get the Blue LED blinking:

#if defined(PROMINI)
#if !defined(MONGOOSE1_0)
#define LEDPIN_PINMODE pinMode (6, OUTPUT); //pinMode (5, OUTPUT);
#define LEDPIN_TOGGLE PIND |= 1<<6; //switch LEDPIN state (digital PIN 6/BLUE)
#define LEDPIN_OFF PORTD &= ~(1<<6);
#define LEDPIN_ON PORTD |= (1<<6);

I did this to see if I can figure out the mapping of some of the pins on my board. I just cant figure out how to get it to recognize PPM on D8/PB0. I'm not writing anything new( somebody else already wrote MultiWii), just trying to adapt it to a different board with the same processor.

Here's some more that I changed to suit my layout:
From:
#define SERVO_6_PINMODE pinMode(A3,OUTPUT); // TRI REAR - BI RIGHT
#define SERVO_6_PIN_HIGH PORTD|= 1<<3;
#define SERVO_6_PIN_LOW PORTD &= ~(1<<3);
To:
#define SERVO_6_PINMODE pinMode(A3,OUTPUT); // TRI REAR - BI RIGHT
#define SERVO_6_PIN_HIGH PORTC|= 1<<3;
#define SERVO_6_PIN_LOW PORTC &= ~(1<<3);

I made this change because the info I have on my board says A3 is C3

I'm not saying I remotely understand any of this, but I managed to get the PPM signal to atleast cause some kind of output. The PPM is all Rx channels wrapped into one and that's what I see. The PWM display for the channel I have PPM connected jumps around from about 900 us to 2100 us. I think the problem is now how do I read that and break it up into individual channels?

CodeTarded:
I think I'm going to cry. OK, I cant login to this site on the computer that has the code or schematics I have looked at.

Internet Explorer 10?

Was 10.

Here's where I'm now. It seems to be reading PPM, but only for a split second when it boots and then it does nothing.

#if defined(SERIAL_SUM_PPM)
ISR(PCINT0_vect) { if(PINB & (1<<0)) rxInt(); }

#endif

// Read PPM SUM RX Data
#if defined(SERIAL_SUM_PPM)
void rxInt() {
PCICR |= (1 << 0) ;
PCMSK0 = (1 << 0);

uint16_t now,diff;
static uint16_t last = 0;
static uint8_t chan = 0;
#if defined(FAILSAFE)
static uint8_t GoodPulses;
#endif

now = micros();
sei();
diff = now - last;
last = now;
if(diff>3000) chan = 0;
else {
if(900<diff && diff<2200 && chan<RC_CHANS ) { //Only if the signal is between these values it is valid, otherwise the failsafe counter should move up
rcValue[chan] = diff;
#if defined(FAILSAFE)
if(chan<4 && diff>FAILSAFE_DETECT_TRESHOLD) GoodPulses |= (1<<chan); // if signal is valid - mark channel as OK
if(GoodPulses==0x0F) { // If first four chanells have good pulses, clear FailSafe counter
GoodPulses = 0;
if(failsafeCnt > 20) failsafeCnt -= 20; else failsafeCnt = 0;
}
#endif
}
chan++;
}
}
#endif