08-04-2015 11:42 AM
While using LabVIEW to code an optical sensor that is used to see when a coin passes through a passage, the code will initally run at a fast enough rate to read a coin falling through it. Yet as time goes on the while loop the sensor is within slows down to a point where it is not quick enough to see/detect a coin falling through. There are two while loops running in parallel, that may still be causing some issues in priority?
Thanks in advance,
Ben
08-04-2015 12:05 PM
Can you either post your VI or provide the settings you are using for the DAQ Assistant?
It looks like you're throttling your loop with the DAQ Assistant and it's hard to evaluate if the other loop could be interfering since you don't provide it.
08-04-2015 12:12 PM
Is this all you would need? It has more coding within it in order to turn on the conveyor belt that returns the coins to the hopper, which in turn will spit out the coin through the optical sensor's passage.
08-04-2015 12:15 PM
Some comments on your code
1. You should use shift registers to hold values from one iteration to the next. You should avoid using the local variables.
2. Your loop stops after 1000 iterations. Perhaps you should use a Stop button instead.
3. I tend to question the DAQ Assistant when it comes to memory issues (which is normally the cause of a loop slowing down). You might want to look into using the actual DAQmx API instead.
08-04-2015 12:31 PM - edited 08-04-2015 12:33 PM
Along with what crossrulz said, your acquisition to find the coin is a little funky. You're pulling a single sample each time that loop runs, so you're limited to the loop rate of that loop for find the coin.
Instead, you should configure your DAQmx task to do hardware timing at a fast(er) rate and then pull all available samples with each iteration. Then you can see within all of the new samples if there is a coin when there wasn't previously (same logic you currently have, but on a data set). For example, you can have this loop timed to run at 20Hz, but your data is acquired at 1000Hz and chunks of the data can be analyzed at a time. This way is much more efficient than what you're doing.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
08-04-2015 12:51 PM
Sorry, I'm fairly new to LabVIEW, DAQ assistant seemed like an easier option for the DAQ to LabVIEW interation. How would you write the code for the DAQmx as I seem to be getting errors when ever I inset a timer to set a sampling rate.
I made the changes crossrulz stated, by switching to a shift register along with including a stop button, just the DAQmx writing is left.
Thanks again.
08-04-2015 04:02 PM
You can set the timing up in the Express VI. Change acquisition mode to Continuous Samples. You'll then need to adapt the code to analyze an array of booleans instead of a single value like you have now.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'