Matlab with 1047_1 - PhidgetEncoder HighSpeed 4-Input

Legacy support with Phidget21
celuti
Fresh meat
Posts: 1
Joined: Wed Jul 17, 2013 4:34 am
Contact:

Matlab with 1047_1 - PhidgetEncoder HighSpeed 4-Input

Postby celuti » Mon Jul 07, 2014 10:16 am

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

User avatar
Patrick
Lead Developer
Posts: 3078
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

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

Postby Patrick » Mon Jul 07, 2014 4:17 pm

You probably need to enable the encoder - the channel are powered down by default.

-Patrick

wackers90
Fresh meat
Posts: 3
Joined: Wed Aug 06, 2014 1:36 am
Contact:

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

Postby wackers90 » Wed Aug 06, 2014 1:45 am

How do you enable the encoder?
Did this work, I'm having a similar problem.

Andy

general
Fresh meat
Posts: 1
Joined: Fri Sep 25, 2015 10:01 am
Contact:

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

Postby general » Fri Sep 25, 2015 10:03 am

I am having the same problem. Can someone tell me how do I enable the device?


Return to “Matlab”

Who is online

Users browsing this forum: No registered users and 0 guests