Jump to content

Problem with LabVIEW for arduino


Recommended Posts

Hi everyone,


i have a problem with digital read pit.


i use LabVIEW  to control AC servo motor with Arduino Mega 2560


it can't read value(encoder) real time,it read value when while loop is active.


post-54593-0-24413700-1460019925.jpg


really,Encoder send 3000 pulse but My code has 99 pulseCan someone help me??


 


This is my Labview simple code.


post-54593-0-11653000-1460020383.jpg


 


Thank you very much :worshippy: 


Edited by Toy_E
Link to comment

Your code has several race conditions.  Do you need to write those DO before you read the DI?  Because the way it is written it will be a race to see who writes to those serial ports first.  You should serialize your code, since it is using one hardware port anyway.

 

You are talking to an Arduino over a serial bus.  Even at 115200 baud each command has several bytes of payload, then the Arduino needs to read those bytes, do some action (like read a DI) then send several serial bytes back, then your LabVIEW code needs to read those several serial bytes, and display it, then it will do this over again.  Your LabVIEW code is Windows based and non-deterministic.  Have you ever had a time when your mouse or keyboard just stopped responding in Windows?  What do you think your program will do when this happens?  You cannot perform reads on an Arduino this way, at any kind of deterministic rate.  Instead you should have the Arduino perform the reading, and maybe return something else instead of each pulse.  What if the Arduino just returned the number of pulses it saw in the last 1 second, or 500ms?  This can be coded on the Arduino side, and have a new function made that performs the task.  You can look at the Arduino source and see how other commands are implemented.

 

Another option might be to look at how the continuous AI works.  This causes the Arduino to take N samples that are hardware timed, and send them back to the Windows side.  You can try to make your own continuous DI read, or possibly just wire your encoder to the AI.  I don't know how fast the sampling rate is, but nyquist says you should be sampling at 2X the input rate minimum, or 10X in real world conditions.  So what is the minimum amount of time between pulses?  Then are you able to sample at 10X that rate with an Arduino?  I'm guessing not.  It really seems like some better hardware would be useful, one that has counter timers built in.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.