LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Minimal wait interval in serial read loop

Solved!
Go to solution

Hello,

 

I would like to ask if it is possible to read data from serial port in loop every 17ms? If so, how should be Serial Read and loop managing it set.

 

I'm reading from Arduino Uno board which can work on up to 115200 kbs baud rate. Arduino is sending integrals (0-3) every 17ms. Now I fail to read them separately (every integral one by one, I get numers like 123, 231, 12, instead of 1, 2, 3 etc.), but this may be due to other stuff I do in the loop. I will elaborate more on my VI later - now I would like to know, if it is possible using LV 2011 + VISA to read from serial every 17ms. What bothers me most is that I saw many times on this forum, that people suggest not to go below 10ms wait time in Serial Read loop (same as in Basic Serial Read and Write provided in Ni examples). Should the loop wait for x ms, where x is divisor of 17ms ?

0 Kudos
Message 1 of 9
(4,415 Views)
Solution
Accepted by topic author Chudy

Do you mean you are reading integers and not integrals? Are you sending a single byte or more? If it's a single byte, then just set that as the number to read. Don't put in any wait function and don't use the VISA Bytes at Serial Port. The VISA Read will automatically terminate when a single byte is read. Are you sending a terminator after the number? The wait in the example has nothing at all to do with reading a constant data stream and in fact, with a terminator is completely unnecessary. 

0 Kudos
Message 2 of 9
(4,409 Views)

Integers of course, not integrals. Sorry for my misleading english 😕 Yeah, its a single byte and at the moment I'm not using terminator. Your suggestion seems simple and easy, I will try to change my VI according to it and post the results.

 

 

0 Kudos
Message 3 of 9
(4,400 Views)

I have done as You had suggested me. I made this serial read as simple as possible. I added some function to measure time, and I don't know if it works well. I get different measurments depending on what I set in "elapsed time" - really, I don't know how to set it correctly. new data is coming every 17ms. Strange thing is, no matter what I set, the measurements shows that some data was skipped (because read time is above 17ms), however I keep getting all the data.I attache You my vi.

0 Kudos
Message 4 of 9
(4,374 Views)

Try a simple tick count like the attached and see if the time is more consistent.

0 Kudos
Message 5 of 9
(4,364 Views)

Great thanks, Your time measurement works well I suppose. I get times varying between 15ms and 22ms.

 

I still find this a bit strange - my Arduino is coded to wait 17ms and send data. Does it mean 22ms between loop iterations results in data lose or it is actual time arduino needs to send data. If no data is skipped I think its the 2nd option (arduino sends data at various speed), am I right?

 

What I will try to find out next is if I can display various pictures every 17ms. I have already made vi for that (there is a thread on this forum about that) but worked on ~300ms refresh rate. Don't know if this is possible, but this issue probably deserves another thread...

 

Thx for Your help once more Dennis Knutson

0 Kudos
Message 6 of 9
(4,360 Views)

sorry for double post, didn't make it on time to edit my last.

 

I have checked it with various waiting times coded into my arduino board, and time measurements varied +/-4ms in every case, so I think arduino board fails to provide constant repeatable intervals between sending data

0 Kudos
Message 7 of 9
(4,357 Views)
Are you doing this on Windows? If so, it is not a determinent OS so there is going to be jitter. It is most likely jitter on your processor, not the hardware.
0 Kudos
Message 8 of 9
(4,345 Views)

I'm testing it on my laptop right now and it has windows xp installed. So this is due to OS? I would need some RTOS to make it work well ?

0 Kudos
Message 9 of 9
(4,335 Views)