Help with DS2436 Voltage monitor


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Cool Re: help with DS2436 voltage monitor

    Hello DynamoBen.
    Thank you for reply. I need to adapt code written for Basic Stamp 2p24 module.
    I’d like to program PIC16F84A – 04/P to display voltage and temperature on Hitachi 44780 style display. I tried to download this program directly to PIC Basic PRO complier, but it gives error messages. As I’m just started with this product and I need little help, please. Can you correct following code?

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [VLADIMIR] *
    '* Notice : Copyright (c) 2006 [None] *
    '* : All Rights Reserved *
    '* Date : 7/30/2006 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    ' File...... DS2436.BS2
    ' Purpose... Reads information from a Dallas DS2436
    '
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    '
    ' -----[ Program Description ]--------------------------------------------------
    ' This program is based on the PSK_DS1822.bsp sample program in the
    ' BASIC Stamp 2p24 Professional Starter Kit (.pdf) document. Thank you Parallax!
    '
    ' Program output is via DEBUG and looks like:
    '
    ' DS2436 DATA
    ' Voltage: 4.8v (01 E3)
    ' Temperature: 25°C (19 10)
    ' counter = 18
    '
    ' -----[ Revision History ]-----------------------------------------------------
    '
    ' -----[ I/O Definitions ]------------------------------------------------------
    '
    OWpin CON 1

    ' -----[ Constants ]------------------------------------------------------------
    '
    ' 1-Wire Support
    '
    ReadROM CON $33 ' read ID, serial num, CRC
    MatchROM CON $55 ' look for specific device
    SkipROM CON $CC ' skip rom (one device)
    SearchROM CON $F0 ' search

    OW_FERst CON %0001 ' Front-End Reset
    OW_BERst CON %0010 ' Back-End Reset
    OW_BitMode CON %0100
    OW_HighSpd CON %1000

    ' DS2346 control
    '
    ConvertV CON $B4 ' convert the voltage
    ConvertT CON $D2 ' convert the temperature
    ReadRegister CON $B2 ' read page 4 and page 5 of DS2436

    NoDevice CON %11 ' no device present
    DegSym CON 176

    ' -----[ Variables ]------------------------------------------------------------
    '
    voltage VAR Word
    vLo VAR voltage.BYTE0
    vHi VAR voltage.BYTE1
    temp VAR Word
    tLo VAR temp.BYTE0
    tHi VAR temp.BYTE1
    counter VAR Word
    romData VAR Word(8)

    devCheck VAR Word

    ' -----[ EEPROM Data ]----------------------------------------------------------
    '
    ' -----[ Initialization ]-------------------------------------------------------
    '
    Initialize:
    DEBUG CLS
    PAUSE 250 ' allow DEBUG screen to open
    counter = 0
    '
    GOSUB Device_Check ' look for device
    IF (devCheck <> NoDevice) THEN Main
    No_Device_Found:
    DEBUG CLS,"No 1-wire device present.", CR
    DEBUG "-- Insert device and re-start."
    END

    ' -----[ Main Code ]------------------------------------------------------------
    '
    Main:
    DEBUG HOME, "DS2436 Data"
    counter = counter + 1 ' count number of conversions

    GOSUB Get_Volt ' voltage conversion
    GOSUB Get_Temp ' temperature conversion

    testValue1: ' voltage = $01E3 ' uncomment to test without DS2436
    testValue2: ' temp = $1910 ' uncomment to test without DS2436

    DEBUG CR, "Voltage: ",DEC voltage/100, ".", DEC1 voltage/10,"v (", HEX2 vHi, " ", HEX2 vLo, ")"
    DEBUG CR, "Temperature: ",DEC tHi, DegSym, "C (", HEX2 tHi, " ", HEX2 tLo, ")"
    DEBUG CR, DEC ? counter

    PAUSE 500 ' delay for a bit....
    GOTO Main

    END
    ' -----[ Subroutines ]----------------------------------------------------------
    '
    'DS2436 Page 4 Memory is read using the Read_Registers [$B2] command
    'addr purpose
    ' $60 Temp LSB (decimal degrees C)
    ' $61 Temp MSB (integer degrees C)
    ' $62 status (BIT0 shows T conversion status, Bit 3 shows V status)
    ' $63 status
    ' $77 Voltage LSB
    ' $78 Voltage MSB

    Get_Volt:
    OWOUT OWpin,OW_FERst,[SkipROM,ConvertV] ' send voltage conversion command
    PAUSE 15 ' give it some time (could wait until bit3 at $62 equals 0)
    OWOUT OWpin,OW_FERst,[SkipROM,ReadRegister, $77] ' lo byte voltage
    OWIN OWpin,OW_BERst,[vLo]
    OWOUT OWpin,OW_FERst,[SkipROM,ReadRegister, $78] ' hi byte voltage
    OWIN OWpin,OW_BERst,[vHi]
    RETURN

    Get_Temp:
    OWOUT OWpin,OW_FERst,[SkipROM,ConvertT] ' send voltage conversion command
    PAUSE 15 ' give it some time (could wait until bit1 at $62 equals 0)
    OWOUT OWpin,OW_FERst,[SkipROM,ReadRegister, $60] ' lo byte temp
    OWIN OWpin,OW_BERst,[tLo]
    OWOUT OWpin,OW_FERst,[SkipROM,ReadRegister, $61] ' hi byte temp
    OWIN OWpin,OW_BERst,[tHi]
    RETURN


    ' This subroutine checks to see if any 1-Wire devices are present on the
    ' bus. It does NOT search for ROM codes
    Device_Check:
    devCheck = 0
    OWOUT OWpin,OW_FERst,[SearchROM] ' reset and start search
    OWIN OWpin,OW_BitMode,[devCheck.BIT1,devCheck.BIT0]
    RETURN

    Thank you in advance
    Vladimir

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    "Can you correct following code?"

    This forum tends to take the "teach a man to fish" attitude. We try to provide people with information to assit them with problems not solve them for the person. I and others are more than happy to assist you with specific problems or questions. Keep in mind we don't have a schematic and often don't know what the intentions of your design are.

    Your code seems very close to being correct. Make sure you have read through the section at the back of the manual about the differences between PICBasic and Stamp. That will help.

    I do see that you have a bunch of debug commands which I would assume are supposed to be text sent to the LCD; if so check out the LCDOut command. These debug statements are causing your errors, lcdout should remedy this. You will also want to specify the xtal speed you are using with the following command at the top of your program:

    DEFINE OSC 20 ; 20mhz XTAL (change notes above)

    Beyond that I found that the search function in the forum will turn up a lot of useful info. I too was a beginner once so I understand the challenges you are facing; that being said you have a jumpstart since what you have works on a stamp.
    Last edited by DynamoBen; - 30th July 2006 at 23:22.

  3. #3
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Talking DS 2436 voltage monitor

    Hello DynamoBen.
    I couldn’t agree with you more! I’m talking about “teach a man to fish attitude”.
    But like anyone else living on this planet I’m trying to find easiest ways first. Another point I’m just started reading PIC BASIC Pro manual, and as English isn’t my native language it probably takes me about a week to finish. I’m very impatient person and after I spent almost 300 CAD I’d really like to accomplish something in first two days. Especially DS2436 voltage monitor project, as I already tried to put through on Basic Stamp II, unsuccessfully unfortunately. That’s why my attempt to put problems on somebody’s shoulders is not a habit; it is just exiting about new “toy” and wish to play with it as soon as possible. I assure you in few weeks I will be familiar with PIC Basic and I will write such program from scratch myself.
    Anyway, thank you for your messages I will check up web site for similar programs and hints.
    Best regards
    Vladimir

  4. #4
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Thumbs up

    The best way to learn is:

    Read and understand the datasheets and user manual
    Review the Melabs examples (some of which come from users on this forum)
    Utilize the search function above
    and most of all...experiment.

    If you still can't find your answer, go ahead and post. This forum is a wealth of information; and a nice bunch of people.

    Soon you too with be a contributing member.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Vladimir,

    Just wanted to reinforce that Ben pretty much hit the nail on the head.

    DEBUG is your biggest problem. It's not the same in PBP.

    Something to focus in on, instead of trying to learn it all at once.
    Quote Originally Posted by DynamoBen
    Make sure you have read through the section at the back of the manual about the differences between PICBasic and Stamp. That will help.
    regards,
    Darrel

  6. #6
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Wink DS 2436 voltage monitor

    Thank you everybody for replies and advises. I corrected the code and a bit improve it. Now it works flawless.
    Thanks again

    Vladimir.

  7. #7
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Thumbs up

    See you didn't need us to correct the code, well done!

Similar Threads

  1. Voltage monitor and PWM control
    By StoneColdFuzzy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th May 2009, 16:11
  2. Voltage monitor for car battery
    By passion1 in forum mel PIC BASIC Pro
    Replies: 50
    Last Post: - 23rd April 2008, 21:47
  3. Expanded Scale Voltmeter
    By Pic_User in forum Schematics
    Replies: 6
    Last Post: - 8th February 2008, 20:32
  4. voltage monitor
    By aftab in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 17th August 2007, 09:57
  5. Help with final project
    By OvERKiLL in forum General
    Replies: 4
    Last Post: - 15th December 2006, 20:35

Members who have read this thread : 0

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