Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

1 Wire Protocol Code Issue

Status
Not open for further replies.
Hi Mike,

I may have misunderstood this but the formula in the data sheet has an additional subtraction of ¼°C which when it is in 12 bit format would be minus 4.

Mike.
 
Hi Mike,

I may have misunderstood this but the formula in the data sheet has an additional subtraction of ¼°C which when it is in 12 bit format would be minus 4.

Mike.
I just assumed they were "rounding" the number. The least significant bit in the DS18S20 temperature word is 1/2° but the "count_remain" byte, or 4 bits actually, is the full fractional portion of the Celsius temperature reading.

Could I be mis-comprehending the info' in the Data Sheet?

Mike
 
Last edited:
Hi Mike thanks for your examples.

Now my result temperature bytes are like DS 18B20 format.

I just calculated some possibility values to the fractional portion.

For a one decimal digit will a lookup table sufficient without going any multiplications & divisions?
 

Attachments

  • Fraction.JPG
    Fraction.JPG
    20.4 KB · Views: 173
That should work fine and then you don't really need to format the data as 12-bit DS18B20 data...

That datasheet formulas make me sick.I still cannot have a better understand how the formula works.:(

DS18S20 gives 0.5 in the LSB of the lower temperature register.

My full try is to make a one decimal digit with a least amount of math routines used.Because I'm showing the temperature on SSD's so no any latch functions.So have to do all the calculations within a unnoticeable time.
 
Last edited:
Just use the integer portion of the temperature in the low byte (get rid of the 1/2 degree bit by shifting it out). Then use the 'count_remain' byte value as a (reverse) index (0..15) into your fraction table...

Mike
 
Last edited:
Hi Mike thanks for that hint.Same as subtract from 16.

Code:
	movf	Count_R,W	;count remain from SP
	sublw	.16		;subtract from 16
	movwf	Index		;
	movf	Index,W		;get the index
	call	Table_Frac	;call the decimal digit

Just a thought you put 16 instead of count per C because of the fraction (count remain) never exceeds 4 bits?

Is this how you made your formula?
 
Gayan,

I saw your other thread over on Forum.Microchip and I just wanted to mention that the temperature data is a sign-extended two's compliment number.

When the most significant bit is a '1' then the number is negative and you need to two's compliment it to make it positive (the "absolute" subroutine call in my example). You would need to do this on the fractional bits too.

Mike
 
Hi Mike thanks for that hint.Same as subtract from 16.

Code:
    movf    Count_R,W    ;count remain from SP
    sublw    .16        ;subtract from 16
    movwf    Index        ;
    movf    Index,W        ;get the index
    call    Table_Frac    ;call the decimal digit
Just a thought you put 16 instead of count per C because of the fraction (count remain) never exceeds 4 bits?

Is this how you made your formula?

No. I meant that you might do something like this (data in table is reversed);

Code:
;
        call    absolute        ; make TempL positive
        clrc                    ; clear carry
        rrf     TempL,F         ; get rid of the half degree bit
        movf    count_remain,W  ; get "count remain"
        call    FracTbl         ; get fraction digit '0'..'9'
;
;  TempL = integer number
;  WREG = fractional digit '0'..'9'
;  NegFlag = '1' if negative (from Absolute sub')
;
 
Hi Mike
When the most significant bit is a '1' then the number is negative and you need to two's compliment it to make it positive (the "absolute" subroutine call in my example). You would need to do this on the fractional bits too.

Yep I have done that.The problem was with the reverse index.I can understand your code.

But with this line

"I meant that you might do something like this (data in table is reversed)"
means the table must arranged in reverse order? like starting from retlw 15(value) ,retlw14(value).......retlw 1(value).

I saw your other thread over on Forum.Microchip

Nop I'm not a member there :rolleyes:

My earlier code for reverse index if I arrange the table values in correct order.ex:retlw 00,retlw 1(value),retlw 3(value) etc...

Thanks for spending time on this.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top