Hi everyone!
I'm trying to acquire two analog signals @1kHz, my fixed sampling frequency.
To accomplish this i'm using the library IntervalTimer and calling a function every 1000 microseconds.
The next step that i cannot manage to do is to collect this live stream of data while
displaying it in LabVIEW (I'm using VISA).
This is the code written and uploaded on teensy 3.2 with Teensy Loader 1.40,
Teensyduino version 1.40 installed over Arduino IDE 1.8.3:
This code works until it happens the "jump" depicted in the following picture:
What LabVIEW does is simply:
- reading the serial port with VISA and obtaining a new line with a string
- split the string received into 4 numbers (2 integers and 2 float)
- append each new value into arrays
- plot the array in a xy graph.
Here is the Block Diagram:
I cannot figure out why these jumps happen after tens of thousands of strings...
Thank you in advance,
Leo
I'm trying to acquire two analog signals @1kHz, my fixed sampling frequency.
To accomplish this i'm using the library IntervalTimer and calling a function every 1000 microseconds.
The next step that i cannot manage to do is to collect this live stream of data while
displaying it in LabVIEW (I'm using VISA).
This is the code written and uploaded on teensy 3.2 with Teensy Loader 1.40,
Teensyduino version 1.40 installed over Arduino IDE 1.8.3:
Code:
// Acquisition & display variables
IntervalTimer myTimer; // Create an IntervalTimer object
const int Ch0 = A0; // the pin with analog input (Channel 0)
const int Ch1 = A1; // the pin with analog input (Channel 1)
float val_Ch0 = 0; // the value read from Channel 0 (16 bit)
float val_Ch1 = 0; // the value read from Channel 1 (16 bit)
float volts_Ch0 = 0; // value of Channel 0 in volts
float volts_Ch1 = 0; // value of Channel 1 in volts
// Processing variables
int counter_ms = 0;
int counter_s = 0;
/////////////
// Setup //
/////////////
void setup(void) {
pinMode(Ch0, INPUT);
pinMode(Ch1, INPUT);
analogReadResolution(16);
Serial.begin(9600);
delay(3000);
myTimer.begin(ChnlsReadPrint, 1000); // function executed every 1000 us
}
/////////////////////////////////////////////////////////////////////
// ChnlsReadPrint() is a function called inside an interrupt. //
// Is called every 1000 microseconds and performs these tasks: //
// - Acquire two analog channels; //
// - Converts the values in volts; //
// - write them together with the time; //
/////////////////////////////////////////////////////////////////////
void ChnlsReadPrint(void) {
val_Ch0 = analogRead(Ch0); // read Channel 0
val_Ch1 = analogRead(Ch1); // read Channel 1
volts_Ch0 = val_Ch0 * 3.3 / pow(2, 16); // conversion to volts
volts_Ch1 = val_Ch1 * 3.3 / pow(2, 16); // conversion to volts
counter_ms += 1;
if (counter_ms > 999) {
counter_ms = 0;
counter_s += 1;
}
String stringOne = String(counter_s, DEC);
String stringTwo = String(counter_ms, DEC);
String stringThree = String(volts_Ch0, 4);
String stringFour = String(volts_Ch1, 4);
String stringTot = String(stringOne + " " + stringTwo + " " + stringThree + " " + stringFour);
Serial.print(stringTot);
Serial.print("\r\n");
Serial.flush();
}
////////////////////////////////////////
// The main program will do nothing //
////////////////////////////////////////
void loop(void) {
}
////////////////////////////////////////
// END OF FILE //
////////////////////////////////////////
This code works until it happens the "jump" depicted in the following picture:
What LabVIEW does is simply:
- reading the serial port with VISA and obtaining a new line with a string
- split the string received into 4 numbers (2 integers and 2 float)
- append each new value into arrays
- plot the array in a xy graph.
Here is the Block Diagram:
I cannot figure out why these jumps happen after tens of thousands of strings...
Thank you in advance,
Leo