reading diff-pressure form OMRON D6F-PH0505
D6F-PH.cpp@0:1d476876f987, 2015-06-27 (annotated)
- Committer:
- Chillee
- Date:
- Sat Jun 27 10:17:59 2015 +0000
- Revision:
- 0:1d476876f987
Diff-Pressure Sensor from OMRON
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Chillee | 0:1d476876f987 | 1 | #include "mbed.h" |
Chillee | 0:1d476876f987 | 2 | #include "D6F-PH.h" |
Chillee | 0:1d476876f987 | 3 | |
Chillee | 0:1d476876f987 | 4 | |
Chillee | 0:1d476876f987 | 5 | // Class constructor |
Chillee | 0:1d476876f987 | 6 | |
Chillee | 0:1d476876f987 | 7 | D6F_PH::D6F_PH(I2C *i2c) : |
Chillee | 0:1d476876f987 | 8 | _i2c(i2c){ |
Chillee | 0:1d476876f987 | 9 | } |
Chillee | 0:1d476876f987 | 10 | |
Chillee | 0:1d476876f987 | 11 | |
Chillee | 0:1d476876f987 | 12 | float D6F_PH::read_pressure(void) { |
Chillee | 0:1d476876f987 | 13 | char error; |
Chillee | 0:1d476876f987 | 14 | char rdata[2]; |
Chillee | 0:1d476876f987 | 15 | uint16_t raw_diff_pa; |
Chillee | 0:1d476876f987 | 16 | float diff_pa; |
Chillee | 0:1d476876f987 | 17 | |
Chillee | 0:1d476876f987 | 18 | error = _i2c->write(D6F_ADDR, d6f_config, 5); |
Chillee | 0:1d476876f987 | 19 | wait_us(40000); |
Chillee | 0:1d476876f987 | 20 | error |= _i2c->write(D6F_ADDR, d6f_comp_read, 4); |
Chillee | 0:1d476876f987 | 21 | error |= _i2c->write(D6F_ADDR, d6f_mem_read, 1, true); |
Chillee | 0:1d476876f987 | 22 | error |= _i2c->read(D6F_ADDR, rdata, 2); |
Chillee | 0:1d476876f987 | 23 | if(error) { |
Chillee | 0:1d476876f987 | 24 | return(error); |
Chillee | 0:1d476876f987 | 25 | } |
Chillee | 0:1d476876f987 | 26 | raw_diff_pa = (rdata[0]<<8) + rdata[1]; |
Chillee | 0:1d476876f987 | 27 | diff_pa = ((float)raw_diff_pa-1024)/600 - 50; |
Chillee | 0:1d476876f987 | 28 | return(diff_pa); |
Chillee | 0:1d476876f987 | 29 | } |
Chillee | 0:1d476876f987 | 30 | |
Chillee | 0:1d476876f987 | 31 | |
Chillee | 0:1d476876f987 | 32 | float D6F_PH::read_d6f_temp(void) { |
Chillee | 0:1d476876f987 | 33 | char error; |
Chillee | 0:1d476876f987 | 34 | char rdata[2]; |
Chillee | 0:1d476876f987 | 35 | uint16_t raw_ref_temp; |
Chillee | 0:1d476876f987 | 36 | float ref_temp; |
Chillee | 0:1d476876f987 | 37 | |
Chillee | 0:1d476876f987 | 38 | error = _i2c->write(D6F_ADDR, d6f_config, 5); |
Chillee | 0:1d476876f987 | 39 | wait_us(40000); |
Chillee | 0:1d476876f987 | 40 | error |= _i2c->write(D6F_ADDR, d6f_temp_read, 4); |
Chillee | 0:1d476876f987 | 41 | error |= _i2c->write(D6F_ADDR, d6f_mem_read, 1, true); |
Chillee | 0:1d476876f987 | 42 | error |= _i2c->read(D6F_ADDR, rdata, 2); |
Chillee | 0:1d476876f987 | 43 | if(error) { |
Chillee | 0:1d476876f987 | 44 | return(error); |
Chillee | 0:1d476876f987 | 45 | } |
Chillee | 0:1d476876f987 | 46 | raw_ref_temp = (rdata[0]<<8) + rdata[1]; |
Chillee | 0:1d476876f987 | 47 | ref_temp = ((float)raw_ref_temp-10214)/37.39; |
Chillee | 0:1d476876f987 | 48 | return(ref_temp); |
Chillee | 0:1d476876f987 | 49 | } |
Chillee | 0:1d476876f987 | 50 | |
Chillee | 0:1d476876f987 | 51 | uint8_t D6F_PH::init(void) { |
Chillee | 0:1d476876f987 | 52 | uint8_t error; |
Chillee | 0:1d476876f987 | 53 | |
Chillee | 0:1d476876f987 | 54 | // Init config cmd |
Chillee | 0:1d476876f987 | 55 | //d6f_config[5] = {0x00, 0xD0, 0x40, 0x18, 0x06}; |
Chillee | 0:1d476876f987 | 56 | d6f_config[0] = 0x00; |
Chillee | 0:1d476876f987 | 57 | d6f_config[1] = 0xD0; |
Chillee | 0:1d476876f987 | 58 | d6f_config[2] = 0x40; |
Chillee | 0:1d476876f987 | 59 | d6f_config[3] = 0x18; |
Chillee | 0:1d476876f987 | 60 | d6f_config[4] = 0x06; |
Chillee | 0:1d476876f987 | 61 | |
Chillee | 0:1d476876f987 | 62 | //d6f_comp_read[4] = {0x00, 0xD0, 0x51, 0x2C}; |
Chillee | 0:1d476876f987 | 63 | d6f_comp_read[0] = 0x00; |
Chillee | 0:1d476876f987 | 64 | d6f_comp_read[1] = 0xD0; |
Chillee | 0:1d476876f987 | 65 | d6f_comp_read[2] = 0x51; |
Chillee | 0:1d476876f987 | 66 | d6f_comp_read[3] = 0x2C; |
Chillee | 0:1d476876f987 | 67 | |
Chillee | 0:1d476876f987 | 68 | //d6f_temp_read[4] = {0x00, 0xD0, 0x61, 0x2C}; |
Chillee | 0:1d476876f987 | 69 | d6f_temp_read[0] = 0x00; |
Chillee | 0:1d476876f987 | 70 | d6f_temp_read[1] = 0xD0; |
Chillee | 0:1d476876f987 | 71 | d6f_temp_read[2] = 0x61; |
Chillee | 0:1d476876f987 | 72 | d6f_temp_read[3] = 0x2C; |
Chillee | 0:1d476876f987 | 73 | |
Chillee | 0:1d476876f987 | 74 | //d6f_mem_read[1] = {0x07}; |
Chillee | 0:1d476876f987 | 75 | d6f_mem_read[0] = 0x07; |
Chillee | 0:1d476876f987 | 76 | |
Chillee | 0:1d476876f987 | 77 | d6f_init[0] = 0x0B; |
Chillee | 0:1d476876f987 | 78 | d6f_init[1] = 0x00; |
Chillee | 0:1d476876f987 | 79 | error = _i2c->write(D6F_ADDR, d6f_init, 2); |
Chillee | 0:1d476876f987 | 80 | |
Chillee | 0:1d476876f987 | 81 | return(error); |
Chillee | 0:1d476876f987 | 82 | } |
Chillee | 0:1d476876f987 | 83 |