ADC for threaded program
Dependents: LEX_Threaded_Programming MEMSPCR_Control_Program_AD_Logging_Demo_PCB MEMSPCR_Control_Program_AD_Logging_Sync MEMSPCR_Control_Program_AD_Logging_PWM ... more
ADS8568_ADC.h@0:d59f808e1719, 2019-07-16 (annotated)
- Committer:
- AlexStokoe
- Date:
- Tue Jul 16 14:22:31 2019 +0000
- Revision:
- 0:d59f808e1719
initial commit of ADC library;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AlexStokoe | 0:d59f808e1719 | 1 | /*------------------------------------------------------------------------------ |
AlexStokoe | 0:d59f808e1719 | 2 | Library header file for ADS8568 TI 16 bit 8 channel sampling ADC |
AlexStokoe | 0:d59f808e1719 | 3 | Date: 15/07/2018 |
AlexStokoe | 0:d59f808e1719 | 4 | Author: AS7 |
AlexStokoe | 0:d59f808e1719 | 5 | |
AlexStokoe | 0:d59f808e1719 | 6 | |
AlexStokoe | 0:d59f808e1719 | 7 | ------------------------------------------------------------------------------*/ |
AlexStokoe | 0:d59f808e1719 | 8 | |
AlexStokoe | 0:d59f808e1719 | 9 | #ifndef ADS8568_ADC_H |
AlexStokoe | 0:d59f808e1719 | 10 | #define ADS8568_ADC_H |
AlexStokoe | 0:d59f808e1719 | 11 | #include "mbed.h" |
AlexStokoe | 0:d59f808e1719 | 12 | |
AlexStokoe | 0:d59f808e1719 | 13 | #ifndef ADC_CONV_ALL_CH |
AlexStokoe | 0:d59f808e1719 | 14 | #define ADC_CONV_ALL_CH 15 |
AlexStokoe | 0:d59f808e1719 | 15 | #endif |
AlexStokoe | 0:d59f808e1719 | 16 | |
AlexStokoe | 0:d59f808e1719 | 17 | class ADS8568_ADC |
AlexStokoe | 0:d59f808e1719 | 18 | { |
AlexStokoe | 0:d59f808e1719 | 19 | public: |
AlexStokoe | 0:d59f808e1719 | 20 | /** Constructor |
AlexStokoe | 0:d59f808e1719 | 21 | * @param MOSI SPI pin |
AlexStokoe | 0:d59f808e1719 | 22 | * @param MISO SPI pin |
AlexStokoe | 0:d59f808e1719 | 23 | * @param SCLK SPI pin |
AlexStokoe | 0:d59f808e1719 | 24 | * @param nCS SPI pin |
AlexStokoe | 0:d59f808e1719 | 25 | * @param ADC reset pin |
AlexStokoe | 0:d59f808e1719 | 26 | * @param Conv chA pin |
AlexStokoe | 0:d59f808e1719 | 27 | * @param Conv chB pin |
AlexStokoe | 0:d59f808e1719 | 28 | * @param Conv chC pin |
AlexStokoe | 0:d59f808e1719 | 29 | * @param Conv chD pin |
AlexStokoe | 0:d59f808e1719 | 30 | */ |
AlexStokoe | 0:d59f808e1719 | 31 | ADS8568_ADC(PinName mosi, PinName miso, PinName sclk, PinName ncs, PinName reset, PinName convA, PinName convB, PinName convC, PinName convD); |
AlexStokoe | 0:d59f808e1719 | 32 | //ADS8568_ADC(SPI bus, DigitalOut adc_nselect, DigitalOut adc_reset |
AlexStokoe | 0:d59f808e1719 | 33 | |
AlexStokoe | 0:d59f808e1719 | 34 | void init(); |
AlexStokoe | 0:d59f808e1719 | 35 | |
AlexStokoe | 0:d59f808e1719 | 36 | void start_conversion(int channel); |
AlexStokoe | 0:d59f808e1719 | 37 | int read_channels(); |
AlexStokoe | 0:d59f808e1719 | 38 | int read_channel_result(int channel); |
AlexStokoe | 0:d59f808e1719 | 39 | int new_data_channels(); |
AlexStokoe | 0:d59f808e1719 | 40 | int OSR; |
AlexStokoe | 0:d59f808e1719 | 41 | |
AlexStokoe | 0:d59f808e1719 | 42 | |
AlexStokoe | 0:d59f808e1719 | 43 | protected: |
AlexStokoe | 0:d59f808e1719 | 44 | SPI bus; |
AlexStokoe | 0:d59f808e1719 | 45 | DigitalOut adc_nselect; |
AlexStokoe | 0:d59f808e1719 | 46 | DigitalOut adc_reset; |
AlexStokoe | 0:d59f808e1719 | 47 | BusOut converts; |
AlexStokoe | 0:d59f808e1719 | 48 | |
AlexStokoe | 0:d59f808e1719 | 49 | char buffer[16]; |
AlexStokoe | 0:d59f808e1719 | 50 | int values[8]; |
AlexStokoe | 0:d59f808e1719 | 51 | int val_array[8]; |
AlexStokoe | 0:d59f808e1719 | 52 | char dummy; |
AlexStokoe | 0:d59f808e1719 | 53 | int channels_read; |
AlexStokoe | 0:d59f808e1719 | 54 | |
AlexStokoe | 0:d59f808e1719 | 55 | }; |
AlexStokoe | 0:d59f808e1719 | 56 | |
AlexStokoe | 0:d59f808e1719 | 57 | #endif |
AlexStokoe | 0:d59f808e1719 | 58 |