Color sensor reset at the end of calibration added. sensor id auto assignment was changed to be a fixed value assignment to avoid sensor id shift when some sensor is absent.

Dependencies:   UniGraphic mbed vt100

Committer:
Rhyme
Date:
Fri Feb 23 07:51:55 2018 +0000
Revision:
1:8818b793d147
Parent:
0:ce97f6d34336
Wrong behavior when one of color sensor is missing has been fixed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:ce97f6d34336 1 #include "mbed.h"
Rhyme 0:ce97f6d34336 2 #include "PSE530.h"
Rhyme 0:ce97f6d34336 3
Rhyme 0:ce97f6d34336 4 /**
Rhyme 0:ce97f6d34336 5 * SMC PSE530 pressure sensor
Rhyme 0:ce97f6d34336 6 * analog output 1.0V - 5.0V
Rhyme 0:ce97f6d34336 7 * 1.0V : 0
Rhyme 0:ce97f6d34336 8 * 5.0V : 1MPa
Rhyme 0:ce97f6d34336 9 * (at 0.6V : -0.1MPa)
Rhyme 0:ce97f6d34336 10 * Our sensor I/F converts 0-5V to 0-3V
Rhyme 0:ce97f6d34336 11 * So we suppose V = Analog Float Value : Pressure
Rhyme 0:ce97f6d34336 12 * 0.6V = 0.2 : 0
Rhyme 0:ce97f6d34336 13 * 3.0V = 1.0 : 1MPa
Rhyme 0:ce97f6d34336 14 */
Rhyme 0:ce97f6d34336 15
Rhyme 0:ce97f6d34336 16 /**
Rhyme 0:ce97f6d34336 17 * conversion from Pa to kgf/cm2
Rhyme 0:ce97f6d34336 18 * 98,066.5 Pa = 1 kgf/cm2
Rhyme 0:ce97f6d34336 19 * 1 Pa = 1 / 98066.6 kgf/cm2
Rhyme 0:ce97f6d34336 20 */
Rhyme 0:ce97f6d34336 21
Rhyme 0:ce97f6d34336 22 PSE530::PSE530(AnalogIn *ain)
Rhyme 0:ce97f6d34336 23 {
Rhyme 0:ce97f6d34336 24 _ain = ain ;
Rhyme 0:ce97f6d34336 25 }
Rhyme 0:ce97f6d34336 26
Rhyme 0:ce97f6d34336 27 PSE530::~PSE530(void)
Rhyme 0:ce97f6d34336 28 {
Rhyme 0:ce97f6d34336 29 if (_ain) {
Rhyme 0:ce97f6d34336 30 delete _ain ;
Rhyme 0:ce97f6d34336 31 }
Rhyme 0:ce97f6d34336 32 }
Rhyme 0:ce97f6d34336 33
Rhyme 0:ce97f6d34336 34 /**
Rhyme 0:ce97f6d34336 35 * On FRDM-KL25Z ADC's AREF is about 3.28V
Rhyme 0:ce97f6d34336 36 * Where the converted pressure output is 0 to 3.21V
Rhyme 0:ce97f6d34336 37 * So we must map ADC output 0 to 3.21/3.28 as full scale
Rhyme 0:ce97f6d34336 38 *
Rhyme 0:ce97f6d34336 39 * Then according to the datasheet of PSE530
Rhyme 0:ce97f6d34336 40 * when full range is 0V to 5V
Rhyme 0:ce97f6d34336 41 * 1V is 0 and 5V is 1MPa which is converted to
Rhyme 0:ce97f6d34336 42 * 0.642/3.28 to 3.21/3.28 ~ 0.195731 to 0.9786585.
Rhyme 0:ce97f6d34336 43 * The linear equation of
Rhyme 0:ce97f6d34336 44 * y = a x + b
Rhyme 0:ce97f6d34336 45 * 0 = a * 0.195731 + b
Rhyme 0:ce97f6d34336 46 * 1 = a * 0.978658 + b
Rhyme 0:ce97f6d34336 47 * results a = 1.277, b = -0.250
Rhyme 0:ce97f6d34336 48 */
Rhyme 0:ce97f6d34336 49 float PSE530::getPressure(void)
Rhyme 0:ce97f6d34336 50 {
Rhyme 0:ce97f6d34336 51 float coef_A = 1.277 ;
Rhyme 0:ce97f6d34336 52 float coef_B = -0.250 ;
Rhyme 0:ce97f6d34336 53 float av = 0.0 ;
Rhyme 0:ce97f6d34336 54 float value = 0.0 ;
Rhyme 0:ce97f6d34336 55 av = coef_A * _ain->read() + coef_B ;
Rhyme 0:ce97f6d34336 56 // printf("Pressure ADC = %.4f\n", av) ;
Rhyme 0:ce97f6d34336 57 value = 1000000 * av ; /* 1MPa at 1.0 */
Rhyme 0:ce97f6d34336 58 value = value / 98066.5 ; /* Pa -> kgf/cm2 */
Rhyme 0:ce97f6d34336 59 return( value ) ;
Rhyme 0:ce97f6d34336 60 }