X-Git-Url: http://git.smho.de/gw/?a=blobdiff_plain;f=DS18B20_VOC_DS2438_SHT%2FDS18B20_DS2438.c;h=0e9ae0aa3d49cb1cc959b756ba947064c300df5b;hb=cd92472e6fd63693741f8e168123a4182802651b;hp=d455f89528666bad8d861f9d60cc30a476690118;hpb=c612a6c03106176eb24430e254ea8a1dfd8e1343;p=owSlave2.git diff --git a/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c index d455f89..0e9ae0a 100644 --- a/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c @@ -41,33 +41,17 @@ #include "../common/I2C/USI_TWI_Master.h" #include "../common/I2C/MAX1164x.h" #include "../common/I2C/SHT2x.h" -#include +#include "../common/calibr.h" extern void OWINIT(); extern void EXTERN_SLEEP(); -const int16_t hl[5] PROGMEM = {0,400,650,850,1000}; //H*10 - -//log values *1000 -const int16_t il[5][5] PROGMEM= { -{470, 247, 140, 77, 49}, -{336, 104, 0, -62, -83}, -{207, -20, -139, -198, -223}, -{86, -139, -248, -315, -342}, -{-30, -248, -371, -431, -462}}; - - - - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/ -uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/ -uint8_t config_info1[16]={0x08,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; -uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x07,0x08, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +volatile uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/ +volatile uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/ +volatile uint8_t config_info1[16]={0x08,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; +volatile uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x07,0x08, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; #if (owid>128) #error "Variable not correct" @@ -146,8 +130,8 @@ volatile uint16_t am2302_hum; uint8_t userRegister[1]; int16_t sRH,sT; -volatile double temperatureC,humidityRH; -volatile double l; +double temperatureC,humidityRH,hhum; +double l; uint8_t max_adr=0; #define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL @@ -155,43 +139,25 @@ uint8_t max_adr=0; #define CH0_CH1 MAX1164x_C_SCAN0 //|MAX1164x_C_CS0 -//T und H mit 10 multipliziert - -double interp(int16_t t, int16_t h) { -double ya,yb; -uint8_t h1,h2,t1,t2; -int16_t x1,x2,y1_,y2; - h1=0; - h2=0; - for(uint8_t i=0;i<5;i++) { - int16_t hlw=pgm_read_word(&(hl[i])); - if (h>hlw) h1=i; - } - h2=h1+1; - if (h2>4) {h2=4;h1=3;} - t2=((uint8_t)t/100); //t mit 10 multipliziert - if (t2<1) t2=1; - t1=t2-1; - x1=pgm_read_word(&(hl[h1])); - x2=pgm_read_word(&(hl[h2])); - y1_=pgm_read_word(&(il[t1][h1])); - y2=pgm_read_word(&(il[t1][h2])); - double d=(double)(h-x1)/(x2-x1); - ya=y1_+(y2-y1_)*d; - y1_=pgm_read_word(&(il[t2][h1])); - y2=pgm_read_word(&(il[t2][h2])); - yb=y1_+(y2-y1_)*d; - x1=(t1+1)*100; - x2=x1+100; - return exp((ya+(yb-ya)/(double)(x2-x1)*(t-x1))/1000.0); - + +inline double interp(double t, double h) { + double h2; + double t2; + h2=h*h; + t2=t*t; + return 4.76111e-9*h2*t2-3.96956e-7*h2*t+0.0000408889*h2-1.07132e-6*h*t2+0.000115968*h*t-0.0101333*h+0.000163806*t2-0.0241179*t+1.80591; } + uint8_t cmode=0; double R0=0; int16_t hr; uint8_t startup=5; +uint8_t reset_R0=0; +int16_t mr; +double ip; int main(void){ + //volatile double test=calibr_hum(20,1,20); PRR|=(1< 1,5V @@ -261,36 +220,73 @@ int main(void){ sei(); //DDRB|=(1<>8)&0xFF; + + while(EECR & (1<>8; + EECR |= (1<0) { if (startup!=0) startup--; - //PORTB|=(1<1.8) { + //l+=1.5; //Spannung real + mr+=6000; + } + //if (l>1.8) { + if (mr>7200) { if (cmode==0) { MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1); cmode=1; pack2.page3[4]=cmode; } } - if (l<1.6) { + //if (l<1.6) { + if (mr<6400) { if (cmode==1) { MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M); cmode=0; @@ -299,18 +295,21 @@ int main(void){ } - hr=l*10000.0; + //hr=l*10000.0; + hr=mr*5/2; pack2.page3[2]=hr&0xFF; pack2.page3[3]=(hr>>8)&0xFF; - l=( 3/l- 1) *27; + l=mr/4000.0; + l=( 3/l- 1) *30; pack2.current=l*100; - float ip=interp(temperatureC,humidityRH); + //ip=interp(temperatureC,humidityRH); hr=ip*1000; pack2.page3[5]=hr&0xFF; pack2.page3[6]=(hr>>8)&0xFF; l=l/ip; - if (startup!=0){ + + if (startup==0){ if (l>R0) { R0=l; hr=R0*100; @@ -334,7 +333,10 @@ int main(void){ } l=l/R0; l=log(1/l); - l=l*160; //fuer DS18B20 + l=l*160*4; //fuer DS18B20 + if (l>500) { + l=100; + } wdcounter=0; }