- Documentation Check: Refer to the latest MATLAB documentation for your version to confirm that InitialCount is a supported property for encoders with the Data Acquisition Object interface for your specific NI device.
- Compatibility: Ensure your hardware and its drivers are fully compatible with the version of MATLAB you're using. Sometimes, newer features or changes in behavior can be related to driver or firmware updates.
Encoder InitialCount Data acquisition object
2 次查看(过去 30 天)
显示 更早的评论
I have switched over to use the data acquisition object instead of the session. For encoders, there is a property called initial count. It enables the user to set the starting value for a counter. It is important for linear position measurement, as if you start at zero and go negative, the counter would go to 2^32, then work down from there. It allows me to set the value, however it does nothing with the value. The encoder count still starts at zero.
Here is a pseudocode to demonstrate:
app.ni.dq=daq("ni") %Create object
app.ni.dq.Channels(1).EncoderType=app.instrument.Inputs.TerminalConfig{ii};
app.ni.dq.Channels(1).InitialCount=2^30;
Then, when I run this in the background, the encoder still starts at zero. Therefore, negative moves beyond zero start over at 2^32... Am I doing something wrong? This used to work with data aquisition sessions.
0 个评论
回答(1 个)
Aditya
2024-3-21
Switching from Data Acquisition Sessions to Data Acquisition Objects in MATLAB introduces some changes in how things are handled, including setting properties like InitialCount for encoders. The behavior you're experiencing, where setting the InitialCount does not seem to affect the starting value of the encoder count, could be due to a few reasons. Let's explore some steps and considerations to troubleshoot and potentially resolve this issue:
1. Verify Property Support
First, ensure that the InitialCount property is supported and behaves as expected with the Data Acquisition Object (daq) interface for your specific hardware. The support and behavior might vary between different versions of MATLAB and hardware devices.
2. Correct Property Setting
Ensure the property is set correctly in your code. Your pseudocode seems correct, but it's always good to double-check for typos or incorrect object references. Also, ensure that the property setting is not being overwritten or reset somewhere else in your code before the acquisition starts.
3. Property Application Timing
With the Data Acquisition Object interface, the timing of when properties are set can sometimes matter more than with the session-based interface. Ensure the InitialCount is set after adding the channel and configuring the encoder type but before starting the acquisition.
4. Test with a Simplified Setup
Try simplifying your setup to isolate the issue. Use a minimal script that only creates the Data Acquisition Object, adds one encoder input channel, sets the EncoderType and InitialCount, and then immediately reads the encoder value. This can help determine if the issue is with the property itself or how it's being used in the context of your larger application.
Here's a slightly revised version of your pseudocode with explicit steps:
% Create Data Acquisition Object
dq = daq("ni");
% Add encoder input channel
ch = addinput(dq, 'Dev2', 'ctr3', 'Position');
% Set Encoder Type (assuming 'app.instrument.Inputs.TerminalConfig{ii}' is valid)
ch.EncoderType = 'X4'; % Example, replace 'X4' with your specific encoder type
% Set Initial Count
ch.InitialCount = 2^30;
% Start background acquisition to test (simplified example)
start(dq, "Duration", seconds(10)); % Adjust duration as needed
% Read and display the initial value (after some delay to ensure acquisition has started)
pause(1); % Short pause to ensure acquisition starts
[data, timestamps] = read(dq, seconds(1), "OutputFormat", "Matrix");
disp(data(1));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simultaneous and Synchronized Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!