Hi
I am trying to learn how to use the Pin Change Interrupts. I have watched the tutorial at Tutorial and read the data sheet for the ATmega2560/V at ATmega2560/V Data Sheet and below is the code I am running
//Original code from Tutorial: Pin Change Interrupts on the Arduino
//https://www.youtube.com/watch?v=-rvaUgYVNuI
//Modified to work with arduino Mega 2650 on pin D11
#define Rx_Throt 11 //D11 corrisponds to PCINT5 (PCMSK0 / PCIF0 / PCIE0)
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
volatile long unsigned eventTime;
volatile long unsigned previousEventTime;
volatile long unsigned timeSinceLastEvent;
volatile byte portBstatus;
volatile byte eventFlag;
void setup() {
Serial.begin(9600);
//define the pins
pinMode(Rx_Throt, INPUT);
digitalWrite(Rx_Throt, HIGH);
sbi (PCICR, PCIE0); //Enable interupt PCIE0
sbi (PCMSK0, PCINT5); //Set the interupt control bits
}
void loop() {
//if(eventFlag == 1 && (eventTime - previousEventTime > 100)){
//timeSinceLastEvent = eventTime - previousEventTime;
//previousEventTime = eventTime;
//Serial.print(timeSinceLastEvent);
//Serial.println(" ms");
Serial.println(portBstatus, BIN);
Serial.println(digitalRead(Rx_Throt));
//eventFlag = 0;
//}
}
ISR (PCINT5_vect){
portBstatus = PINB;
//eventTime = millis();
//eventFlag = 1;
}
With that I get nothing as PCINT5 remains low even when it has been set to HIGH in the setup. This can be seen if you comment out the if statement in the main loop Serial.println(portBstatus, BIN); returns a 0 or low.
Not sure where I have gone wrong. Have I got a register wrong or am I doing something incorrect?
Note: Long term goal is to read 6 Rx inputs using this method as using the pulse in method takes up too much time to read this many inputs (around 400 milliseconds)