Analog


Data Structures

struct  adc_t
 Struct to hold the value of a particular analog port. More...

Defines

#define AN0   0x00
 Analog port 0.
#define AN1   0x01
 Analog port 1.
#define AN2   0x02
 Analog port 2.
#define AN3   0x03
 Analog port 3.
#define AN4   0x04
 Analog port 4.
#define AN5   0x05
 Analog port 5.
#define AN6   0x06
 Analog port 6.
#define AN7   0x07
 Analog port 7.
#define AN8   0x08
 Analog port 8.
#define AN9   0x09
 Analog port 9.
#define AN10   0x0A
 Analog port 10.
#define AN11   0x0B
 Analog port 11.
#define AN12   0x0C
 Analog port 12.
#define AN13   0x0D
 Analog port 13.
#define AN14   0x0E
 Analog port 14.
#define AN15   0x0F
 Analog port 15.
#define BOM_PORT   AN0
 BOM_PORT analog port for BOM.
#define EXT_MUX   AN7
 EXT_MUX analog port.
#define WHEEL_PORT   AN10
 Analog port for the wheel.
#define BATT_PORT   AN11
 Analog port for the battery voltage detector.
#define ADC_START   1
#define ADC_STOP   0
#define ADMUX_OPT   0x60

Functions

void analog_init (int start_conversion)
 Initialize analog ports. Will start running a loop if start_conversion is ADC_START.
unsigned int analog8 (int which)
 Returns an 8-bit analog value from the look up table. Use this instead of analog_get8.
unsigned int analog10 (int which)
 Returns an 10-bit analog value from the look up table. Use this instead of analog_get10.
void analog_start_loop (void)
 starts the analog loop. Doesn't do anything if the loop is already running.
void analog_stop_loop (void)
 Stops the analog loop. Doesn't do anything if the loop is already stopped.
unsigned int analog_get8 (int which)
 Read an 8-bit number from an analog port. Loop must be stopped for this to work.
unsigned int analog_get10 (int which)
 Read a 10-bit number from an analog port. Loop must be stopped for this to work.
int wheel (void)
 Read the position of the wheel.
void set_adc_mux (int which)

Variables

int adc_loop_running = 0
int adc_current_port = 0
adc_t an_val [11]

Detailed Description

Functions for manipulation the ADC on the dragonfly board. All definitions may be found in analog.h.

Function Documentation

unsigned int analog10 ( int  which  ) 

Returns an 10-bit analog value from the look up table. Use this instead of analog_get10.

Returns the 10-bit analog conversion of which from the lookup table. If the requested port is the BOM_PORT you will get an automatic 0 since the BOM_PORT is not read in the loop and not stored. If you need that port you should use the functions in bom.c. There is an analog_get10 function which for instant lookups but should be avoided unless you know what you are doing.

Parameters:
which the port that you want to read
Bug:
may cause a seg fault if which is a larger value than exists in an_val table. Not sure if we should fix this or not since it would add overhead.
Returns:
10-bit analog value for the which port requested
See also:
analog8, analog_get8, analog_get10

References adc_t::adc10, and BOM_PORT.

unsigned int analog8 ( int  which  ) 

Returns an 8-bit analog value from the look up table. Use this instead of analog_get8.

Returns the 8-bit analog conversion of which from the lookup table. If the requested port is the BOM_PORT you will get an automatic 0 since the BOM_PORT is not read in the loop and not stored. If you need that port you should use the functions in bom.c. There is an analog_get8 function which for instant lookups but should be avoided unless you know what you're doing.

Parameters:
which the port that you want to read
Bug:
may cause a seg fault if which is a larger value than exists in an_val table. Not sure if we should fix this or not since it would add overhead.
Returns:
8-bit analog value for the which port requested
See also:
analog10, analog_get8, analog_get10

References adc_t::adc8, and BOM_PORT.

Referenced by battery(), battery8(), range_read_distance(), and wheel().

unsigned int analog_get10 ( int  which  ) 

Read a 10-bit number from an analog port. Loop must be stopped for this to work.

Reads an 10-bit number from an analog port. analog_init must be called before using this function. The analog loop must also be stopped before using this function or you will mess up the lookup table. You must also reenabled the loop when you are done unless you are doing more instant reads. See analog_stop_loop and analog_start_loop for more information about the loop.

Parameters:
which the analog port to read from. Typically a constant, one of AN0 - AN7.
Returns:
the 10-bit number input to the specified port
See also:
analog_init, analog_get8, analog10, analog_stop_loop, analog_start_loop

References EXT_MUX, and set_adc_mux().

unsigned int analog_get8 ( int  which  ) 

Read an 8-bit number from an analog port. Loop must be stopped for this to work.

Reads an 8-bit number from an analog port. analog_init must be called before using this function. The analog loop must also be stopped before using this function or you will mess up the lookup table. You must also reenabled the loop when you are done unless you are doing more instant reads. See analog_stop_loop and analog_start_loop for more information about the loop.

Parameters:
which the analog port to read from. One of the constants AN0 - AN7.
Returns:
the 8-bit input to the specified port
See also:
analog_init, analog_get10, analog8, analog_stop_loop, analog_start_loop

References EXT_MUX, and set_adc_mux().

Referenced by bom_refresh().

void analog_init ( int  start_conversion  ) 

Initialize analog ports. Will start running a loop if start_conversion is ADC_START.

Initializes the ADC. Call analog_init before reading from the analog ports.

See also:
analog8, analog10, analog_get8, analog_get10

References adc_t::adc10, adc_t::adc8, AN1, analog_start_loop(), analog_stop_loop(), and set_adc_mux().

Referenced by dragonfly_init().

void analog_start_loop ( void   ) 

starts the analog loop. Doesn't do anything if the loop is already running.

Starts the analog update loop. Will continue to run until analog_stop_loop is called.

See also:
analog_stop_loop

Referenced by analog_init(), and bom_refresh().

void analog_stop_loop ( void   ) 

Stops the analog loop. Doesn't do anything if the loop is already stopped.

Stops the analog update loop. If there is a current read, it will finish up and be stored before the loop is interrupted. No further updates will be made until the loop is started again.

See also:
analog_start_loop

Referenced by analog_init(), and bom_refresh().

void set_adc_mux ( int  which  ) 

Sets the value of the external analog mux. Values are read on AN7 physical port. (AN8 - AN15 are "virtual" ports).

Parameters:
which which analog mux port (0-7) which corresponds to AN8-AN15.
Bug:
FIX THIS IN THE NEXT BOARD REVISION: ADDR2 ADDR1 ADDR0 G2.G4.G3 set mux to port 0-7 via vinary selection math would be much cleaner if it was G4.G3.G2
See also:
analog_init

Referenced by analog_get10(), analog_get8(), and analog_init().

int wheel ( void   ) 

Read the position of the wheel.

Returns the current position of the wheel, as an integer in the range 0 - 255. analog_init must be called before using this function.

Returns:
the orientation of the wheel, as an integer in the range 0 - 255.
See also:
analog_init

References analog8(), and WHEEL_PORT.


Generated on Thu Apr 16 18:33:23 2009 for libdragonfly by  doxygen 1.5.5