Driver for National Semiconductor ADC128Sxxx family of analog to digital converters
Embed:
(wiki syntax)
Show/hide line numbers
ADC128S.h
00001 /* mbed library for the National Semiconductor ADC128S family of analog to digital converters 00002 * 00003 * by Michael Shimniok - http://www.bot-thoughts.com/ 00004 */ 00005 00006 /** An interface for driving a National Semiconductor ADC128Sxxx analog to digital converter using SPI 00007 * 00008 * @code 00009 * #include "mbed.h" 00010 * #include "ADC128S.h" 00011 * 00012 * Serial pc(USBTX, USBRX); // tx, rx 00013 * ADC128S adc(p5, p6, p7, p15); // mosi, miso, sck, cs 00014 * 00015 * int main() { 00016 * unsigned int result; 00017 * pc.baud(115200); 00018 * 00019 * while(1) { 00020 * for (int i = 0; i < 8; i++) { 00021 * result = adc.read(i); 00022 * pc.printf("ADC(%d)=%d\n", i, result); 00023 * } 00024 * pc.printf("\n"); 00025 * } 00026 * } 00027 * @endcode 00028 */ 00029 class ADC128S { 00030 public: 00031 /** Create an ADC128S interface 00032 * 00033 * @param mosi MOSI line 00034 * @param miso MISO line 00035 * @param sck SCK line 00036 * @param cs !CS/!SS line 00037 */ 00038 ADC128S(PinName mosi, PinName miso, PinName sck, PinName cs); 00039 00040 00041 /** Get the next channel to be converted with next call to read() 00042 * 00043 * @returns an integer representing the adc channel about to be converted 00044 */ 00045 int getChannel(void); 00046 00047 /** Set channel to be used for the next conversion. 00048 * 00049 * @param channel is the adc channel you want to read with next call to read() 00050 */ 00051 void setChannel(int channel); 00052 00053 /** Convert the current channel and return the result and prepare to read the next channel. 00054 * The channel will count to 7 and then wrap around to 0. See also: setChannel() 00055 * 00056 * @param returns conversion for the curent channel and prepares to read the next channel 00057 */ 00058 unsigned int read(void); 00059 00060 /** Read in analog value from the specified ADC channel 00061 * 00062 * @param channel The ADC channel to read 00063 * @returns the analog to digital conversion result 00064 */ 00065 unsigned int read(int channel); 00066 00067 private: 00068 SPI _adc; 00069 DigitalOut _cs; 00070 int _channel; 00071 };
Generated on Sat Jul 23 2022 19:31:45 by 1.7.2