реклама на сайте
подробности

 
 
2 страниц V   1 2 >  
Reply to this topicStart new topic
> Dewpointer
Andrejka
сообщение Jan 2 2009, 19:28
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 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.html
Source code - http://www.embedtronics.com/sht11/shtdemo1.c
Schematic - http://www.embedtronics.com/sht11/SHT11Sch.pdf


My 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!
Go to the top of the page
 
+Quote Post
korobov_michael
сообщение Jan 3 2009, 06:45
Сообщение #2


Частый гость
**

Группа: Свой
Сообщений: 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
        {
          ........
         }
    }
Go to the top of the page
 
+Quote Post
ReAl
сообщение Jan 3 2009, 07:30
Сообщение #3


Нечётный пользователь.
******

Группа: Свой
Сообщений: 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.


--------------------
Ну, я пошёл… Если что – звоните…
Go to the top of the page
 
+Quote Post
Andrejka
сообщение Jan 4 2009, 13:38
Сообщение #4


Участник
*

Группа: Участник
Сообщений: 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!!!
Go to the top of the page
 
+Quote Post
_Pasha
сообщение Jan 4 2009, 14:11
Сообщение #5


;
******

Группа: Участник
Сообщений: 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)...

biggrin.gif I was going to recommend you leave the CodeVision and try WinAVR...
Go to the top of the page
 
+Quote Post
korobov_michael
сообщение Jan 5 2009, 06:44
Сообщение #6


Частый гость
**

Группа: Свой
Сообщений: 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).
Go to the top of the page
 
+Quote Post
Andrejka
сообщение Jan 5 2009, 14:38
Сообщение #7


Участник
*

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



My Atmega8535 fuses are: CKSEL3..0 - 1111, and I using exeternal 4 MHz crystal, the same as in original design from http://www.embedtronics.com/sht11/sht11.html

Sht11 and Sht15 sensors manufacturer provide a sample C code for AT89S53 with data output into UART (for eg. PC hyperterminal).

http://www.sensirion.com/en/pdf/product_in...ensor_SHTxx.pdf

Сообщение отредактировал Andrejka - Jan 5 2009, 14:44
Go to the top of the page
 
+Quote Post
_Pasha
сообщение Jan 5 2009, 18:21
Сообщение #8


;
******

Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509



Цитата(Andrejka @ Jan 5 2009, 18:38) *
Sht11 and Sht15 sensors manufacturer provide a sample C code for AT89S53

It's quiet interesting.
Please, show me where it resides. Can't find it surfing their site.
Go to the top of the page
 
+Quote Post
korobov_michael
сообщение Jan 5 2009, 18:42
Сообщение #9


Частый гость
**

Группа: Свой
Сообщений: 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.

Прикрепленные файлы
Прикрепленный файл  Sample_Code_humidity_sensor_SHTxx.pdf ( 65.38 килобайт ) Кол-во скачиваний: 205
 
Go to the top of the page
 
+Quote Post
korobov_michael
сообщение Jan 5 2009, 20:07
Сообщение #10


Частый гость
**

Группа: Свой
Сообщений: 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
Go to the top of the page
 
+Quote Post
_Pasha
сообщение Jan 5 2009, 20:22
Сообщение #11


;
******

Группа: Участник
Сообщений: 5 646
Регистрация: 1-08-07
Пользователь №: 29 509



Цитата(korobov_michael @ Jan 6 2009, 00:07) *
Each assembler instruction in 8051 requires 12 clock cycles and in AVR it takes approx two cycles.

You simply made this timeout long enough.

2Andrejka: what about watchdog? Is it kept off?
Go to the top of the page
 
+Quote Post
korobov_michael
сообщение Jan 5 2009, 21:32
Сообщение #12


Частый гость
**

Группа: Свой
Сообщений: 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.
Go to the top of the page
 
+Quote Post
Andrejka
сообщение Jan 6 2009, 05:52
Сообщение #13


Участник
*

Группа: Участник
Сообщений: 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!
Go to the top of the page
 
+Quote Post
korobov_michael
сообщение Jan 6 2009, 07:39
Сообщение #14


Частый гость
**

Группа: Свой
Сообщений: 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
Прикрепленные файлы
Прикрепленный файл  DewPoint.rar ( 76.22 килобайт ) Кол-во скачиваний: 86
 
Go to the top of the page
 
+Quote Post
Andrejka
сообщение Jan 6 2009, 21:43
Сообщение #15


Участник
*

Группа: Участник
Сообщений: 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!
Go to the top of the page
 
+Quote Post

2 страниц V   1 2 >
Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 19th July 2025 - 08:07
Рейтинг@Mail.ru


Страница сгенерированна за 0.01491 секунд с 7
ELECTRONIX ©2004-2016