Release candidate version. The pointer in GAS Pressure display is changed to a triangle.
Dependencies: UniGraphic mbed vt100
Please note, at 2-Mar-2018 the current version of mbed-lib has a defect in Ticker.
https://os.mbed.com/forum/bugs-suggestions/topic/29287/
So, mbed lib version 157 is intentionally being used.
Please do not update mbed library until the problem in the above URL is fixed.
In this version, format of GAS Pressure Display has been changed.
moto
sensors/PSE530.cpp@0:774324cbc5a6, 2018-03-02 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Mar 02 07:56:09 2018 +0000
- Revision:
- 0:774324cbc5a6
Release candidate version. GAS Pressure pointer is now a triangle.; Some source file clean-up was done.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:774324cbc5a6 | 1 | #include "mbed.h" |
Rhyme | 0:774324cbc5a6 | 2 | #include "PSE530.h" |
Rhyme | 0:774324cbc5a6 | 3 | |
Rhyme | 0:774324cbc5a6 | 4 | /** |
Rhyme | 0:774324cbc5a6 | 5 | * SMC PSE530 pressure sensor |
Rhyme | 0:774324cbc5a6 | 6 | * analog output 1.0V - 5.0V |
Rhyme | 0:774324cbc5a6 | 7 | * 1.0V : 0 |
Rhyme | 0:774324cbc5a6 | 8 | * 5.0V : 1MPa |
Rhyme | 0:774324cbc5a6 | 9 | * (at 0.6V : -0.1MPa) |
Rhyme | 0:774324cbc5a6 | 10 | * Our sensor I/F converts 0-5V to 0-3V |
Rhyme | 0:774324cbc5a6 | 11 | * So we suppose V = Analog Float Value : Pressure |
Rhyme | 0:774324cbc5a6 | 12 | * 0.6V = 0.2 : 0 |
Rhyme | 0:774324cbc5a6 | 13 | * 3.0V = 1.0 : 1MPa |
Rhyme | 0:774324cbc5a6 | 14 | */ |
Rhyme | 0:774324cbc5a6 | 15 | |
Rhyme | 0:774324cbc5a6 | 16 | /** |
Rhyme | 0:774324cbc5a6 | 17 | * conversion from Pa to kgf/cm2 |
Rhyme | 0:774324cbc5a6 | 18 | * 98,066.5 Pa = 1 kgf/cm2 |
Rhyme | 0:774324cbc5a6 | 19 | * 1 Pa = 1 / 98066.6 kgf/cm2 |
Rhyme | 0:774324cbc5a6 | 20 | */ |
Rhyme | 0:774324cbc5a6 | 21 | |
Rhyme | 0:774324cbc5a6 | 22 | PSE530::PSE530(AnalogIn *ain) |
Rhyme | 0:774324cbc5a6 | 23 | { |
Rhyme | 0:774324cbc5a6 | 24 | _ain = ain ; |
Rhyme | 0:774324cbc5a6 | 25 | } |
Rhyme | 0:774324cbc5a6 | 26 | |
Rhyme | 0:774324cbc5a6 | 27 | PSE530::~PSE530(void) |
Rhyme | 0:774324cbc5a6 | 28 | { |
Rhyme | 0:774324cbc5a6 | 29 | if (_ain) { |
Rhyme | 0:774324cbc5a6 | 30 | delete _ain ; |
Rhyme | 0:774324cbc5a6 | 31 | } |
Rhyme | 0:774324cbc5a6 | 32 | } |
Rhyme | 0:774324cbc5a6 | 33 | |
Rhyme | 0:774324cbc5a6 | 34 | /** |
Rhyme | 0:774324cbc5a6 | 35 | * On FRDM-KL25Z ADC's AREF is about 3.28V |
Rhyme | 0:774324cbc5a6 | 36 | * Where the converted pressure output is 0 to 3.21V |
Rhyme | 0:774324cbc5a6 | 37 | * So we must map ADC output 0 to 3.21/3.28 as full scale |
Rhyme | 0:774324cbc5a6 | 38 | * |
Rhyme | 0:774324cbc5a6 | 39 | * Then according to the datasheet of PSE530 |
Rhyme | 0:774324cbc5a6 | 40 | * when full range is 0V to 5V |
Rhyme | 0:774324cbc5a6 | 41 | * 1V is 0 and 5V is 1MPa which is converted to |
Rhyme | 0:774324cbc5a6 | 42 | * 0.642/3.28 to 3.21/3.28 ~ 0.195731 to 0.9786585. |
Rhyme | 0:774324cbc5a6 | 43 | * The linear equation of |
Rhyme | 0:774324cbc5a6 | 44 | * y = a x + b |
Rhyme | 0:774324cbc5a6 | 45 | * 0 = a * 0.195731 + b |
Rhyme | 0:774324cbc5a6 | 46 | * 1 = a * 0.978658 + b |
Rhyme | 0:774324cbc5a6 | 47 | * results a = 1.277, b = -0.250 |
Rhyme | 0:774324cbc5a6 | 48 | */ |
Rhyme | 0:774324cbc5a6 | 49 | float PSE530::getPressure(void) |
Rhyme | 0:774324cbc5a6 | 50 | { |
Rhyme | 0:774324cbc5a6 | 51 | float coef_A = 1.277 ; |
Rhyme | 0:774324cbc5a6 | 52 | float coef_B = -0.250 ; |
Rhyme | 0:774324cbc5a6 | 53 | float av = 0.0 ; |
Rhyme | 0:774324cbc5a6 | 54 | float value = 0.0 ; |
Rhyme | 0:774324cbc5a6 | 55 | av = coef_A * _ain->read() + coef_B ; |
Rhyme | 0:774324cbc5a6 | 56 | // printf("Pressure ADC = %.4f\n", av) ; |
Rhyme | 0:774324cbc5a6 | 57 | value = 1000000 * av ; /* 1MPa at 1.0 */ |
Rhyme | 0:774324cbc5a6 | 58 | value = value / 98066.5 ; /* Pa -> kgf/cm2 */ |
Rhyme | 0:774324cbc5a6 | 59 | return( value ) ; |
Rhyme | 0:774324cbc5a6 | 60 | } |