A compilation of some hardware sensors and their shared programming interfaces.
ADCSensor.h@0:8d34cc2ff388, 2014-03-16 (annotated)
- Committer:
- mgottscho
- Date:
- Sun Mar 16 01:48:59 2014 +0000
- Revision:
- 0:8d34cc2ff388
A compilation of various hardware sensors and some shared programming interfaces.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mgottscho | 0:8d34cc2ff388 | 1 | /* ADCSensor.h |
mgottscho | 0:8d34cc2ff388 | 2 | * Tested with mbed board: FRDM-KL46Z |
mgottscho | 0:8d34cc2ff388 | 3 | * Author: Mark Gottscho |
mgottscho | 0:8d34cc2ff388 | 4 | * mgottscho@ucla.edu |
mgottscho | 0:8d34cc2ff388 | 5 | */ |
mgottscho | 0:8d34cc2ff388 | 6 | |
mgottscho | 0:8d34cc2ff388 | 7 | #ifndef ADCSensor_H |
mgottscho | 0:8d34cc2ff388 | 8 | #define ADCSensor_H |
mgottscho | 0:8d34cc2ff388 | 9 | |
mgottscho | 0:8d34cc2ff388 | 10 | #include "mbed.h" |
mgottscho | 0:8d34cc2ff388 | 11 | #include "PeriodicSensor.h" |
mgottscho | 0:8d34cc2ff388 | 12 | |
mgottscho | 0:8d34cc2ff388 | 13 | class ADCSensor : public PeriodicSensor { |
mgottscho | 0:8d34cc2ff388 | 14 | public: |
mgottscho | 0:8d34cc2ff388 | 15 | /** |
mgottscho | 0:8d34cc2ff388 | 16 | * Constructs an ADCSensor. |
mgottscho | 0:8d34cc2ff388 | 17 | * @param adc_pin the ADC pin to use |
mgottscho | 0:8d34cc2ff388 | 18 | */ |
mgottscho | 0:8d34cc2ff388 | 19 | ADCSensor(PinName adc_pin); |
mgottscho | 0:8d34cc2ff388 | 20 | |
mgottscho | 0:8d34cc2ff388 | 21 | ~ADCSensor(); |
mgottscho | 0:8d34cc2ff388 | 22 | |
mgottscho | 0:8d34cc2ff388 | 23 | /** |
mgottscho | 0:8d34cc2ff388 | 24 | * @param sampleNow if true, samples the ADC returns it. if false, gets the last sampled value. |
mgottscho | 0:8d34cc2ff388 | 25 | * The latter is preferred if this object is set up to sample using interrupts. |
mgottscho | 0:8d34cc2ff388 | 26 | * @returns a raw ADC reading |
mgottscho | 0:8d34cc2ff388 | 27 | */ |
mgottscho | 0:8d34cc2ff388 | 28 | uint16_t getSample(bool sampleNow); |
mgottscho | 0:8d34cc2ff388 | 29 | |
mgottscho | 0:8d34cc2ff388 | 30 | /** |
mgottscho | 0:8d34cc2ff388 | 31 | * @param sampleNow if true, samples the ADC returns it. if false, gets the last sampled value. |
mgottscho | 0:8d34cc2ff388 | 32 | * The latter is preferred if this object is set up to sample using interrupts. |
mgottscho | 0:8d34cc2ff388 | 33 | * @returns the ADC reading in Volts |
mgottscho | 0:8d34cc2ff388 | 34 | */ |
mgottscho | 0:8d34cc2ff388 | 35 | float getSampleFloat(bool sampleNow); |
mgottscho | 0:8d34cc2ff388 | 36 | |
mgottscho | 0:8d34cc2ff388 | 37 | private: |
mgottscho | 0:8d34cc2ff388 | 38 | /** |
mgottscho | 0:8d34cc2ff388 | 39 | * Interrupt service routine for sampling the ADC. |
mgottscho | 0:8d34cc2ff388 | 40 | */ |
mgottscho | 0:8d34cc2ff388 | 41 | virtual void __sample_data_ISR(); |
mgottscho | 0:8d34cc2ff388 | 42 | |
mgottscho | 0:8d34cc2ff388 | 43 | AnalogIn __adc; |
mgottscho | 0:8d34cc2ff388 | 44 | volatile uint16_t __data; |
mgottscho | 0:8d34cc2ff388 | 45 | |
mgottscho | 0:8d34cc2ff388 | 46 | const static float ADC_DIV = 0.00005035; //Volts/level |
mgottscho | 0:8d34cc2ff388 | 47 | }; |
mgottscho | 0:8d34cc2ff388 | 48 | |
mgottscho | 0:8d34cc2ff388 | 49 | #endif |