11-18-2012 06:12 AM
Dear all,
I have an MCU which performs spectrum analysis, the magnitude is stored in an array which I send serially to my PC. I would like to plot this on a graph but I've run into a problem.
I wrote a test program which continuously sends an array containing numbers from 0 to 7.
int data[8]={0,1,2,3,4,5,6,7};
while(1)
{
for (int i=0;i<8;++i)
{
while (!(UCSR0A & (1 << UDRE0)));
UDR0 = data[i];
}
}
I expect to see a linear function on the graph, as seen on my first screenshot.
However, the plot keeps shifting from right to left just like on a Waveform Chart and I get the sawtooth like plot seen on the second screenshot.
How can I stop the graph from shifting?
Regards,
Adam
11-18-2012 10:48 AM
Hi Adam,
when you want to plot your data beginning with zero and ending with largest value you should also adapt your data aquisition to "trigger" at the correct data points...
Right now you just fetch the data coming from the serial port. You don't take any measures to analyze those data, you just read in the bytes from the buffer. Now you wonder about missing synchronization...
Possible solution:
- send a "End of transmission" char and use it as TermChar for the InitSerialPort vi!
- Get rid of the BytesAtPort node, it's most of the times not needed for serial communication!
- Analyze your data when you need a certain plot...
11-18-2012 11:07 AM - edited 11-18-2012 11:08 AM
Thank you for the help.
I'm thinking about assigning two start/stop characters and sending them before and after the array elements.
The first one would start the waveform plotting which would be in a while loop that is stopped by the second, closing character.
The problem is I don't know how to check every byte in the buffer and determine which one is the designated start/stop character.
11-20-2012 12:05 PM
Can anyone help me please?
11-20-2012 12:22 PM - edited 11-20-2012 12:23 PM
11-26-2012 09:13 AM
I managed to modify my VI to display the data the way I wanted, however, there's a new issue.
The graph keeps flickering. How can I get rid of this problem?
11-26-2012 09:15 AM
11-26-2012 02:57 PM
I attached the VI.
I don't know how to give you example data though.
My MCU is continuously sending a 63 element array, containing the magnitude of a signal's spectrum.
11-27-2012 02:30 AM
Hi Adam,
your VI is reading the serial buffer each 150ms. Then it cuts the received string and converts the string to U8 array. That U8 array data is presented on the graph - roughly 6 times per second.
What else do you expect than flickering?
11-27-2012 12:01 PM
I see.
The reason why I did not increase the delay is because I'd like to plot the spectrum's magnitude in real time, so if there is a change in the signals frequency it is immediately displayed.