|
Dewpointer |
|
|
|
Jan 2 2009, 19:28
|
Участник

Группа: Участник
Сообщений: 18
Регистрация: 7-12-08
Пользователь №: 42 268

|
Hi, I found a schematic of simple temperature, huminidity and dewpoint measuring cicruit. Originally device uses: Sht11 sensor, AT90S8535 MCU, and HD44780 like 20x4 LCD. In my project I replace Sht11 with Sht15 (from Sparkfun), At90s8535 is replaced with newer Atmega8535 (Atmel datasheets say - this is a at90s8535 direct repalcement). But this device working incorrectly, so I have only "Sht11 Monitor" label on LCD, without sensor readings. If possible please help me with source code. Source project:    URL: Source project - http://www.embedtronics.com/sht11/sht11.htmlSource code - http://www.embedtronics.com/sht11/shtdemo1.cSchematic - http://www.embedtronics.com/sht11/SHT11Sch.pdfMy device show only this label:  I tried to simulate device in Proteus simulator but this program show the same screen, without sensor readings, only label. Thank You!
|
|
|
|
|
Jan 3 2009, 06:45
|
Частый гость
 
Группа: Свой
Сообщений: 118
Регистрация: 11-03-07
Из: Украина, Харьков
Пользователь №: 26 059

|
I found the following: 1. At initialization, you set the bit AS2 in register ASSR (ASSR = 0x08). This means you want the Timer2 to be clocked from TOSCs pins (PC6, PC7). But these pins are connected to LCD and therefore canot be clock sources. 2. Since you didn't clock Timer2, you cannot receive interrupts from this timer and absence of last LCD string with time confirms this. 3. It is not good practice to use library functions like sprintf in interrupt handlers - they take a lot of processor time (In my IAR it taken approx. 16000 cycles, taking into account that you use CodeWizard it can take more). I'd like to propose the following. Don't set the AS2 bit in ASSR. Using the crystal of 4MHz interrupts from Timer2 will be every (256 * 128) / 4MHz = 1/122s seconds. Correct the interrupt handler in the following way: Код interrupt [TIM2_OVF] void timer2_ovf_isr(void) { static unsigned char sec122; // 1/122 seconds if(++sec122 > 122) { sec122 = 0; if (++t.second==60) //keep track of time, date, month, and year { ........ } } The next thing - do not use the 4MHz crystal in tasks where real time is needed. Try to use the 3.6864MHz and TCCR2 = 0x04; You'll get the exact 1/225 seconds timer2 interval: Код interrupt [TIM2_OVF] void timer2_ovf_isr(void) { static unsigned char sec122; // 1/122 seconds if(++sec225 > 225) { sec225 = 0; if (++t.second==60) //keep track of time, date, month, and year { ........ } }
|
|
|
|
|
Jan 3 2009, 07:30
|

Нечётный пользователь.
     
Группа: Свой
Сообщений: 2 033
Регистрация: 26-05-05
Из: Бровари, Україна
Пользователь №: 5 417

|
Цитата(Andrejka @ Jan 2 2009, 21:28)  I tried to simulate device in Proteus simulator but this program show the same screen, without sensor readings, only label. "T:1fC H:1f%" looks like no floating point formats support in sprintf function - "small" formatter used 1. Try integer formats Код sprintf(lcd_buffer,"T:%5dC H:%5d%%", (int)temp_val.f, (int)humi_val.f); for confidence 2. Check compiler/linker options for linking appropriate ("large") version of formatter function.
--------------------
Ну, я пошёл… Если что – звоните…
|
|
|
|
|
Jan 4 2009, 13:38
|
Участник

Группа: Участник
Сообщений: 18
Регистрация: 7-12-08
Пользователь №: 42 268

|
Thanks for reply! Maybe I just simple attach a watch 32768 Hz crystal to TOSC1 ant TOSC2 pins, to run clock correctly? And I solve the "T:1fC H:1f%" readings problem, so I change "sprintf" function features in CodeVision software from "int, width" to "long, width, precision".  But some issue remain in th source code, because with sensor i give this LCd screen:  and without sensor like this (time, and readings are in correct format, but these no data from sensor):  Moddeling in Proteus give the same results. Maybe problem is in this block of code, because its like disabled (I am not programer)...  Thanks!!!
|
|
|
|
|
Jan 4 2009, 14:11
|
;
     
Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509

|
Цитата(Andrejka @ Jan 4 2009, 17:38)  Maybe I just simple attach a watch 32768 Hz crystal to TOSC1 ant TOSC2 pins That's just right! Цитата But some issue remain in th source code, because with sensor i give this LCd screen: This code need to be traced. Verify the output is according to the sensor datasheet. Цитата (I am not programer)...  I was going to recommend you leave the CodeVision and try WinAVR...
|
|
|
|
|
Jan 5 2009, 06:44
|
Частый гость
 
Группа: Свой
Сообщений: 118
Регистрация: 11-03-07
Из: Украина, Харьков
Пользователь №: 26 059

|
Цитата(Andrejka @ Jan 4 2009, 15:38)  Maybe problem is in this block of code, because its like disabled Hardly. Such piece of code is present some lower in file. Tell me please did you change Fuses? As I understand you generated code for 4MHz quartz, but really work with 1MHz internal oscillator (this is important for functions delay_ms, delay_us etc).
|
|
|
|
|
Jan 5 2009, 18:42
|
Частый гость
 
Группа: Свой
Сообщений: 118
Регистрация: 11-03-07
Из: Украина, Харьков
Пользователь №: 26 059

|
Цитата(_Pasha @ Jan 5 2009, 20:21)  Please, show me where it resides. Can't find it surfing their site.
|
|
|
|
|
Jan 5 2009, 20:07
|
Частый гость
 
Группа: Свой
Сообщений: 118
Регистрация: 11-03-07
Из: Украина, Харьков
Пользователь №: 26 059

|
Цитата(Andrejka @ Jan 5 2009, 16:38)  Sample_Code_humidity_sensor_SHTxx.pdf I have modeled the design in Proteus. Due to differences in architectures 8051 and AVR there are time restrictions in C instructions. Each assembler instruction in 8051 requires 12 clock cycles and in AVR it takes approx two cycles. So the same code will take different cycles to complete. At first time I obtained errors during measurement. When I inserted delays in code Код for (i=0;i<65535;i++) { __delay_cycles(14); //approx. 1us at 14.7456MHz quartz if(PINB&_BV(0) == 0) break; //wait until sensor has finished the measurement } in function s_measure(), I obtained all measurements are adequate. P.S. I'm using IAR, so you have to use your delay function. If you want, I'll give you source codes for IAR that I have made to test. Regards!
Сообщение отредактировал korobov_michael - Jan 5 2009, 20:08
|
|
|
|
|
Jan 5 2009, 21:32
|
Частый гость
 
Группа: Свой
Сообщений: 118
Регистрация: 11-03-07
Из: Украина, Харьков
Пользователь №: 26 059

|
Цитата(_Pasha @ Jan 5 2009, 22:22)  You simply made this timeout long enough. Yes. I have never worked with SHT11. Andrejka said that in his Proteus simulation the program didn't work properly. So I think that I found the solution. Let Andrejka say.
|
|
|
|
|
Jan 6 2009, 05:52
|
Участник

Группа: Участник
Сообщений: 18
Регистрация: 7-12-08
Пользователь №: 42 268

|
Цитата(korobov_michael @ Jan 6 2009, 00:07)  I have modeled the design in Proteus. Due to differences in architectures 8051 and AVR there are time restrictions in C instructions. Each assembler instruction in 8051 requires 12 clock cycles and in AVR it takes approx two cycles. So the same code will take different cycles to complete. At first time I obtained errors during measurement. When I inserted delays in code Код for (i=0;i<65535;i++) { __delay_cycles(14); //approx. 1us at 14.7456MHz quartz if(PINB&_BV(0) == 0) break; //wait until sensor has finished the measurement } in function s_measure(), I obtained all measurements are adequate. P.S. I'm using IAR, so you have to use your delay function. If you want, I'll give you source codes for IAR that I have made to test. Regards! Yes, if possible provide IAR code for me. Thanks!
|
|
|
|
|
Jan 6 2009, 07:39
|
Частый гость
 
Группа: Свой
Сообщений: 118
Регистрация: 11-03-07
Из: Украина, Харьков
Пользователь №: 26 059

|
Цитата(Andrejka @ Jan 6 2009, 07:52)  Yes, if possible provide IAR code for me. Here it is. In 'hardware' folder there is proteus simulation. Please remember, that I just worked to setup correct interface, so I'm not calculate temperature, and my humidity calculations contain non-linear not compensated errors. Anyway, compensation will not be a problem I hope. Regards P.S. Please remember, that code provided is not of high quality - I've just adapted the code proposed by Sensirion in the way that will be easy of use to you. But if you will only measure humidity, temperature and will have unlimited power source, it will work Regards
Сообщение отредактировал korobov_michael - Jan 6 2009, 07:46
|
|
|
|
|
Jan 6 2009, 21:43
|
Участник

Группа: Участник
Сообщений: 18
Регистрация: 7-12-08
Пользователь №: 42 268

|
Цитата(korobov_michael @ Jan 6 2009, 00:07)  I have modeled the design in Proteus. Due to differences in architectures 8051 and AVR there are time restrictions in C instructions. Each assembler instruction in 8051 requires 12 clock cycles and in AVR it takes approx two cycles. So the same code will take different cycles to complete. At first time I obtained errors during measurement. When I inserted delays in code Код for (i=0;i<65535;i++) { __delay_cycles(14); //approx. 1us at 14.7456MHz quartz if(PINB&_BV(0) == 0) break; //wait until sensor has finished the measurement } in function s_measure(), I obtained all measurements are adequate. P.S. I'm using IAR, so you have to use your delay function. If you want, I'll give you source codes for IAR that I have made to test. Regards! Bingo, it now working!!! I reads Michael's suggestion about delay and just insert 1 us delay into project source code. Output hex from CodeVison works correctly in the Proteus and also in real hardware works fine! All measurements are adequate.  I think value of this delay are not very critical because 5 us works also. Maybe author of this project just forgotten about this small delay ... Big Thanks Boys! Regards from Vilnius!
|
|
|
|
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0
|
|
|