What does it mean that digitalRead() has to read it at the right moment? Does it mean that digitalRead() takes place at whenever it is ready to take place, and once it reads the input (regardless of whether it's LOW or HIGH), it moves forward and when the 600ns signal comes in, the digitalRead() may have already been executed, thus missing the actual signal itself?
Thanks for the fast responses! I did some more reading and gave it a shot, incorporating it into my current code:
int pin = 21; //*added (pin 21 is int.2 on Arduino Mega, right?)
volatile int state = LOW; //*added
void setup()
{
Serial.begin(9600);
pinMode(22, INPUT); // digital DB00
pinMode(23, INPUT); // digital DB01
pinMode(24, INPUT); // digital DB02
pinMode(25, INPUT); // digital DB03
pinMode(26, INPUT); // digital DB04
pinMode(27, INPUT); // digital DB05
pinMode(28, INPUT); // digital DB06
pinMode(29, INPUT); // digital DB07
pinMode(30, INPUT); // digital DB08
pinMode(31, INPUT); // digital DB09
pinMode(32, INPUT); // digital DB10
pinMode(33, INPUT); // digital DB11
pinMode(34, INPUT); // digital DB12
pinMode(35, INPUT); // digital DB13
pinMode(36, INPUT); // digital DB14
pinMode(37, INPUT); // digital DB15
pinMode(38, OUTPUT); // CPU_Ready digital
pinMode(39, OUTPUT); // Data_Hold digital
pinMode(40, INPUT); // Cycle_Request digital
pinMode(pin, INPUT); //*added
attachInterrupt(digitalPinToInterrupt(pin), xyz, RISING); //*added
digitalWrite(38, HIGH); // Tells signal processor that it can start sending data
}
void xyz () //*added
{ //*added
state = !state; //*added
//*added
} //*added
void loop()
{
if (digitalRead(pin) > 0) // Cycle_Request (pulses for about 600ns from LDV) //*modified
{
digitalWrite(39, HIGH); // Data_Hold
Serial.print(digitalRead(22)); // DB00
Serial.print(digitalRead(23)); // DB01
Serial.print(digitalRead(24)); // DB02
Serial.print(digitalRead(25)); // DB03
Serial.print(digitalRead(26)); // DB04
Serial.print(digitalRead(27)); // DB05
Serial.print(digitalRead(28)); // DB06
Serial.print(digitalRead(29)); // DB07
Serial.print(digitalRead(30)); // DB08
Serial.print(digitalRead(31)); // DB09
Serial.print(digitalRead(32)); // DB10
Serial.print(digitalRead(33)); // DB11
Serial.print(digitalRead(34)); // DB12
Serial.print(digitalRead(35)); // DB13
Serial.print(digitalRead(36)); // DB14
Serial.println(digitalRead(37)); // DB15
digitalWrite(39, LOW); // Data_Hold done and ready for next set
}
else
{
}
}
The basic logic of this code (might look familiar, been working it for a while) is that it reads data sent to the 16 data pins (for data bits 00-15). Also, there are three signal lines that manage this flow.
- CPU_Ready (pin 38) is an outgoing signal to the signal processor to let it know it's ready to receive data (I just write to that pin as HIGH).
- Data_Hold (pin 39) tells the signal processor to hold the data, until it is fully read, before proceeding with the next string of data to the 16 data lines.
- Cycle_Request (pin 40) is the one that "listens" for the 600ns signal from the signal processor. But it is temporarily disabled with "//" as I incorporated the attachInterrupt() set for pin 21 (int.2 on the Mega).
The changes I made to the code to incorporate the attachInterrupt() is commented with an asterisk*. What do you folks think? I don't really understand the types of ISR to be used here (AttachInterrupt() uses "blink") but I just stuck an arbitrary "xyz" in there.
Would this work? Am I applying it correctly?