A library to interface to the MCP3208 SPI-based ADC from Microchip. This chip provides eight analogue inputs, providing converted 12-bit values via SPI.

Dependents:   Nucleo_MCP3208_Test Nucleo_MCP3208_Ticker_Test BBMv2_eps ref_BBMv2_eps ... more

Revision:
1:316f86115221
Parent:
0:d37e8cb188c1
Child:
2:93009a423b45
--- a/mcp3208.h	Mon May 23 22:58:59 2011 +0000
+++ b/mcp3208.h	Tue May 24 13:58:00 2011 +0000
@@ -5,13 +5,44 @@
 #define MCP3208_H
 
 
+enum Polarity {
+    POL_EVEN_POSITIVE,
+    POL_EVEN_NEGATIVE
+};
+
+
+/** Class for interfacing to the MCP3208 SPI-based ADC.
+ *
+ * This class will also allow interfacing to the MCP3204, but only four
+ * inputs are provided by that chip, as opposed to the eight of the MCP3208.
+ */
 class MCP3208
 {
 public:
     MCP3208(SPI bus, PinName cs);
     ~MCP3208();
     
-    int read_input(int channel);
+    /** Read from a single-ended input.
+     *
+     * @param channel The channel number to read from.
+     *
+     * @param returns The sampled value as a float between 0.0 and 1.0.
+     */
+    float read_input(int channel);
+    
+    /** Read from a pair of differential inputs.
+     *
+     * In differential mode, the channels are referred to as 0 to 3, with
+     * polarity set in a separate parameter. This avoids the user having to set
+     * the polarity as part of the channel number or having channel numbers
+     * increase by two (i.e. the channels being 0, 2, 4, and 6).
+     *
+     * @param channel The channel number to read from.
+     * @param polarity The polarity of the differential signal.
+     *
+     * @param returns The sampled value as a float between 0.0 and 1.0.
+     */
+    float read_diff_input(int channel, Polarity polarity);
   
 private:
     DigitalOut m_cs;