View Single Post
  #1   Spotlight this post!  
Unread 21-02-2009, 09:58
davidc10 davidc10 is offline
Registered User
FRC #0423
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Pennsylvania
Posts: 20
davidc10 will become famous soon enough
AnalogModule->GetAverageValue() gives wrong results if polled too fast

I have found that if I try to read from Analog Module 1 while the battery reading jumper is on it, I occasionally get a value of 1628, even if the signal line is grounded.

This only happens if the battery jumper is in place, and if a Wait(.005) is omitted from the read loop.

I have produced a minimal Wind River project to demonstrate this. Here is the main routine, but the zipped project file is attached:

class AnalogModuleBugTest : public SimpleRobot{
Timer timer;
AnalogModule *aMod;

public:
AnalogModuleBugTest(void):
timer()
{
aMod = AnalogModule::GetInstance(1);
GetWatchdog().SetExpiration(0.1);
timer.Start();
}

void Autonomous(void){
double deltaT = 0;
float sampleRate = 0;
INT32 avgValue;
bool error = false;
timer.Reset();
sampleRate = aMod->GetSampleRate();
while (IsAutonomous())
{
GetWatchdog().Feed();

deltaT = timer.Get();
if (deltaT > .02){
avgValue = aMod->GetAverageValue(6);
if (avgValue > 500){
error = true; //<- put breakpoint here <<<-should never get here!
}
timer.Reset();
}
//Wait(.005); // (.005 seems OK) (.0005 has error) (.001 has error)
}
}

... balance of code not relevant.

Here is the complete description, which is also included in the zip file ( and the line numbers will make more sense in the IDE):

This applies to Analog Module 1 only.

Although channel 6 is used in this example I have duplicated the
results for all other channels, except 8 which is battery.

Setup:
(1) Place a jumper on Channel 6 of AnalogModule 1 (slot 1) between
ground and signal, so the voltage and avgValue should be 0, + noise.
Typical value is -4.

(2) Battery jumper is IN place on the breakout board.

(3) Breakpoint is set on line 33 "error = true".

(4) Line 37 "Wait(.005)" is commented out.

(5) Program is run as Debug Kernal Task - with option to attach spawned
tasks checked.

Result:
Breakpoint is reached within 3-4 minutes, often sooner, with
avgValue near 1630. If the program is resumed from the breakpoint,
the breakpoint is reached again within a similar timeframe.

Comments:
(1) With Wait(.005) at line 37 active the breakpoint was not reached
in a 2 hour span.

(2) With Wait(.0005) the breakpoint was reached as usual.

(3) With battery jumper OUT the breakpoint was not reached in several
hours. (Program was restarted after removing jumper).

(4) With battery jumper OUT - and the breakpoint not having been
reached for 20 minutes - the jumper was put IN while the program was
running. The breakpoint was reached with 2 minutes.

(3) Same results if using a gyro or accelerometer on channel 6 (or other
channel, including accumulator channels), whether using a live signal
or jumper to ground.

(4) SampleRate is 50000 as is, slightly higher ~51000 if a gyro is used due
to the oversampling/sample rate conversion.

(5) Module 2 (slot 2) seems not to be affected, possibly because placing
the battery jumper on that module has no effect.

Based on these tests it appears that there is a bug when the battery
jumper is in place on module 1.

Regards,
David
Attached Files
File Type: zip AnalogModuleBug.zip (7.8 KB, 30 views)
Reply With Quote