Help for decimal conversion


Closed Thread
Results 1 to 3 of 3
  1. #1
    eva's Avatar
    eva Guest

    Default Help for decimal conversion

    Hi everybody.
    I’m trying to make a differential thermostat for a solar water heating system using a 16f876 and two DS1820. I succeeded using as a starting point the onewire.bas in the examples. The sensors are used on two different pins. The temperature difference at which the pump has to start was initially fixed at 7°C with no problems but now I’d like to make it selectable between say 7 and 20 degs.
    I have tried this program and it works, except that I can evaluate the set temperature difference only
    memorizing the strange symbols displayed or their sequence. Can anybody help me solving this conversion problem? Any other suggestion will be very much appreciated.

    ' Differential thermostat


    temperature VAR WORD ' Temperature storage
    count_remain VAR BYTE ' Count remaining
    count_per_c VAR BYTE ' Count per degree C
    temperapanel VAR WORD ' Panel temperature storage
    count_rempan VAR BYTE
    count_per_cpan VAR BYTE
    DQ VAR PORTA.4 ' One-wire data pin for boiler
    DP VAR PORTA.5 ' One-wire data pin for panel*
    delta VAR WORD ' Delta T° btwn Panel & Boiler to start pump

    ' Define LCD registers and bits
    DEFINE LCD_DREG PORTB

    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTA

    DEFINE LCD_RSBIT 2

    DEFINE LCD_EREG PORTA

    DEFINE LCD_EBIT 1

    DEFINE LCD_BITS 4

    DEFINE LCD_LINES 2

    DEFINE LCD_COMMANDUS 2000

    DEFINE LCD_DATAUS 50


    ADCON1 = 7 ' Set PORTA and PORTE to digital
    LCDOut $fe, 1, "Diff. Thermostat"

    Pause 3000
    delta = 700 ' DEFAULT T° DIFFERENCE AT WHICH PUMP STARTS

    mainloop: IF PORTA.3 = 0 Then pressed ' CHECK IF TEMPERATURE DIFFERENCE
    ' BUTTON IS PRESSED

    OWOut DQ, 1, [$CC, $44] ' Start temperature conversion

    waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
    IF count_remain = 0 Then waitloop

    OWOut DQ, 1, [$CC, $BE] ' Read the temperature
    OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

    ' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
    temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    LCDOut $fe, 1, DEC (temperature / 100), ".", DEC1 temperature, "C Boiler"


    OWOut DP, 1, [$CC, $44] ' Start temperature conversion
    waitloop2: OWIn DP, 4, [count_rempan] ' Check for still busy converting
    IF count_rempan = 0 Then waitloop2

    OWOut DP, 1, [$CC, $BE] ' Read the temperature
    OWIn DP, 0, [temperapanel.LOWBYTE, temperapanel.HIGHBYTE, Skip 4, count_rempan, count_per_cpan]

    ' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
    temperapanel = (((temperapanel >> 1) * 100) - 25) + (((count_per_cpan - count_rempan) * 100) / count_per_cpan)
    LCDOut $fe, $c0, DEC (temperapanel / 100), ".", DEC1 temperapanel, "C Panel"

    Pause 3000 ' Display about once every 3 seconds

    IF temperapanel < 1800 Then mainloop 'Less than 18°C? Pump stays off

    IF temperapanel > (temperature + delta) Then 'Checks T diff. for the pump to start (default 7°C)

    High PORTC.4 'Start pump
    EndIF
    IF PORTC.4 Then 'Check for PORTC pin 4 high
    LCDOut $fe,$c0+4, " h2o PUMPING" 'It's high so pump is on
    EndIF
    IF temperapanel < (temperature +300) Then 'Checks if T difference < 3°C
    Low PORTC.4 'Stop pump
    EndIF
    Pause 3000 ' Refresh time =~3 seconds
    GoTo mainloop ' Do it forever
    End


    pressed: Pause 30 'debounce
    IF PORTA.3 = 0 Then setdelta 'IF STILL PRESSED GO TO SETDELTA
    setdelta: For delta = 700 TO 2000 STEP 100 ' STEP SIZE 1°C
    LCDOut $fe, 1, "Delta ", delta 'CLEAR LCD AND DISPLAY DELTA VALUE
    Pause 3000
    IF PORTA.3 = 1 Then mainloop 'if not pressed go to mainloop
    Next delta
    GoTo setdelta
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2005
    Location
    Macedonia
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Hi Eva question for diferentioal termometar with 876

    Hi,
    I read you massage and I have question, can you send me schematic and hex file for software, I do net have bas to hex converters for pic,
    regards

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    May I suggest
    http://compilespot.com/
    to get your hex file?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. A/D conversion problem on 18F4431
    By ttease in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2007, 23:03
  4. Conversion problem
    By eva in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th March 2007, 18:21
  5. Strange A/D conversion...
    By Christos_K in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2005, 01:35

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts