the_maxx
New member
Hello,
I am new in the microcontrollers world so excuse me if I ask stupid things.
I have a Teensy4.0 and I want to use it to measure analog data with the following structure:
The time between trigger and trigger is constant and the time of the signals between triggers can change. The width of the signals also change. Once the second trigger finishes the loop starts again.
I would like to measure the time and width of all the signals.
Right now I am feeding the signal in one of the analog pins and I see the signal in the serial plotter. I am using the following code:
My questions are:
- Is there any better way to measure this type of signals. I would like very good timing precision and measure fast
- How should I decide the better baudrate in my case? I am not pretty sure how it works, I read that if you are connecting teensy through USB the baudrate doesn't affect the measurements but I don't know if it is true.
- How can I save arrays of the measured data and calculate the times and widths of the signals while I am measuring?
- Can I somehow calculate the Fourier transform of the measured data in order to obtain the frequencies of the signals?
Thank you in advance.
I am new in the microcontrollers world so excuse me if I ask stupid things.
I have a Teensy4.0 and I want to use it to measure analog data with the following structure:
The time between trigger and trigger is constant and the time of the signals between triggers can change. The width of the signals also change. Once the second trigger finishes the loop starts again.
I would like to measure the time and width of all the signals.
Right now I am feeding the signal in one of the analog pins and I see the signal in the serial plotter. I am using the following code:
Code:
/* Example
* https://www.pjrc.com/teensy/tutorial4.html
*
* Baudrate time res -> https://gammon.com.au/adc
*
* Conectar el volt al pin A8 = 22
* Conectar el grnd al pin GND
*
*/
void setup() {
//Serial.begin(38400);
Serial.begin(9600);
//Serial.begin(16000000);
}
long val;
long valp;
long mcrTminus = 0.0;
void loop() {
val = analogRead(A8);
valp = analogRead(A0);
long mcrT = micros();
if(valp/310.0 > 0.40){
Serial.print("Up_3000:");
Serial.println(3000.0); // To freeze the upper limit
Serial.print("Up_500:");
Serial.println(500.0); // To freeze the upper limit
Serial.print("Up_10:");
Serial.println(10.0); // To freeze the upper limit
Serial.print("Down_0:");
Serial.println(0); // To freeze the upper limit
Serial.print("analog_A0_is:");
Serial.println(valp/310.0); // en mV -> baudrate = 9600 para input de 1V valp/310
Serial.print("Time_in_us_is:");
Serial.println(mcrT);
Serial.print("Time_diff (us):");
Serial.println(mcrT-mcrTminus); // in us
Serial.print("Time_diff (ms):");
Serial.println((mcrT-mcrTminus)/1000); // in ms
mcrTminus =mcrT;
}
}
My questions are:
- Is there any better way to measure this type of signals. I would like very good timing precision and measure fast
- How should I decide the better baudrate in my case? I am not pretty sure how it works, I read that if you are connecting teensy through USB the baudrate doesn't affect the measurements but I don't know if it is true.
- How can I save arrays of the measured data and calculate the times and widths of the signals while I am measuring?
- Can I somehow calculate the Fourier transform of the measured data in order to obtain the frequencies of the signals?
Thank you in advance.