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_LOOP_RUNNING 1 |
| Analog loop status. ADC conversion running. | |
| #define | ADC_LOOP_STOPPED 0 |
| Analog loop status. No ADC conversion running. | |
| #define | ADC_START 1 |
| Analog init parameter. Start the analog loop. | |
| #define | ADC_STOP 0 |
| Analog init parameter. Don't start the analog loop. | |
| #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. | |
| int | analog_loop_status (void) |
| Returns the status of the analog loop. | |
| 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. | |
| unsigned int | read_line (int which) |
| int | wheel (void) |
| Read the position of the wheel. | |
| void | set_adc_mux (int which) |
Variables | |
| volatile int | adc_loop_status = ADC_LOOP_STOPPED |
| volatile int | adc_sig_stop_loop = 0 |
| volatile int | adc_current_port = 0 |
| volatile 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
| 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
| 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
| 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
| 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
- Bug:
- First conversion takes a performance penalty of 25 vs. 13 ADC clock cycles of successive conversions. Analog_init should run a dummy conversion to pre-empt this.
For good 10-bit precision, ACD clock must be between 50kHz and 200kHz. Currently, ADC clock is fixed at 125kHz using 1/64prescalar. However, most code uses 8-bit precision which can work at ADC clock speeds higher than 200kHz. Experimental tests needed to determine highest clock speed for accurate 8-bit ADC.
| int analog_loop_status | ( | void | ) |
Returns the status of the analog loop.
Returns the status of loop. 0 for stopped. 1 for running. 2 for paused.
- See also:
- analog_start_loop, analog_stop_loop
| 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, analog_loop_status
| void analog_stop_loop | ( | ) |
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, analog_loop_status
| unsigned int read_line | ( | int | which | ) |
| 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
| 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
Generated on Wed Feb 8 00:00:08 2012 for libdragonfly by
1.6.1