12-09-2020 12:11 PM
Hello,
I have a very simple task to perform but I am missing something. I need to perform an analog read (Arduino connected through the serial port) every millisecond (actually I would like to have the opportunity to change the sampling rate as needed, but as an example, let's stick with data points sampled every millisecond, 1 kHz).
Find attached a LabVIEW 2015 file with the basics to achieve what I need (I just created an example with random numbers to make it easier to share in the forum; no need for serial devices), but instead of having one data point every millisecond, I am having several points every millisecond. In addition, I am not getting 5000 data points (I expected that because of the 5 seconds period I used into the example). To make the producer loop run ligther, I used queue to transfer data to consumer loop.
How should I proceed to achieve what I need?
Thanks.
Dan07.
12-09-2020 12:22 PM
LabVIEW isn't a real-time operating system. As such, Windows (or MacOS/Linux, if you're using them) can and will decide to pause it from time to time to do system tasks. So timing things to the millisecond is not something you can do in Windows.
The timed loop is only truly able to do its timing as desired when it's run under a real-time OS. LabVIEW has this option but it's only for things like CompactRIO and the like, not a standard PC, and it's not free or cheap either:
Your best bet using a standard PC is to offload the timing portion of whatever you're doing to the device you're polling, and not count on LabVIEW itself for anything better than 1-second accuracy or so. I'm not sure if you can set up an Arduino to do that.
12-09-2020 12:48 PM
Luckily for you, your Arduino is spitting out data every 1ms. So that will determine your data rate, not your Windows system. Just use a loop to read the data as it comes across the serial port and a queue to send the data to another loop for processing.