View Single Post
  #5   Spotlight this post!  
Unread 23-01-2006, 00:17
duane's Avatar
duane duane is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Vacaville
Posts: 98
duane is an unknown quantity at this point
Send a message via AIM to duane
Re: Analog to Digital Conversion Help

Quote:
Originally Posted by Der Rowan
I'm just looking for a good way to trouble shoot.

Even if I get the sensor and the RC to talk how do I see what they are saying to each other? The way I understand it, The RC is going to capture a value every so often at regular intervals which can then be used within the code to integrate (given that you know the interval...) or whatever. But I dont know how to see what that value is. Is there a way? It would be very helpful to explain whats going on to a highschooler.
That explains things a little better.

There's nothing special about what's going on. You are in complete control.

First, I would second, what another poster said. Check out the ADC code from Kevin Watson (I saw wish I had to time to do what he does! :-)

Analog inputs are pretty simple. Unlike digital inputs which are just on and off, analog inputs can have any value between 0-5 volts. In order to read those values, the analog reading has to be coverted to an digital value. The FRC has a 10-bit analog-to-digital converter built in. When you call Get_Analog_Value() the RC returns a 10-bit number (in an integer). That means the value will range from 0 to 1024 (2^10).

Imagine dividing a line that is 5 units long into 1024 pieces. Each value represents that length of the line. 0 is 0, 1024 is 5, 512 is 2.5, etc. In practice, you care less about what the actual value is than how the value is different from the previous or expected value your code may be looking for.

The value you want to look at when you are debugging is the result from Get_Analog_Value(). That is the reading from the ADC converter.

You will see many examples that show shifting the result to the right 2 bits:
int result = Get_Analog_Value( rc_ana_in01 ) >> 2;

This reduces the resolution from 1024 (2^10) to 256 (2^8) by removing the two least significant bits. This is often done if the reading is going to be used with other devices that only support 8-bit values. For internal lookup tables and other math, you can use the entire 10-bit value.

Hope that helps,
...Duane