Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Help] 8051 interfacing sensirion SHT7X digital sensor

Status
Not open for further replies.
Okie,i understand what you gave me now.Thank you !

Another question is that, for this enginerring unit conversion using 89c52. Why should things be like this?Is it we need a transformation of the equation to a equation where the microprocessor can perform?

You said i do not need to follow the approximation given? What this mean ?

Sorry... maybe i am abit slow !!
 

Hi,
The method suggested is to overcome the need for floating point calculations. While the method saves calculation time, it involves neglecting some terms and to that extent it is inaccurate. By doing a direct 16 bit integer arithmetic, though it takes little extra time, which is not critical in this case, you can get more accurate results. In any case you need not do floating point calculations.

Regards,
Laktronics
 
Sorry for late update.

For the temperature formula
T=0.01[BCD of ( Rdt -1 in 13th bit)+100D]

I seperate the 14th bit result to two 8bit register,lets say register B holding the most significant byte and A holding the least significant byte.

So for the +100D= 0110 0100B
ADD A,#0110 0100B

For Rdt -1 in 13th bit (13th bit of Rdt = 5th bit in register A)
SUBB B,#0001 0000B

Hence A hold the least significant byte and B hold the most significant byte.

I hav two question up to here.
1)After this operation i should set the OV flag?To indicate the CPU that B and A both together representing a 16bit number?
2)How to store the 14bit result in register A and B? Is it by a manual way like :
P2.7 's bit X 2^7
p2.6 's bit X 2^6
p2.5 's bit X 2^5
p2.4 's bit X 2^4
p2.3 's bit X 2^3
p2.2 's bit X 2^2
p2.1 's bit X 2^1
p2.0 's bit X 2^0

P0.7 's bit X 2^7
p0.6 's bit X 2^6
p0.5 's bit X 2^5
p0.4 's bit X 2^4
p0.3 's bit X 2^3
p0.2 's bit X 2^2
p0.1 's bit X 2^1
p0.0 's bit X 2^0

And using add operation add the result one by one in the register?
I think this should be working right?

Thank you.
 

Hi,
When you are picking up the bit one by one from the sensor, and since you get MSB first, after storing each bit in carry, you do an rlc a( rotate Accu. left with carry ) instruction and store each bit in the accumulator, starting with its LSB due to left rotation.
After collecting each byte, store it in a memory location say first byte in 30h, next byte in 31h and so on. When you want to do computation, read these bytes back into accumulator and B reg and do the processing.
When you add as above, you first clear carry and do an ADDC (ADD with carry) instruction and subsequently add this carry to the MSByte. Similarly, while subtracting the 13th bit as above you should look for any carry (borrow) though in this case I expect the MS nibble to be always greater than 0001b.
Regards,
Laktronics
 
Okie,i added RLC to store the byte in R0(for MSB) and R1(for LSB) register

Is this the correct way? I uploaded the code

And i try to compute the temperature equation after that also.

I don't understand for the subtraction part.

while subtracting the 13th bit as above you should look for any carry (borrow) though in this case I expect the MS nibble to be always greater than 0001b.

Mean after subtraction i should check the carry? For what i check the carry?

Here there is no borrow for bit7 from bit8 in the MSB because both this two bit is equal to zero.So the carry won't be set rite?
 

I have a question about subtration,
Lets say a 16bit number 1010 1010 0110 0000B and i want to minus a 100D from it which is equal to

1010 1010 0110 0000B - 0110 0100B

If i do this operation in 8051, i need to seperate 1010 1010 0110 0000B into MSB and LSB to do the subtration is it?

Let's say
mov R0,#1010 1010B
mov A,#0110 0000B

SUBB A,#100D (which equal to 0110 0000B - 0110 0100B)

So now 1010 1010B - 0110 0000B = 1111 1100 B
Where C and AC flag set to 1.

So 8051 take it as unsign number ?
And if C flag set to 1,i need to - 1 for the MSB right?

Thank you !
 

Hi,
1. As far as 100D is concerned, it is added and not subtracted, it is to compensate for a 1°C error because of subtraction of 13th bit instead of 4000D.
2. For negative temperatures, the readings will be within a 12 bit number. This is because, the sensor range of -40°C to +120°C (160° total) is represented by one 14 bit number. In the equation since he is subtracting 40D from the (reading*0.01), I guess the maximum value in decimal of reading should be 16000. So I am expecting that for any +ve value of temp., the 13th bit or a higher bit should be set. However, if you want to measure -ve temp., you have to do a signed arithmetic while subtracting the 13th bit.
3. Have you cross checked at least a reading of temperature using a calculator to find out there is no error in the assumptions? For example, it is assumed that the readings are binary and the -40 in the equation is decimal, what if the readings are in BCD? So, atleast calculate manually using a calculator one reading, to check there is no mistake done in the assumptions and then only proceed with the software implementation.
4. Storing the reading in RO/R1 is OK as they can be more esily manipulated.

If I have left out any point to reply, please let me know.
Regards,
Laktronics
 
Yes i did do some assumption with the value,so i notice RDT - 1 in 13bit is always valid or positive at temperature > 1 degree C

Sorry, the above assumption is made for the 12bit humidity calculation.

As i simplified the last equation to
Rh=0.01[4(Rdh-100D)+2n1n2] - 2.8x10^-4(n1.256)^2]


Let Rdh=1001 0011 0001 = 75%RH [without compensation]

and i want to minus a 100D from it which is equal to

1001 0011 0001B - 0110 0100B

If i do this operation in 8051, i need to seperate 1001 0011 0001B into MSB and LSB to do the subtration is it?

Let's say
mov R0,#0000 1001B
mov A,#0011 0001B

SUBB A,#100D (which equal to 0011 0001B - 0110 0100B)

And my question is:

1)So now the microprocessor take 0011 0001B- 0110 0100B = 1100 1101 ?
Where C and AC flag set to 1?

2)And if C flag set to 1,i need to minus 1 for the MSB right?

3)How do i check if C flag trigger to 1 and if it is triggered i want to minus a 1 for the MSB bye?

Thank you !
 

Hi,
Yes when you do multi byte arithmetic you have to keep track of carry and add/ sub to MS byte when set. You can clear carry first and use Subb/ADDC instruction to automatically take care of carry.
Regards,
Laktronics
 
How carry will be automatically handle using SUBB command in my case? As i seperate MSB and LSB in two register?Is is like what i do below

Example:
1001 0011 0001B - 0110 0100B

Let's say
mov R0,#0000 1001B
mov A,#0011 0001B

SUBB A,#100D (which equal to 0011 0001B - 0110 0100B)

Here Carry flag set.

MOV A,R0
SUBB A,#00H (SUBB command will minus value of A with 1 since carry is set?)

Is it the way??

I need some example for me to understand how to really work it out.
My reference book have insufficient information.

Thank you very much
 

Hi,
First Clear Carry and then Subb 100D from LSByte. Then you Subb zero from MSbyte, which will take care of carry if set, you do not have to check for carry status separately. since in this case you know Subtracting 1 from MSB will not generate a carry, no further checking of carry is required. This is what I meant by automatically taking care of carry when using Subb/Addc.
Regards,
Laktronics
 
Erm...now only i notice

T = 0.01[ BCD of ( Rdt - 1 in 13 th bit) +100D]

BCD and binary format is different things...Sorry

But why want it in BCD form?

Added after 1 minutes:

laktronics said:
Hi,
First Clear Carry and then Subb 100D from LSByte. Then you Subb zero from MSbyte, which will take care of carry if set, you do not have to check for carry status separately. since in this case you know Subtracting 1 from MSB will not generate a carry, no further checking of carry is required. This is what I meant by automatically taking care of carry when using Subb/Addc.
Regards,
Laktronics

Okie understood !! thank you !!
 

Hi,
BCD is the binary representation of decimal digits and is mainly used for seven segment displays for human interfacing. Even if you directly output on to a port, a two digit BCD number is easy to read. Using 4 bits, a binary or hex representation stores 16 values whereas the BCD uses only 0 to 9 , ten values. If only we used a hex maths in our day to day life, we could have directly interfaced ourselves with computers and there would have been fewer digits in the world!!

Regards,
Laktronics
 

Lactronics i faced a seriuos problem here...

According to my previous testing, there was trigger on LEDs.

Just now i tested again,

But why my p2.7 and p2.6 LEDs didnt light up ? This two should equal to 0 and should lighten up the LEDs right?

oh my god....what happened...
 

Hi,
Are other bits of P2 changing?, if so, the temperature change might have caused a change in bit pattern, now it is time for you to observe all bits simultaneously.
Regards,
Laktronics.
 

OHh..i found out why !!

Now i tested and get the bits, and they give me correct arrangement in correct temperature. Thank you !

Added after 3 hours 55 minutes:

Hi, i am working on the humidity formula
Rh=0.01[4(Rdh-100D)+2n1n2]-2.8x10^-4(n1.256)^2]

i've done up to the stage 49(Rdh-100D)+2n1n2]
1)I think it is working but if you have time could you please check it?Else just skip the code down there.

2)for the -2.8x10^-4(n1.256)^2 , i had calculate out all the 15 result using calculator.But i don't have any idea how to do it? I know how to define word/byte using assembly.But how to load the result from the address i specified?

;pre assume i have the RH reading 1001 0011 0001 (2353) where 1001:n1 , 0011:n2 , 0001:n3
;and i store n1 in R2 , n2n3 in R3

CLR C
MOV A,R3
SUBB A,#64H ; subbtrating a 100D value from Less significant byte
MOV R4,A
Mov A,R2
SUBB A,#00H
MOV R5,A

;now n1 in R2, n2n3 in R3 , R4 hold LSbyte value after -100D , R5 hold MSbyte value after - carry if there are carry.

MOv B,#4D ;multiply 4 for Rdt-100D
MUL AB
MOV R5,A

MOV A,R4
MOV B,#4D
MUL AB
MOV R0,A
MOV R1,B
MOV A,R5
ADD A,R1
MOV R5,A

;now R0 hold the LSbyte after x4 , R5 hold the MSbyte after x4

MOV A,R3 ;getting 2n1n2
MOV B,#2D
MUL AB

CLR C
ADD A,R0
MOV R0,A
MOV A,B
ADDC A,R5
MOV R5,A

;So until now i had calculated this part [4(RDh-100D)+2n1n2], with MSbyte stored in R5 and LSbyte store in R0
 

Hi,
I will get back to you later regarding your code, I hope it should be OK.

Regarding creation of the table, you can use .DB (define byte) directive of assembler and store the 16 values for n1 in a known code area (specified by .ORG) Let us say the starting address of the table is 1000h. Ensure that this address lies outside your code area.

Then in your program to get the byte correspoding to any n1 value got from a reading and stored in say 30h location , do the following:
1.Mov dptr,#1000h
2. Mov a, 30h
3. Movc a,@a+dptr ; A will get the data corresponding to value of n1.

Regards,
Laktronics
 

Hi,
I find 2n1*n2 calculation is not right. You need to pick up n2 from R3 by loading R3 into ACC, swap A and AND a with #0F to get n2 into lsnibble of ACC. Load n1 from r2 into B, and multiply. Result would be a byte in ACC only, no carry, Now rotate ACC left with carry to multiply by 2h. If now the carry is set increment R5 and then add Acc to R5-Ro.

Regards,
Laktronics
 
Okie,understood,Thank you !

Added after 46 minutes:

Mov A,R2
SUBB A,#00H
MOV R5,A

;now n1 in R2, n2n3 in R3 , R4 hold LSbyte value after -100D , R5 hold MSbyte value after - carry if there are carry.

MOv B,#4D ;multiply 4 for Rdt-100D
MUL AB
MOV R5,A

MOV A,R4
MOV B,#4D
MUL AB
MOV R0,A
MOV R1,B
MOV A,R5
ADD A,R1
MOV R5,A

;now R0 hold the LSbyte after x4 , R5 hold the MSbyte after x4

MOV B,R7 ;getting 2n1.n2
MOV A,R2
MUL AB

MOV B,#2
MUL AB ;A store LSByte of 2n1.n2 ,B store MSByte of 2n1.n2

CLR C
ADD A,R0
MOV R0,A
MOV A,B
ADDC A,R5
MOV R5,A

;So until now i had calculated this part [4(RDh-100D)+2n1n2], with MSbyte stored in R5 and LSbyte store in R0

MOV DPTR,#1EFFH
MOV A, R2
MOVC A,@A+DPTR ; A will get the data corresponding to value of n1
MOV B,#100D
MUL AB
MOV R1,B ;R1 hold MSbyte

CLR C
SUBB A,R0
MOV R0,A
MOV A,R5
SUBB A,R1
MOV R5,A ;R5 hold MSbyte and R0 hold LSbyte for [4(Rdh-100D)+2n1.n2-2.8x10^-4(n1.256)^2]


CSEG AT 1EFFH
DB 0D,0D,0D,2D,3D,5D,7D,9D,12D,15D,18D,22D,26D,31D,36D,41D

This is my coding for humidity. Some minor changing and add on the last part.I tried compile and no problem found,but if u free can help me to debug it. But i think it is okie so far.
Now i am forwading in study of LCD, i have 1week time left fot the due date !!!
If any doubt i come to you again, once again thank you very much !
 

Hi,
1. I did not see how you got n2 into R7.
2. In the final subtraction of the table value from the measurement , you should subtract A from R0, you did it reverse.

Very Important:

3. The term 2n1n2 is to be added to the table value after MUL by 100 and then to be subtracted from the basic term. I also did not notice this error earlier.

4. Rememver there is a multiplication by 0.01 for the final value, to be adjusted in display.

Otherwise the code looks ok.

Regards,
Laktronics
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top