Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MODSERIAL FATFileSystem
Diff: omegaPX209/omegaPX209.cpp
- Revision:
- 54:d4990fb68404
- Parent:
- 17:7c16b5671d0e
- Child:
- 55:f4ec445c42fe
--- a/omegaPX209/omegaPX209.cpp Thu Jun 07 13:02:08 2018 +0000 +++ b/omegaPX209/omegaPX209.cpp Fri Jun 08 13:56:30 2018 +0000 @@ -2,19 +2,25 @@ This class wraps an Omega pressure transducer. Author: Matthew, October 24th, 2013 Modified: Dan, 2017-10-30 + +WIP: Troy +- added the ability to read the counts from this class directly +- had to fix the class to have the header guard in the header file (#ifndef, #define, #endif) */ #include "mbed.h" #include "omegaPX209.hpp" +#include "StaticDefs.hpp" //pins and other hardware (new) omegaPX209::omegaPX209(PinName pin): - _adc(pin) + _adc(pin) //leaving function as is for now { _psi = 14.7; // pressure [psi] _zeroPsi = 14.7; // atmospheric pressure at sea level [psi] - _adcVoltage = 3.3; // mbed ADC system voltage [V] + _adcVoltage = 5.6; // Troy: I'm not sure this is the right name for this multiplier... [V] (was 3.3 before) _fullscale = 50; // value of sensor at full scale (*confirm with Stearns*) [psi] - _cal = _fullscale/5.0; // psi per volt calibration [psi/V] + _psi_per_volt_cal = _fullscale/5.0; // psi per volt calibration [psi/V] + _PSI_reading = 0; } // nothing to initialize, but you can call this function if it makes you feel better. @@ -35,11 +41,18 @@ float omegaPX209::getPsi() { // filter by over-sampling float add = 0; + float adc_reading = 0; + float PSI_reading = 0; + for (int i = 0; i < OVERSAMPLE; i++) { // analog input _adc is float 0.0 to 1.0 // multiplying by _adcVoltage converts percentage to a voltage // multiplying by _cal converts voltage to a pressure - add += _adc.read() * _adcVoltage * _cal; + adc_reading = adc().readCh4()/4095.0; + + _PSI_reading = adc_reading * _adcVoltage * _psi_per_volt_cal; //Note: real_voltage_reading = adc_reading * _adcVoltage + + add += PSI_reading; //replaced _adc.read() } // use over-sampled @@ -61,4 +74,21 @@ // call this if you want to tare to zero void omegaPX209::tare() { setZero(getPsi()); +} + +// 06/06/2018 + +int omegaPX209::readADCCounts() { + //return _adc.read(); + return adc().readCh4(); +} + +float omegaPX209::readVoltage() { + float pressure_voltage = adc().readCh4()/4095.0 * 5.6; + return pressure_voltage; +} + +float omegaPX209::getRawPSI() { + float pressure_raw = adc().readCh4()/4095.0 * 56; + return pressure_raw; } \ No newline at end of file