Driver for National Semiconductor ADC128Sxxx family of analog to digital converters
ADC128S.h@1:0edd6142cd67, 2011-03-02 (annotated)
- Committer:
- shimniok
- Date:
- Wed Mar 02 05:50:24 2011 +0000
- Revision:
- 1:0edd6142cd67
- Parent:
- 0:28addf1f4c26
- Child:
- 2:f6c4a79f2ee0
Changed order of parameters. Updated documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 1:0edd6142cd67 | 1 | /* mbed library for the National Semiconductor ADC128S family of analog to digital converters |
shimniok | 1:0edd6142cd67 | 2 | * |
shimniok | 1:0edd6142cd67 | 3 | * by Michael Shimniok - http://www.bot-thoughts.com/ |
shimniok | 1:0edd6142cd67 | 4 | */ |
shimniok | 1:0edd6142cd67 | 5 | |
shimniok | 1:0edd6142cd67 | 6 | /** An interface for driving a National Semiconductor ADC128Sxxx analog to digital converter using SPI |
shimniok | 1:0edd6142cd67 | 7 | * |
shimniok | 1:0edd6142cd67 | 8 | * @code |
shimniok | 1:0edd6142cd67 | 9 | * #include "mbed.h" |
shimniok | 1:0edd6142cd67 | 10 | * #include "ADC128S.h" |
shimniok | 1:0edd6142cd67 | 11 | * |
shimniok | 1:0edd6142cd67 | 12 | * Serial pc(USBTX, USBRX); // tx, rx |
shimniok | 1:0edd6142cd67 | 13 | * ADC128S adc(p5, p6, p7, p15); // mosi, miso, sck, cs |
shimniok | 1:0edd6142cd67 | 14 | * |
shimniok | 1:0edd6142cd67 | 15 | * int main() { |
shimniok | 1:0edd6142cd67 | 16 | * unsigned int result; |
shimniok | 1:0edd6142cd67 | 17 | * pc.baud(115200); |
shimniok | 1:0edd6142cd67 | 18 | * |
shimniok | 1:0edd6142cd67 | 19 | * while(1) { |
shimniok | 1:0edd6142cd67 | 20 | * for (int i = 0; i < 8; i++) { |
shimniok | 1:0edd6142cd67 | 21 | * result = adc.read(i); |
shimniok | 1:0edd6142cd67 | 22 | * pc.printf("ADC(%d)=%d\n", i, result); |
shimniok | 1:0edd6142cd67 | 23 | * } |
shimniok | 1:0edd6142cd67 | 24 | * pc.printf("\n"); |
shimniok | 1:0edd6142cd67 | 25 | * } |
shimniok | 1:0edd6142cd67 | 26 | * } |
shimniok | 1:0edd6142cd67 | 27 | * @endcode |
shimniok | 1:0edd6142cd67 | 28 | */ |
shimniok | 1:0edd6142cd67 | 29 | class ADC128S { |
shimniok | 1:0edd6142cd67 | 30 | public: |
shimniok | 1:0edd6142cd67 | 31 | /** Create an ADC128S interface |
shimniok | 1:0edd6142cd67 | 32 | * |
shimniok | 1:0edd6142cd67 | 33 | * @param mosi MOSI line |
shimniok | 1:0edd6142cd67 | 34 | * @param miso MISO line |
shimniok | 1:0edd6142cd67 | 35 | * @param sck SCK line |
shimniok | 1:0edd6142cd67 | 36 | * @param cs !CS/!SS line |
shimniok | 1:0edd6142cd67 | 37 | */ |
shimniok | 1:0edd6142cd67 | 38 | ADC128S(PinName mosi, PinName miso, PinName sck, PinName cs); |
shimniok | 1:0edd6142cd67 | 39 | |
shimniok | 1:0edd6142cd67 | 40 | /** Read in analog value from the specified ADC channel |
shimniok | 1:0edd6142cd67 | 41 | * |
shimniok | 1:0edd6142cd67 | 42 | * @param channel The ADC channel to read |
shimniok | 1:0edd6142cd67 | 43 | * @param returns the analog to digital conversion result |
shimniok | 1:0edd6142cd67 | 44 | */ |
shimniok | 1:0edd6142cd67 | 45 | unsigned int read(int channel); |
shimniok | 1:0edd6142cd67 | 46 | |
shimniok | 1:0edd6142cd67 | 47 | private: |
shimniok | 1:0edd6142cd67 | 48 | SPI _adc; |
shimniok | 1:0edd6142cd67 | 49 | DigitalOut _cs; |
shimniok | 0:28addf1f4c26 | 50 | }; |