LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delay in write in Arduino?

Hello all,

 

I am pretty new to labVIEW. I am using LINX toolkit to program Arduino.

 

I am using Arduino to create some controlling signals. However the output signal read from the Arduino seems to be delayed. I made a test program as below that just reads a clk and writes it in another pin but the written signal is delayed when I check it with scope, and not at all like the read signal.

 

mg7077_0-1682372049439.png

 

 

Is there any mistake I am making?

 

PS:

Signal read(clk, ~100kHz):

Image.jpeg

Signal Write:

 

 

Image1.jpeg

 

0 Kudos
Message 1 of 14
(1,903 Views)

I haven't used LINX myself, but it looks like you're trying to read and update a 100kHz clock, is that right? If so it'll never get there. The LINX toolkit loads some code on the Arduino that lets it read and write values to the board. It communicates back and forth to the LabVIEW computer. I'm not sure what kind of loop rate you can get with this setup but it's likely to be 1 kHz at best. Maybe things are much faster but it's definitely not going to hit 100 kHz.

0 Kudos
Message 2 of 14
(1,890 Views)

I would have to concur with Bert, LINX is slow compared to native Arduino code.

 

It has been a while but I think there is a VI in LINX that reports the loop rate. 

 

I was astonished how slow basic LINX code ran, I believe it was in the 100Hz range.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 14
(1,839 Views)

The fastest transition in your scope capture looks like about 10 ms, which agrees with RTSLVU's thought it's in the 100 Hz range.

 

Your Arduino loop is probably pretty repeatable, so if it's running at 100 Hz, and your clock is running at 100 kHz, then missing 4-5 clock signals makes sense. Basically you're happening to read the input signal every time it's high.

 

If you're not familiar with how that works, imagine that you have a buzzer that fires every hour. When the buzzer fires, you look at your watch and record the time. The first time it fires, you see 10:43. The second time it fires, you see 11:43. The third time, you happen to delay a bit and see 12:44. Looking at this pattern, you might assume that your watch's minute hand only moves once every 3 hours, but the reality is you're reading its position at exactly a multiple of the minute hand's motion.

 

Reading a 100 kHz clock at 100 Hz means that exactly 1000 cycles go by between reads. If everything was perfectly consistent, you'd never see a change- but you DO see some changes, so that means it's not perfectly consistent (which is accurate since you're running on Windows which isn't deterministic down to the millisecond).

Message 4 of 14
(1,833 Views)

Thanks for your replies.

 

So basically I can not get signals and process them and write them using LINX with frequency more than near 100Hz!

0 Kudos
Message 5 of 14
(1,829 Views)

Get signals and react? No. Record signals? Yes, you can go higher, but you need to use continuous acquisition. See https://forums.ni.com/t5/LabVIEW-Interface-for-Arduino/Max-Sample-rate/td-p/3439339

 

You really can't get much better than 1 kHz (with ANY device) on Windows anyway, and even that isn't guaranteed. Windows may decide to check for updates, or play a video, or any number of things that the computer decides are a more important task.

 

If you explain a bit more of what you're doing we might could help, but I'd bet you'll wind up needing to run on actual Arduino code (or maybe Raspberry Pi).

0 Kudos
Message 6 of 14
(1,818 Views)

Thank you Bert for replying.

 

 

What I want to do is to get a signal as clk and reset signal and a binary code and generate clk and reset and data flow for an 8 bit shift register.

 

I wanted to get a clk from other chip (100kHz), reset and code from VI control window. So the clk that comes out and goes into shift register, must follow the input clk in reset mode and for 8 clk (since all data is in) and then be stuck to high so the data is locked in shift register. (data moves with positive edge of clk).

 

I was hopping I can do that using the Arduino and LINX. But I need to have clk frequency of 100KHz and higher(1MHz). 

0 Kudos
Message 7 of 14
(1,801 Views)

If you want to use LabVIEW with those frequencies you'll need an FPGA like those on the cRIO chassis. It's a bit out of my area of expertise but you'll likely need some kind of DSP or FPGA at those frequencies.

 

Although that said... this sounds like you're trying to implement some sort of SPI (or similar) protocol. You can buy USB to SPI (or I2C or whatever) converters for very cheap and they'll handle a lot of this for you.

0 Kudos
Message 8 of 14
(1,770 Views)

I tried to change the clock for the whole operation to 100Hz. But I still don't get the clk from output of Arduino in the coherent 100Hz frequency!(the signal that goes into labView and is written back with digital write)

 

Does that mean I need to further decrease the clk frequency? LabVIEW can't even handle a 100Hz signal processing?

0 Kudos
Message 9 of 14
(1,705 Views)

The Nyquist criterion (briefly) says that to adequately reproduce a signal of frequency A you will need to measure it with a frequency of 2xA. If the Arduino can sample at 100 Hz, then the best you can do is 50 Hz.

 

The other problem is the aliasing that I mentioned above. If you read a regular wall clock exactly once an hour, you'd think the minute hand was broken. If you sample a 100 Hz signal at 100 Hz, you won't ever see a change.

 

Pretend it's a blinking light that you only look at once in a while. Let's say this lightbulb turns on for one second, then off for one second, then on for one second, etc. (in other words, a 2 second period, or 0.5 Hz frequency). If you look at the light once every 2 seconds, it will appear to be either always on or always off. This is because you're not looking at it frequently enough. If you look at it once per second (1 Hz, or 2x the cycle rate) then you're guaranteed to see that it's off and on in subsequent looks.

 

Try something like 10 Hz, then increase the frequency on your signal generator until it starts to show errors.

 

You're really using the wrong tool for the job here. The Linx toolkit is meant for hobby usage, nowhere near the rates you're looking for. LabVIEW can handle 100 Hz loops on Windows, but you have a big bottleneck in that you're using the Linx toolkit on an Arduino.

0 Kudos
Message 10 of 14
(1,699 Views)