Hi everyone
I'm using an optical encoder to keep track of how much my stepper motor has rotated, however I am encountering a problem which I think has a simple solution but I haven't been able to figure it out or find anything online.
My quadrature encoder is connected to a NI 6229-USB DAQ unit and by using the code below, I am able to read data from the encoder.
----------------------------------------------------------------------------------------
s = daq.createSession('ni');
ch = s.addCounterInputChannel ('Dev3', 'ctr0', 'Position');
ch.EncoderType = 'X4'
ch =
Data acquisition counter input position channel 'ctr0' on device 'Dev3':
EncoderType: X4
ZResetEnable: 0
ZResetValue: 0
ZResetCondition: BothHigh
TerminalA: 'PFI8'
TerminalB: 'PFI10'
TerminalZ: 'PFI9'
Name: ''
ID: 'ctr0'
Device: [1x1 daq.ni.DeviceInfo]
MeasurementType: 'Position'
----------------------------------------------------------------------------------------
When I tell my motor to turn in its positive direction (in this case clockwise), the encoder works fine and I get the right angle by using:
(s.inputSingleScan/(4*1024))*360
where "s.inputSingleScan" gives me the count. The encoder also works if I then tell the motor to in its negative direction, for example if I initialise the session and tell the motor to go to 10degrees and then 5degrees, I get the right value. However, if I initialise the code and I tell the motor to go in the negative direction first, I get nonsensical values i.e. if I tell it to go from 0 to -5 degrees I get an angle of 4x10^6... Any ideas why this is happening?