I'm using the pin change interrupt library to read a typical r/c receiver of 6 channels.
Note: Leonardo/atmega32u4 is being used.
Using the PinChangeInt library I'm able to read 4 of the 6 channels no problem with main loop time 4-8uS.
The problem is it doesn't work with pins 0, 7 which is my throttle and Aux2 signals.
I've tested the receiver with the same board/pins with the multi-wii code and it can read these pins just fine, the signal is confirmed on those pins. (I have yet to analyze how there code reads the pins but suspect its a very similar process)
The only conclusion that I could come up with is that pins 0 and 7 are actual hardware interrupt pins and this library was somehow incompatible on them. As you can see in the code I tried to change those pins to hardware interrupts but with no success. For the record, the fact that they are hardware interrupt pins shouldn't affect how the library works, its just only thing that stands out as odd.
No matter what I do it will not trigger an interrupt on those pins, hardware or other. Tomorrow I plan to see if the PulseIn function works on those pins,.
This is the test code I'm using, its far longer then it needs to be but I was just trying for a quick proof of concept.
//#include <TimerOne.h>
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
int pin;
long timer, timer1;
long time1, time2, time3, time4;
long time11, time22, time33, time44;
volatile long time, time0, time5, time55;
void setup() {
Serial.begin(115200);
while(!Serial);
// #define PIN0 7 // throttle
#define PIN1 MOSI // rotate
#define PIN2 SCK // forward
#define PIN3 8 // left
#define PIN4 MISO // Aux1
// #define PIN5 0 // Aux2
// pinMode(PIN0, INPUT_PULLUP);
pinMode(PIN1, INPUT_PULLUP);
pinMode(PIN2, INPUT_PULLUP);
pinMode(PIN3, INPUT_PULLUP);
pinMode(PIN4, INPUT_PULLUP);
// pinMode(PIN5, INPUT_PULLUP);
// attachInterrupt(PIN0, &rising, RISING);
// attachInterrupt(PIN5, &rising5, RISING);
PCintPort::attachInterrupt(PIN1, &rising1, RISING);
PCintPort::attachInterrupt(PIN2, &rising2, RISING);
PCintPort::attachInterrupt(PIN3, &rising3, RISING);
PCintPort::attachInterrupt(PIN4, &rising4, RISING);
timer1 = micros();
}
//uint8_t i;
void loop() {
timer = micros() - timer1;
Serial.print(timer); Serial.print(", ");
Serial.print(time); Serial.print(", ");
Serial.print(time1); Serial.print(", ");
Serial.print(time2); Serial.print(", ");
Serial.print(time3); Serial.print(", ");
Serial.print(time4); Serial.print(", ");
Serial.println(time5);
timer1 = micros();
}
///////////////////////////////////////////////////////////////////
/*
void rising() {
// pin = PCintPort::arduinoPin;
// time = micros() - time0;
time0 = micros();
detachInterrupt(PIN1);
attachInterrupt(PIN1, &fall, FALLING);
}
void fall() {
// pin = PCintPort::arduinoPin;
time = micros() - time0;
detachInterrupt(7);
attachInterrupt(7, &rising, RISING); }
*/
//////////////////////////////////////////////////////////////////////
void rising1() {
pin = PCintPort::arduinoPin;
time11 = micros();
PCintPort::detachInterrupt(pin);
PCintPort::attachInterrupt(pin, &fall1, FALLING); }
void fall1() {
pin = PCintPort::arduinoPin;
time1 = micros() - time11;
PCintPort::detachInterrupt(pin);
PCintPort::attachInterrupt(pin, &rising1, RISING); }
////////////////////////////////////////////////////////////////
void rising2() {
pin = PCintPort::arduinoPin;
time22 = micros();
PCintPort::detachInterrupt(pin);
PCintPort::attachInterrupt(pin, &fall2, FALLING); }
void fall2() {
pin = PCintPort::arduinoPin;
time2 = micros() - time22;
PCintPort::detachInterrupt(pin);
PCintPort::attachInterrupt(pin, &rising2, RISING); }
///////////////////////////////////////////////////////////////////////////////////
void rising3() {
pin = PCintPort::arduinoPin;
time33 = micros();
PCintPort::detachInterrupt(pin);
PCintPort::attachInterrupt(pin, &fall3, FALLING); }
void fall3() {
pin = PCintPort::arduinoPin;
time3 = micros() - time33;
PCintPort::detachInterrupt(pin);
PCintPort::attachInterrupt(pin, &rising3, RISING); }
/////////////////////////////////////////////////////////////////////////////
void rising4() {
pin = PCintPort::arduinoPin;
time44 = micros();
PCintPort::detachInterrupt(pin);
PCintPort::attachInterrupt(pin, &fall4, FALLING); }
void fall4() {
pin = PCintPort::arduinoPin;
time4 = micros() - time44;
PCintPort::detachInterrupt(pin);
PCintPort::attachInterrupt(pin, &rising4, RISING); }
//////////////////////////////////////////////////////////////////////////////
/*
void rising5() {
// pin = PCintPort::arduinoPin;
time55 = micros();
detachInterrupt(PIN5);
attachInterrupt(PIN5, &fall5, FALLING);
}
void fall5() {
// pin = PCintPort::arduinoPin;
time5 = micros() - time55;
detachInterrupt(PIN5);
attachInterrupt(PIN5, &rising5, RISING); }
*/