Page 1 of 1

Matlab with 1047_1 - PhidgetEncoder HighSpeed 4-Input

Posted: Mon Jul 07, 2014 10:16 am
by celuti
Im trying to read from the encoder but the countValue variable is always equal to 0
My code is that of the example but including the for loop:

function encoderPositionCount()

loadphidget21;

handle = libpointer('int32Ptr');
calllib('phidget21', 'CPhidgetEncoder_create', handle);
calllib('phidget21', 'CPhidget_open', handle, -1);
for i=1:100
if calllib('phidget21', 'CPhidget_waitForAttachment', handle, 2500) == 0
disp('Opened Encoder')

%dataptr is a ptr where the polling function will store the position value
dataptr = libpointer('int32Ptr',0);

%handle is the handle ptr that is create when you create the encoder object
%0 is specifying encoder index 0 (the first encoder input) in this case
%passing the dataptr pointer to the function which will receive the position value
calllib('phidget21', 'CPhidgetEncoder_getPosition', handle, 0, dataptr);

%The value returned by getPosition is in encoder pulses. There are 4 pulses per encoder count, so you need to divide the value by 4.
countValue = get(dataptr, 'Value') / 4;
disp(countValue)
else
disp('Could not open Encoder')
end
end
% clean up
calllib('phidget21', 'CPhidget_close', handle);

Has anybody successfully readed encoders with matlab?

Cheers

Re: Matlab with 1047_1 - PhidgetEncoder HighSpeed 4-Input

Posted: Mon Jul 07, 2014 4:17 pm
by Patrick
You probably need to enable the encoder - the channel are powered down by default.

-Patrick

Re: Matlab with 1047_1 - PhidgetEncoder HighSpeed 4-Input

Posted: Wed Aug 06, 2014 1:45 am
by wackers90
How do you enable the encoder?
Did this work, I'm having a similar problem.

Andy

Re: Matlab with 1047_1 - PhidgetEncoder HighSpeed 4-Input

Posted: Fri Sep 25, 2015 10:03 am
by general
I am having the same problem. Can someone tell me how do I enable the device?