In the SetMinRate problem thread http://forums.usfirst.org/showthread.php?t=12050 there is a lot of discussion re encoder period averaging. Apparently, the encoders are set up to do a moving average of pulses to determine the average period used to derive rate. This is defaulted to one period but Joe H. has suggested a way to extend this to be any number of pulses between 1 and 127. This is a very valuable tool to handle the noise problems seen with encoders. I would like to use this thread to develop prototype changes to the Encoder class that we all can use. I suggest we add the following simple method to Encoder() class that goes something like this:
void Encoder::SetMovingAveragePulseCount(UINT32 max_count)
{ //check if 1=<max_count<=127 TODO: should throw an error flag here with message if max_count invalid
if (max_count<1) max_count = 1;
else if (max_coount>127) max_count = 127;
if(m_counter)
{m_counter->writeTimerConfig_AverageSize(max_count, &status);} //x1
else
{m_encoder->writeTimerConfig_AverageSize(max_count, &status);}//x2 OR x4
}
Also, since the encoder pulse widths are asymmetric, using a single pulse to determine periods leads to some very large rate errors. See thread http://www.chiefdelphi.com/forums/sh...ad.php?t=74763 . I would recommend that in InitEncoder(bool reverseDirection, EncodingType encodingType) that we always average over one full period as a default. I.E.
x1: m_encoder->writeTimerConfig_AverageSize(1, &status);
x2: m_encoder->writeTimerConfig_AverageSize(2, &status);
x4: m_encoder->writeTimerConfig_AverageSize(2, &status);// This is 2 because of FPGA error which reads only B chan for timing.
This should drop the noise rates by at least a factor of 3 when using x2 or x4.


Reply With Quote
