Robot Control Library
adc.h
Go to the documentation of this file.
1 /**
2  * <rc/adc.h>
3  *
4  * @brief C interface for the Linux IIO ADC driver
5  *
6  * The Robotics cape and BeagleBone Blue include two voltage dividers for safe
7  * measurement of the 2-cell lithium battery voltage and the voltage of any
8  * power source connected to the 9-18V DC power jack. These can be read with
9  * c_adc_batt() and rc_adc_dc_jack()
10  *
11  * There is also a 6-pin JST-SH socket on the Cape for connecting up to 4
12  * potentiometers or general use analog signals. The pinout of this socket is as
13  * follows:
14  *
15  * - 1 - Ground
16  * - 2 - VDD_ADC (1.8V)
17  * - 3 - AIN0
18  * - 4 - AIN1
19  * - 5 - AIN2
20  * - 6 - AIN3
21  *
22  * All 8 ADC channels on the Sitara including the 4 listed above can be read
23  * with rc_adc_read_raw(int ch) which returns the raw integer output of the
24  * 12-bit ADC. rc_adc_read_volt(int ch) additionally converts this raw value to
25  * a voltage.
26  *
27  * See the rc_test_adc example for sample use case.
28  *
29  * @addtogroup ADC
30  * @ingroup IO
31  * @{
32  */
33 
34 #ifndef RC_ADC_H
35 #define RC_ADC_H
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * @brief initializes the analog to digital converter for reading
43  *
44  * @return 0 on success, -1 on failure.
45  */
46 int rc_adc_init(void);
47 
48 /**
49  * @brief Cleans up the ADC subsystem.
50  *
51  * Call before your program closes down
52  *
53  * @return 0 on success, -1 on failure.
54  */
55 int rc_adc_cleanup(void);
56 
57 /**
58  * @brief reads the raw integer ADC value for a particular channel
59  *
60  * @param[in] ch channel 0-7
61  *
62  * @return 16-bit adc reading on success, -1 on failure.
63  */
64 int rc_adc_read_raw(int ch);
65 
66 /**
67  * @brief reads an adc voltage.
68  *
69  * @param[in] ch channel 0-7
70  *
71  * @return voltage from 0-1.8v or -1 on error
72  */
73 double rc_adc_read_volt(int ch);
74 
75 /**
76  * @brief reads the voltage of the 2-cell Lithium battery
77  *
78  * @return voltage of battery or -1 on failure
79  */
80 double rc_adc_batt(void);
81 
82 /**
83  * @brief Reads the voltage of the 9-18v DC jack
84  *
85  * @return Voltage at DC jack or -1 on failure
86  */
87 double rc_adc_dc_jack(void);
88 
89 
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif // RC_ADC_H
96 
97 /** @} end group ADC*/
double rc_adc_batt(void)
reads the voltage of the 2-cell Lithium battery
double rc_adc_dc_jack(void)
Reads the voltage of the 9-18v DC jack.
int rc_adc_read_raw(int ch)
reads the raw integer ADC value for a particular channel
int rc_adc_cleanup(void)
Cleans up the ADC subsystem.
double rc_adc_read_volt(int ch)
reads an adc voltage.
int rc_adc_init(void)
initializes the analog to digital converter for reading