Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder Feedback question.

I am reading encoder feedback using Visual Basic and an E-Series Board. My problem is as follows: when the motor is moving in the negative direction and the encoder is counting down towards zero counts what is the best way to start displaying the counts as negative when it passes zero?
0 Kudos
Message 1 of 2
(2,557 Views)
Since the STC is a 24-bit counter, it's a bit awkward to display the counts as negative. The least complicated solution would be to simply have a case statement that divides the counter values such that half are positive and half are negative.

value1 = measuredValue;
value2 = 2^24 - value1

if(value1 < value2)
{
reportedValue = value1;
}
else
{
reportedValue = -1 * value2;
}

The only time this method would break down is when the encoder moves in a positive direction too far (2^12 ticks) in which case the numbers would go negative, but this isn't a common issue.
0 Kudos
Message 2 of 2
(2,557 Views)