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.

Code Optimisation (Digital FAHRENEHIT Thermometer)

Status
Not open for further replies.
Hi everyone.

I have finally just got the code working on my DS18B20 Digital Fahrenheit Thermometer after disussion with a few very knowlegdeable people in another thread.

Here it is below after a couple of minutes in the freezer with the themostat turned all the way down :p

-6.5F = -21.4C
fahrenheit-jpg.54538

There ASM file has too many characters for a post so here it is here:
http://www.jakeselectronics.net/fil...orbasic/digitaltemperaturesensorbasicFasm.php

What I have done is take my old Celsius program and add the C to F Conversion in.

What I am looking for/asking/wanting to discuss, is code optimisation or better ways of doing things from line 313 down.
 

Attachments

  • Fahrenheit.JPG
    Fahrenheit.JPG
    224.8 KB · Views: 324
I'll look at the code when I get home. I'm making a well house thermostat based on the DS18B20. I'm ordering parts for it on Monday. On that project I'm using a LCD instead of seven segment displays.
 
Hi Jake,

Your bin_to_dec_f routine looks like a very nice extension of your original and very novel 8-bit (0..255) routine from long ago. I'd just like to mention that, like your original routine, you could take advantage of the -10 value in WREG to subtract ten instead of one during each loop, which would improve execution time quite dramatically.

Code:
;
;  Jake's modified 13+ bit 0000..9999 bin-to-dec algorithm
;
;   input: binh:binl -> 0x0000..0x270F (0..9999)
;  output: thou -> 0..9
;          huns -> 0..9
;          tens -> 0..9
;          ones -> 0..9
;
;  19 words, 4 or 5 variables, 14..8330 cycles  (Mike, K8LH)
;
        radix   dec

        clrf    thou            ;
        movlw   -10             ; wreg = -10
resHuns movwf   huns            ; set huns = -10
resTens movwf   tens            ; set tens = -10
div10z  addwf   binl,F          ; binl = binl - 10, borrow?
        skpc                    ; no, skip, else
        decf    binh,F          ; decrement hi byte
        btfsc   binh,7          ; negative? no, skip, else
        goto    b2dwrap         ; wrap up (borrow/underflow)
        incfsz  tens,F          ; tens overflow? yes, skip, else
        goto    div10z          ; loop
        incfsz  huns,F          ; huns overflow? yes, skip, else
        goto    resTens         ; reset 'tens' & loop
        incf    thou,F          ; bump 'thou'
        goto    resHuns         ; reset 'huns' & 'tens' & loop
b2dwrap subwf   huns,F          ; fix huns
        subwf   tens,F          ; fix tens
        subwf   binl,W          ; fix ones
        movwf   ones            ;
Cheerful regards, Mike
 
Mike, Im interested to study the modified routine because I dont quite understand your worded description. I just started a new job, so Ill take an in depth look on the weekend.

I wanted to leave the other thread, becasue I've gone from 'how the hell do i make this work' to, 'how can i do this better'...
Anyway in the other thread you stated:
While this modified version of your routine is much faster, it's still pretty slow compared to some of the alternatives. If that becomes an issue, please let us know.
Its not an issue for this project, but im allways interested in being able to do things better.. Please expand on the/your alternatives.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top