01-26-2025 02:45 PM
Hi all,
I know that encoder questions are quite common here, but I have looked through many of the topics and really am stumped.
I am trying to run an encoder with a 100ns pulse width at peak velocity. I started from the basic encoder example provided by LabVIEW, but I cannot get sampling to run any faster than 2000Hz.
I tried to introduce a sample clock outside my while loop that used the 20MHz internal clock, but I was not able to divide it down (error 200141), and if I set sampling to 20MHz, the buffer would be filled due to the amount of data. In other cases, I was able to record position data, however, the time stamp would only be recorded for 5ish samples, then continue as a 0 output.
I believe I do need to sample faster because I am noticing quite large skips in the data that should not be appearing otherwise.
I have been through some of the beginner tutorials, but a lot of the DAQmx blocks aren't making a whole ton of sense to me as far as how to use the base/internal. If there are other good tutorials out there to introduce me to the basics of counters and sample clocks, I would appreciate it. Just trying to take the time to learn and understand how to do this right.
Data is being recorded on a USB-6210 and the computer is running Windows 11 with LV 24.
Any help is appreciated!
01-27-2025 12:19 PM
Hi all,
I have done a few updates to my code and now I'm getting even stranger results. I have no clue why the encoder data is being inverted as seen in the image below, in addition to the 0 value readings.
01-27-2025 02:58 PM - edited 01-27-2025 02:58 PM
I was i the same situation when I realized that a 3$ IC can count the pulses easily. My advice is to make/buy discrete hardware for that job.
01-27-2025 03:20 PM
Thanks for making me feel a little less crazy for trying to get this to work. I've looked at the US Digital QSB (will also allow me to have the differential signal from the encoder rather than being limited to the single). I have also looked at the RLS E201-9 which is a little more expensive.
However, the issue is that I need to sync up the recordings with a force transducer, servo, and high speed camera, which it seems like it will be a different pain to try to get the IC to sync up with the DAQ clock.
01-27-2025 03:36 PM - edited 01-27-2025 03:42 PM
Your issue is that you're misunderstanding what the sample clock does for an encoder device. The encoder counter's sample clock does NOT control when it counts pulses, it counts when you read the VALUE of the pulse counter.
The encoder counter will count pulses as fast as it will count pulses. There are some limits related to the internal base clocks, but generally speaking you don't need to worry about those, and that's NOT the sample clock.
The counter will count as fast as it needs to to keep up with your pulses. The *sample clock* will then read the value of that counter to an external buffer which is read by DAQmx Read.
For example: Let's say your encoder is increasing at a rate of 1000 counts per second. If you sample the system using a 10 Hz sample clock, you'll get readings of 0, 100, 200, etc. If you sample at 100 Hz, you'll get readings of 0, 10, 20, 30, etc. The internal counter is read into the buffer at each sample clock pulse.
Unfortunately, you're using an M series device, which doesn't have dedicated sample clock sources, but fortunately, you're synchronizing it with other analog devices. This means you can route the analog sample clock to the counter input, and read the analog inputs simultaneously* with your sample clock inputs.
See this example:
(That's a digital input, but you can switch it to counter input instead).
*Your device doesn't do simultaneous sampling of all of the analog input channels, so there will be a TINY delay between channels, but it's generally something you can ignore.
01-27-2025 03:41 PM
@Sayre wrote:
Hi all,
I have done a few updates to my code and now I'm getting even stranger results. I have no clue why the encoder data is being inverted as seen in the image below, in addition to the 0 value readings.
That's because your Build Array terminals are wired backwards- flip those around. You're prepending new data so it's before the old data. You almost certainly want to stick it on the end, not the beginning.
Also, delete the input to the "Source" input on the AI Voltage's Sample Clock function, DAQmx figures that out on its own. You're basically rerouting the AI sample clock correctly here.
Also, I'd clean up your code, don't maximize the front panel and block diagram, and don't use the flat sequence structure. That'll help others follow your code better.
01-27-2025 05:08 PM - edited 01-27-2025 05:10 PM
If you can get it done in pure software or this is just an assignment, fine - don't read further.
Assuming you have to trigger the camera in fixed intervals. A decoding chip connected to one or more timer IC can give you the camera triggers for free. You can even adjust the intervals using jumpers. Those timers could then trigger your DAQ for pressure transfucer reading. Your servo has probably it's own encoders and a motorcontroller and is most likely not driven by your DAQ, unless it is a toy thingy.
01-27-2025 05:23 PM
Thanks everyone for the feedback, as I’m sure it’s evident I’m very green to all this. I am going to go back to basics and see if I can establish a firm baseline rather than trying to piece together what I’m seeing on the forums.
I will try to implement some of these solutions tomorrow and see what else I can figure out. I am trying to establish a good baseline for a program to run our lab in the future rather than making a hodgepodge solution.
I will update this post as I learn more/improve the code as suggested.