In my application I monitor a quarature encoder and trigger an analog read at certain count values. I seem to be losing encoder counts while the analog read takes place. If I reduce the A/D Settling Factor from 8 to 1 the problem is improved but not fixed.
More specifically, I am using a surface encoder on a larger, rotating drum and I am taking 36 measurements per drum revolution and continuing this for five revolutions. As the code runs now, it takes a little more than one revolution to complete each group of 36 measurements so I precess a little on each measurement group. As I mentioned above reducing the settling factor improves performance. Commenting out the analog read section of the code fixes the problem and there is no precession.
Here is the measurement loop. If I comment out the section in red there is no precession. So it appears the quadrature counter stops while the analog read takes place.
trigcnt is a vector of trigger points. For example if the encoder produced 3600 counts per drum revolution and I wanted to make 36 measurements around the drum trigcnt would equal [100, 200, 300, . . .2600]
I am using a Labjack U6 and it is up to date.
for j in range(0, num_revs):
for i in range(0,num_pts):
while count <= trigcnt[i]:
count1 = u6d.getFeedback( u6.Timer0( UpdateReset = False, Value = 0 ) )
count = count1
if count > 2**31:
count = 2**32 - count
count = abs(count)
if i == num_pts-1: #reset counter each rev
count1 = u6d.getFeedback( u6.Timer0( UpdateReset = 1, Value = 0 ) ) #Reset Counter
ADC_val = u6d.getFeedback( u6.AIN24(0, ResolutionIndex = 7,
GainIndex = 0, SettlingFactor = 1,
Differential = True ) )
temp_ADC = u6d.binaryToCalibratedAnalogVoltage(0, ADC_val)
run_out[i][j] = 20*(temp_ADC)
count_tab[i][j] = count
print "Rev. ", j+1, "Measurement ", i+1, " is ", run_out[i][j], "um", "at", count
count = 0