Toy_E Posted April 7, 2016 Report Share Posted April 7, 2016 (edited) 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. really,Encoder send 3000 pulse but My code has 99 pulse, Can someone help me?? This is my Labview simple code. Thank you very much Edited April 7, 2016 by Toy_E Quote Link to comment
hooovahh Posted April 7, 2016 Report Share Posted April 7, 2016 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.