Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Dewpointer
Форум разработчиков электроники ELECTRONIX.ru > Микроконтроллеры (MCs) > AVR
Andrejka
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!
korobov_michael
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
        {
          ........
         }
    }
ReAl
Цитата(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.
Andrejka
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!!!
_Pasha
Цитата(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...
korobov_michael
Цитата(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).
Andrejka
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
_Pasha
Цитата(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.
korobov_michael
Цитата(_Pasha @ Jan 5 2009, 20:21) *
Please, show me where it resides. Can't find it surfing their site.
korobov_michael
Цитата(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!
_Pasha
Цитата(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?
korobov_michael
Цитата(_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.
Andrejka
Цитата(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!
korobov_michael
Цитата(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
Andrejka
Цитата(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!
radu
hello
i'm beginner and i have the same problem as Andrejka
i try atmega16, 32 and 162 and the resultat was the same
at start the LCD show only "SHT11 MONITOR" on first line
when i disconnect the 10 k pull-up resistor from DATA line of SHT11 sensor it didn't show time and date and the other parameters aren't correct, only heat position swich is correct
i mentioned i'm using CodevisionAvr to compile and i tryed the sugestion metioned in previously posts
i attach the pictures
any sugestion to make it work will be helpfull
best regards
radu
hello again
i solve the problem regarding correct parameters
the solution was putting timer 2 to clock system
but remains one problem
how to display data and time
best regards
korobov_michael
Цитата(radu @ Jan 16 2009, 21:16) *
hello again...

First of all, don't use library functions in ISR - they take many cycles to complete. Try to replace the block

Код
sprintf(lcd_buffer,"%02d:%02d:%02d  %02d/%02d/%04d",t.hour, t.minute, t.second, t.date, t.month, t.year);
lcd_gotoxy(0,3);
lcd_puts(lcd_buffer);



by block, for exampe


Код
uint8_t i = 0;

lcd_buffer[i++] = 'H';

lcd_buffer[i++] = 'e';

lcd_buffer[i++] = 'l';

lcd_buffer[i++] = 'l';

lcd_buffer[i++] = 'o';

lcd_gotoxy(0,3);
lcd_puts(lcd_buffer);

and check if you will see the 4-th string.
The second. Sorry for  bb-offtopic.gif . Don't place your projects in the C disk smile.gif It's not a good practice
B0SC0
I, too, am working on this project and have a problem.

I am using original code, Codevision to compile, AT90S8035-8JI 44 PIN PLCC, 4mhz crystal
20X4 LCD HITACHI COMPATIBLE W/backlight 16 pin connector, SHT11,
PCB that I created.
I have verified all voltages, crystal running at 4 mhz okay.

The problem I am having is the LCD. All character 20x4 are full on blocks. No data. LCD connected to atmel PC0-PC2(lcd pins 4-6) + PC4 - PC7 port(lcd pins 11-14).
In codevision I set the lcd for 20 characters and 4mhz. What other settings do I need to make to at least to get the lcd working right?
I believe hardware is okay, but firmware is not correct.
korobov_michael
Well, first of all give me please a couple of your code. 


After startup all LCDs have the first string is filled by black blocks, and the second is empty. So if in your LCD all strings are filled try to check the contrast
B0SC0
Цитата(korobov_michael @ Jan 23 2009, 08:06) *
Well, first of all give me please a couple of your code. 


After startup all LCDs have the first string is filled by black blocks, and the second is empty. So if in your LCD all strings are filled try to check the contrast


The code was posted at the beginning of the thread. It is the original code.

The contrast control is fine. I can dim or max the contrast. It is a 4 line x 20 character lcd that is called for in the original project(also posted at the beginning of the thread).

All four lines are just blocks without any data/characters.

Attached is my schematic.

I am new to atmel and I am not sure if I have the initial settings correct for burning this code.

I know the code has been altered to make the data correct, but right now I just want to get the lcd working right.

Thanks

B0SC0
Andrejka
Цитата(B0SC0 @ Jan 23 2009, 17:05) *
The code was posted at the beginning of the thread. It is the original code.

The contrast control is fine. I can dim or max the contrast. It is a 4 line x 20 character lcd that is called for in the original project(also posted at the beginning of the thread).

All four lines are just blocks without any data/characters.

Attached is my schematic.

I am new to atmel and I am not sure if I have the initial settings correct for burning this code.

I know the code has been altered to make the data correct, but right now I just want to get the lcd working right.

Thanks

B0SC0





Just define which MCU port is connected to LCD. In original code this is a PORT A, but LCD connected to PORT C (mistake?).
Change code to:

CODE
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>



Regards
B0SC0
Цитата(Andrejka @ Jan 24 2009, 14:40) *
Just define which MCU port is connected to LCD. In original code this is a PORT A, but LCD connected to PORT C (mistake?).
Change code to:

CODE
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>



Regards



Yes, I had already changed that, still no luck.

I also defined in codewizard, lcd,20,4mhz,fast start, no protection, Memory model
Small
External RAM size : 0
Data Stack size : 192


How should I set up codevision c compiler code generator parameters?

I am not sure of all the steps.
I can build all but not sure if all the parameters are right.
Do I need to include math.h,stdio.h,delay.h,along with lcd.h when I build all?

thanks
Andrejka
Цитата(B0SC0 @ Jan 25 2009, 08:25) *
Yes, I had already changed that, still no luck.

I also defined in codewizard, lcd,20,4mhz,fast start, no protection, Memory model
Small
External RAM size : 0
Data Stack size : 192


How should I set up codevision c compiler code generator parameters?

I am not sure of all the steps.
I can build all but not sure if all the parameters are right.
Do I need to include math.h,stdio.h,delay.h,along with lcd.h when I build all?

thanks



First I change "sprintf" function features in CodeVision software from "int, width" to "float, width, precision". Twice I change for Mega8535 "Data Stack Size" upto 256 bytes. All headers listed in original code must be included.
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Invision Power Board © 2001-2025 Invision Power Services, Inc.