X-Git-Url: https://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=DS18B20_Thermocouble_DS2438_SHT%2FDS18B20_DS2438.c;h=8ffaa533f10503658a45fc5a4ce725d6fe57511a;hp=4927b997f6d1441217843e94cff48377db19032f;hb=refs%2Fheads%2Fmaster;hpb=6467d8138460abffd9ddabc7b0a9f00c764af19c diff --git a/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c index 4927b99..8ffaa53 100644 --- a/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c @@ -39,17 +39,25 @@ #include #include #include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/SHT2x.h" +#include "../common/I2C/SHT2xV2.h" +#include "../common/owSlave_tools.h" +OWST_EXTERN_VARS -extern void OWINIT(); -extern void EXTERN_SLEEP(); +//#define K_Type +#define J_Type +#ifdef K_Type //const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176}; const float k_rs[61] PROGMEM ={ -212.538462, -166.260870, -124.892857, -97.562500, -66.888889, -34.157895, 0.000000, 24.125000, 48.585366, 72.731707, 96.829268, 121.097561, 145.700000, 170.600000, 195.650000, 220.625000, 245.365854, 269.853659, 294.119048, 318.192771, 342.166667, 366.000000, 389.761905, 413.428571, 437.023810, 460.558140, 484.047619, 507.511628, 530.976190, 554.418605, 577.883721, 601.395349, 624.952381, 648.571429, 672.285714, 696.073171, 719.976190, 744.000000, 768.146341, 792.439024, 816.853659, 841.414634, 866.125000, 890.975000, 916.000000, 941.179487, 966.525000, 992.025641, 1017.717949, 1043.589744, 1069.657895, 1095.945946, 1122.432432, 1149.173333, 1176.189189, 1203.472222, 1231.083333, 1259.000000, 1287.285714, 1315.941176, 1344.941176}; #define k_ofs 6 +#endif +#ifdef J_Type +#define k_ofs 0 +//J-Type +const float k_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088}; +#endif -//const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088}; double gettemp_rs(double V) { uint8_t iv=(uint8_t)(V+k_ofs); float t0=pgm_read_float(&(k_rs[iv])); @@ -66,55 +74,8 @@ uint8_t owid2[8]={0x26, 0xA7, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x20};/**/ uint8_t config_info1[26]={0x01,0x02 ,0x00,0x00, 0x00,0x00, 0x00,0x00, 0x02,6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; uint8_t config_info2[26]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x02,7,0x00,7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=5; - - -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) -ISR(WATCHDOG_vect) { -#else -ISR(WDT_vect) { -#endif - //sleep_disable(); // Disable Sleep on Wakeup - wdcounter++; - if (reset_indicator==1) reset_indicator++; - else if (reset_indicator==2) mode=0; -/* if (timeout==2) { - DIS_TIMER; - EN_OWINT; - mode=OWM_SLEEP; - } - timeout++;*/ - //sleep_enable(); // Enable Sleep Mode - -} - -int testSW(void) { - uint8_t r; - DDRB&=~(1<0) { if (par==0) { - //PORTB|=(1<1000) humidityRH=1000; + getSHT2xHumTemp(&temperatureC,&humidityRH); + double RH=humidityRH*10.0; + TC =temperatureC *10.0; + if (testSW()) { - am2302_hum= humidityRH*10.0; - am2302_temp=temperatureC*25.6; - // - config_info2[5]=8; - }else{ - double hhum=(1.0546-0.000216*temperatureC)*(humidityRH); - //am2302_hum=0.318*hhum +76.0; - am2302_hum=0.31*hhum +80; - am2302_temp=temperatureC*25.6; - //am2302_temp=am2302_temp-45; + DS2438_2_VAD=RH; + DS2438_2_TEMP=TC*25.6; + + config_info2[5]=12; + + }else{ + + double hhum=(1.0546-0.000216*TC)*(RH); + DS2438_2_VAD=0.31*hhum +80; + DS2438_2_TEMP=TC*25.6; config_info2[5]=7; } } + DS2438_2_VDD=0x01F4; ares[par]=ADmess(); par++; if (par>15) par=0; wdcounter=0; } - if (gcontrol==1) { + if ((gcontrol&1)==1) { gcontrol=0; sum=0; for(uint8_t i=0;i<16;i++) { sum+=ares[i]; } - V=sum/20.0/1024.0*1.12*1000.0/16.0;//Spannung in mV + V=sum/20.0/1024.0*1.18*1000.0/16.0;//Spannung in mV //V=sum/20.0/1024.0*1.01*1000.0/16.0; int16_t htemp; ktemp=gettemp_rs(V); //htemp=(ktemp*16)/10; - htemp=(ktemp*16+temperatureC*1.6)/10; + htemp=(ktemp*16+TC*1.6)/10; int16_t w=htemp; int8_t t8=w>>4;