07-13-2017 10:27 AM - edited 07-13-2017 10:40 AM
I want to write low(0) and high(1) sequentially to an Arduino pin via Labview.
So essentially I want the labview to do this with the arduino:
void loop() {
for (int i=0; i<6400; i++)
{
digitalWrite(DIR,LOW);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}
}
The trouble is, I can set the delay between low to high, but I dont know how to set delay between high to low.
Solved! Go to Solution.
07-13-2017 11:11 AM
Use the Wait function inside of a Flat Sequence Structure. Do note that you are not going to get into the microsecond range of delay on a PC. Even the millisecond range will be unreliable.
07-13-2017 11:15 AM
Thank you, now it works.
And yes, wait.vi cannot go below 1ms, which is not optimal. Is there a way to over come this?
07-13-2017 11:30 AM - edited 07-13-2017 11:31 AM
All you need is a FOR loop with a 50us delay and alternate the data based on bitwise operation of the iteration terminal. Spin it twice as many times. 😄
If you have hardware time IO, I would generate the 01 array once using an autoindexing output tunnel and write the array afterwards using properly configured IO. To get the desired speed, you probably would need to run this natively on the arduino.
07-14-2017 07:13 AM - edited 07-14-2017 07:32 AM
@altenbach wrote:
All you need is a FOR loop with a 50us delay and alternate the data based on bitwise operation of the iteration terminal. Spin it twice as many times. 😄
If you have hardware time IO, I would generate the 01 array once using an autoindexing output tunnel and write the array afterwards using properly configured IO. To get the desired speed, you probably would need to run this natively on the arduino.
how does the wait(ms) function wait 50us (microseconds)?
i have never observed that.
Update: i guess that was a typo, otherwise i would really be interested
07-14-2017 11:58 AM - edited 07-14-2017 12:03 PM
No, the code shown will wait 50ms. I could have placed a black box with the letters 50us on it... :). On LabVIEW RT/FPGA we have other waits that allow much higher resolution.
We cannot have sub-ms waits on windows. One rough approximation would be to wait 1ms every 20 iterations, but that still would get very jittery on a multipurpose OS.
I don't know what kind of waits are available on Arduino when running deployed LabVIEW code.
My other suggestions was to remove the wait, autoindex the signal at the right loop boundary, and "play" the resulting array hardware timed at once (no loop). Not sure if that's available on Arduino.
07-14-2017 12:04 PM - edited 07-14-2017 12:05 PM
sorry i took you literal .. somehow i misunderstood, that this was an example, but you haven't used the proper RT equivalent .. my bad
thx for clearing that up
07-14-2017 12:09 PM
I would have, but only plain LabVIEW on this rig here. I guess I could have copy/pasted an image of the right wait from the online help. 🙂
07-14-2017 02:39 PM
Thank you people! Since wait.vi dosnt support higher precision, I will try another method. Namely to send a boolean to Arduino and if it gives HIGH, then run a piece of code from a sketch. Which means I am no longer generating pulse signal from Labview, but from the Arduino it self instead.
07-14-2017 03:22 PM
You might want to check out these Timer libraries: https://playground.arduino.cc/Code/Timer1 if you have a Mega. I remember doing some PWM with an Arduino at one point and those were useful, though it was a long time ago so I don't remember much.