A Library for MCP3008
Dependents: Nucleo_MCP3008_Test ProjetoBB KIK01 MASTER_SPI_MCP3008
mcp3008.h
00001 /** 00002 * @file mcp32008.h 00003 */ 00004 00005 #include "mbed.h" 00006 00007 00008 #ifndef MCP3008_H 00009 #define MCP3008_H 00010 00011 00012 /** Polarity setting for differential inputs. 00013 * 00014 * POL_EVEN_POSITIVE sets channel [0|2|4|6] as the positive side and channel 00015 * [1|3|5|7] as the negative side. POL_EVEN_NEGATIVE sets the opposite. 00016 */ 00017 enum Polarity { 00018 POL_EVEN_POSITIVE, 00019 POL_EVEN_NEGATIVE 00020 }; 00021 00022 00023 /** Class for interfacing to the MCP3008 SPI-based ADC. 00024 * 00025 */ 00026 class MCP3008 00027 { 00028 public: 00029 /** Create an MCP3008 object. 00030 * 00031 * @param bus An SPI bus object. 00032 * @param cs The name of a pin to use as the chip select. 00033 */ 00034 MCP3008(SPI* p_bus, PinName cs); 00035 ~MCP3008(); 00036 00037 /** Read from a single-ended input. 00038 * 00039 * @param channel The channel number to read from. 00040 * 00041 * @param returns The sampled value as a float between 0.0 and 1.0. 00042 */ 00043 float read_input(int channel); 00044 00045 /** Read from a single-ended input. 00046 * 00047 * @param channel The channel number to read from. 00048 * 00049 * @param returns The sampled value as a unsigned int16_t between 0 and 1024. 00050 */ 00051 uint16_t read_input_u16(int channel); 00052 00053 /** Read from a pair of differential inputs. 00054 * 00055 * In differential mode, the channels are referred to as 0 to 3, with 00056 * polarity set in a separate parameter. This avoids the user having to set 00057 * the polarity as part of the channel number or having channel numbers 00058 * increase by two (i.e. the channels being 0, 2, 4, and 6). 00059 * 00060 * @param channel The channel number to read from. 00061 * @param polarity The polarity of the differential signal. 00062 * 00063 * @param returns The sampled value as a float between 0.0 and 1.0. 00064 */ 00065 //float read_diff_input(int channel, Polarity polarity); 00066 00067 private: 00068 DigitalOut m_cs; 00069 SPI* m_p_bus; 00070 00071 void select(); 00072 void deselect(); 00073 }; 00074 00075 00076 #endif
Generated on Thu Jul 14 2022 22:42:07 by 1.7.2