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

Committer:
Kemp
Date:
Sat Jun 11 21:19:56 2011 +0000
Revision:
3:e7de500b1f2d
Parent:
2:93009a423b45
Minor tweak.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kemp 2:93009a423b45 1 /**
Kemp 2:93009a423b45 2 * @file mcp3208.h
Kemp 2:93009a423b45 3 */
Kemp 2:93009a423b45 4
Kemp 2:93009a423b45 5 #include "mbed.h"
Kemp 2:93009a423b45 6
Kemp 2:93009a423b45 7
Kemp 2:93009a423b45 8 #ifndef MCP3208_H
Kemp 2:93009a423b45 9 #define MCP3208_H
Kemp 2:93009a423b45 10
Kemp 2:93009a423b45 11
Kemp 2:93009a423b45 12 /** Polarity setting for differential inputs.
Kemp 2:93009a423b45 13 *
Kemp 2:93009a423b45 14 * POL_EVEN_POSITIVE sets channel [0|2|4|6] as the positive side and channel
Kemp 2:93009a423b45 15 * [1|3|5|7] as the negative side. POL_EVEN_NEGATIVE sets the opposite.
Kemp 2:93009a423b45 16 */
Kemp 2:93009a423b45 17 enum Polarity {
Kemp 2:93009a423b45 18 POL_EVEN_POSITIVE,
Kemp 2:93009a423b45 19 POL_EVEN_NEGATIVE
Kemp 2:93009a423b45 20 };
Kemp 2:93009a423b45 21
Kemp 2:93009a423b45 22
Kemp 2:93009a423b45 23 /** Class for interfacing to the MCP3208 SPI-based ADC.
Kemp 2:93009a423b45 24 *
Kemp 2:93009a423b45 25 * This class will also allow interfacing to the MCP3204, but only four
Kemp 2:93009a423b45 26 * inputs are provided by that chip, as opposed to the eight of the MCP3208.
Kemp 2:93009a423b45 27 */
Kemp 2:93009a423b45 28 class MCP3208
Kemp 2:93009a423b45 29 {
Kemp 2:93009a423b45 30 public:
Kemp 2:93009a423b45 31 /** Create an MCP3208 object.
Kemp 2:93009a423b45 32 *
Kemp 2:93009a423b45 33 * @param bus An SPI bus object.
Kemp 2:93009a423b45 34 * @param cs The name of a pin to use as the chip select.
Kemp 2:93009a423b45 35 */
Kemp 2:93009a423b45 36 MCP3208(SPI bus, PinName cs);
Kemp 2:93009a423b45 37 ~MCP3208();
Kemp 2:93009a423b45 38
Kemp 2:93009a423b45 39 /** Read from a single-ended input.
Kemp 2:93009a423b45 40 *
Kemp 2:93009a423b45 41 * @param channel The channel number to read from.
Kemp 2:93009a423b45 42 *
Kemp 2:93009a423b45 43 * @param returns The sampled value as a float between 0.0 and 1.0.
Kemp 2:93009a423b45 44 */
Kemp 2:93009a423b45 45 float read_input(int channel);
Kemp 2:93009a423b45 46
Kemp 2:93009a423b45 47 /** Read from a pair of differential inputs.
Kemp 2:93009a423b45 48 *
Kemp 2:93009a423b45 49 * In differential mode, the channels are referred to as 0 to 3, with
Kemp 2:93009a423b45 50 * polarity set in a separate parameter. This avoids the user having to set
Kemp 2:93009a423b45 51 * the polarity as part of the channel number or having channel numbers
Kemp 2:93009a423b45 52 * increase by two (i.e. the channels being 0, 2, 4, and 6).
Kemp 2:93009a423b45 53 *
Kemp 2:93009a423b45 54 * @param channel The channel number to read from.
Kemp 2:93009a423b45 55 * @param polarity The polarity of the differential signal.
Kemp 2:93009a423b45 56 *
Kemp 2:93009a423b45 57 * @param returns The sampled value as a float between 0.0 and 1.0.
Kemp 2:93009a423b45 58 */
Kemp 2:93009a423b45 59 float read_diff_input(int channel, Polarity polarity);
Kemp 2:93009a423b45 60
Kemp 2:93009a423b45 61 private:
Kemp 2:93009a423b45 62 DigitalOut m_cs;
Kemp 2:93009a423b45 63 SPI m_bus;
Kemp 2:93009a423b45 64
Kemp 2:93009a423b45 65 void select();
Kemp 2:93009a423b45 66 void deselect();
Kemp 2:93009a423b45 67 };
Kemp 2:93009a423b45 68
Kemp 2:93009a423b45 69
Kemp 2:93009a423b45 70 #endif