Log in

View Full Version : Analog input delay problems


LinuxMercedes
22-01-2009, 23:27
I've been messing with the analog inputs on both the driver's station and the cRio itself and have noticed a few weird things.

First, it seems to provide values between 0 and 1000. I'm assuming that this is multiplying the actual voltage by 200 since it would be kinda creepy if it was putting 1000 volts through those inputs...

Second, they seem to be mildly inaccurate. A full-open pot reads values between roughly 990 and 1100. This might be just the pot that I was using.

Third, and most importantly, there is a HUGE lag between changing the pot and getting the reading back at the debug console. It's roughly 20 seconds. We've determined that it's not a printf() buffer that's filling up faster than we can read it. Does anyone know why we'd have a delay like that, and how could we fix it?

Thanks!

MikeDubreuil
22-01-2009, 23:43
The reason you are seeing 1000 is most likely because the DS has a 10 bit A/D (http://en.wikipedia.org/wiki/A/D). Therefore, the data range is 0 to 1024 (2^10). Note: this is just a guess because the spec sheet in the control system does not indicate how large the A/D is.

With most potentiometers (even joysticks) you will notice they don't use the entire range. This is due to many reasons and you should plan accordingly in your software.

As for the lag... I'm pretty stumped. You'll have to provide more info for us to help you on that one.

LinuxMercedes
22-01-2009, 23:51
Ok...I'd figured that there was something going on so that it didn't just give us the voltage =]

What information do you want to know? I haven't the slightest clue where to start attacking this problem, to tell you the truth. This is my first (and sadly last--should have gotten into this 2-3 years ago) year with FIRST, although I've been coding for 4-5 years =]. So don't assume 'well, he must have done that, because everyone knows to do x when they have trouble.'

Thanks!

Jared Russell
23-01-2009, 07:11
Do you have access to an oscilloscope? I would hook the pot up to that and watch the wiper voltage change as you turn it. If you see a delay there, you probably have a wiring issue or a busted pot.

Also, you can verify that you have the right connections. One end should be +5V, the other end should be GND. The middle (the wiper) is where you are making your reading.

Lastly, what is the resistance of the pot? You may have an RC-type delay somewhere in the circuit.

drkiraco
23-01-2009, 19:14
Are you using the 'Get Voltage' or 'Get Average Voltage'? My guess is that you are using 'Get Average Voltage' with a low sample rate and a high number for the oversample value (like 10). I say this because when you use the the oversample at a value of N, it adds the previous 2^N values together (and does NOT divide by 2^N either!) So that explains the high values. You should be getting outputs in volts. Plus, since you're averaging together a whole bunch of values, there is going to be a big delay while the average value catches up to the new input value. If you have a low sample rate (as determined by the set sample rate vi, not how frequently your loop is running), 2^10 averages could concievably be 20s. I'm pretty sure that the sample rate vi sets the rate for the whole module, so the same rate per channel is 1/8 of that.

Now, if this doesn't help you out, then try this: make a copy of your code and delete everything but the bit about reading the analog value and displaying (i.e. delete all the camera stuff and all the drive stuff and everything). If that fixes it, then add stuff back into until you find the culprit. If not, then post that code here and maybe somebody can spot your error.

/* Daniel */

I've been messing with the analog inputs on both the driver's station and the cRio itself and have noticed a few weird things.

First, it seems to provide values between 0 and 1000. I'm assuming that this is multiplying the actual voltage by 200 since it would be kinda creepy if it was putting 1000 volts through those inputs...

Second, they seem to be mildly inaccurate. A full-open pot reads values between roughly 990 and 1100. This might be just the pot that I was using.

Third, and most importantly, there is a HUGE lag between changing the pot and getting the reading back at the debug console. It's roughly 20 seconds. We've determined that it's not a printf() buffer that's filling up faster than we can read it. Does anyone know why we'd have a delay like that, and how could we fix it?

Thanks!

LinuxMercedes
23-01-2009, 20:19
Daniel:

I'm using GetValue(). I'll try GetVoltage(). I know it's not a problem with my loop taking 20 seconds to execute because it will printf() the value of the pot several times between changing the pot physically and the voltage change being registered by the software.

Abwher:

Thanks for pointing those things out...as a software guy, I tend to assume there's a software problem, not a hardware problem. I'll check those out tomorrow, although I might have to use a voltmeter of some sort since I don't think we have a 'scope.

PhilBot
23-01-2009, 20:51
How fast are you looping?
If you printf too fast, won't you overrun the debut port?
Are you using the serial port at 9600?
Remember..... Only 1000 charaters per second.
I'd suggest a 100 ms delay per loop to prevent debug overload.

LinuxMercedes
24-01-2009, 00:29
I was using the network terminal and had it set to print once every 1000 loops, which came out to about 1/sec.

LinuxMercedes
24-01-2009, 22:00
Well, I suppose this problem is moot now. I hooked up a pot today to drive a motor speed, and it worked fine...

I think it might have been caused by cosmic rays, since I've never had this happen when printf()ing anything else. =]

Jared Russell
24-01-2009, 22:25
Speaking of cosmic rays...

http://imgs.xkcd.com/comics/real_programmers.png

LinuxMercedes
25-01-2009, 21:20
I love XKCD. "A bunch of rocks" is probably my favorite (http://xkcd.com/505/), but for some reason this (http://xkcd.com/530/) one seems particularly relevant to the current company...

Beakerone
10-02-2009, 20:36
Well, I suppose this problem is moot now. I hooked up a pot today to drive a motor speed, and it worked fine...

I think it might have been caused by cosmic rays, since I've never had this happen when printf()ing anything else. =]

Glad the cosmos is aligning for you. :)
i was wondering - we are using pots also - one on the driver station which we can get the AnalogIn value (1-1024) which we are trying to compare to the value of an identical pot connected to the analog module on the cRio... however, we can not seem to get a similar value back from the Pot attached to the cRio, what was the code that you used to read those values from that pot... appreaciate the help.
we are going to use the pots to control the direction of a turret but need to compare the values so as not to twist the turret all the way around.
thanks in advance for any help you can provide..
have a great season.
Brain