@camsysca @gilshultz
Sorry I did not want to write too much and I feel that by trying to do this, my query seems a bit confusing.
I am using an arduino giga r1
Here is the wiring:
4 BNC female connectors, connected to a basic voltage divider with 2 resistors to make sure that the output is between 0-2V. The - is connected to the GND, and the + to the different analog A0 to A3 from my arduino. Therefore, A0 to A3 are analog INPUT.
Then, on a second hand, I have 3.3V connected to another device to trigger, GND and pin D7 that I connect to my device to trigger it, so pin 7 is a digital OUTPUT.
The code is quite straightforward:
int Channel1 = A0;
int Channel2 = A1;
int Channel3 = A2;
int Channel4 = A3;
const int triggerPin = 7; // Pin connected to the trigger output
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) {
; // Wait for serial port to connect. Needed for native USB
}
pinMode(triggerPin, OUTPUT); // Set the trigger pin as an output
}
void loop() {
delayMicroseconds(50); //Wait 50 µs to fetch the data
RunMeasurement();
}
void RunMeasurement() {
int value1 = analogRead(Channel1);
int value2 = analogRead(Channel2);
int value3 = analogRead(Channel3);
int value4 = analogRead(Channel4);
Serial.print(micros());
Serial.print(value1);
Serial.print(",");
Serial.print(value2);
Serial.print(",");
Serial.print(value3);
Serial.print(",");
Serial.println(value4);
}
Basically, I am fetching the data from my 4 analog (and it is working well) with the time t. It's a basic datalogger, and even if it's not perfectly synchronised I don't mind. As long as the delay between each of these values is constant, and I just have an offset, it's fine.
Now what I want, is while I am fetching these data, I would like to trigger the device with my PIN 7. Hence, writting something like this:
digitalWrite(triggerPin,HIGH);
delayMicroseconds(150);
digitalWrite(triggerPin,LOW);
delayMicrosecond(500); //Next trigger occurs in 500 µs
However, what I would like to do is:
- Keep recording my data with ~20 kHz sampling rate (so delay of 50µs between each print) -> the data are going into my computer, and I just run the code for few seconds, so no problem of memory
- Triggering my device, with a pulse width of ~150µs and a repetition rate of ~2kHz
- Being able to record in time, my trigger, and my data, while these two steps above are running simulteanously.
I am not sure if it's possible with only 1 arduino, and if I am asking too many steps to run simulteanously.
Does it make sense?
Thanks,